Skip to content

Commit

Permalink
Remove black, use ruff.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtarzia committed Feb 13, 2024
1 parent 4f924aa commit 36cdbc5
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
python-version: "3.11"
cache: "pip"
- run: "pip install -e '.[dev]'"
- run: black --check .
- run: ruff format --check .
pytest:
runs-on: ubuntu-22.04
services:
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ check:
(set -x; ruff . )

echo
( set -x; black --check . )
( set -x; ruff format --check . )

echo
( set -x; mypy src )
Expand All @@ -37,7 +37,7 @@ check:

# Auto-fix code issues.
fix:
black .
ruff format .
ruff --fix .

# Start a MongoDB instance in docker.
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ readme = "README.rst"

[project.optional-dependencies]
dev = [
"black",
"ruff",
"moldoc",
"mypy",
Expand All @@ -53,11 +52,11 @@ documentation = "https://stk.readthedocs.io"
[tool.setuptools_scm]
write_to = "src/stk/_version.py"

[tool.black]
line-length = 79

[tool.ruff]
line-length = 79

[too.ruff.lint]
extend-select = ["I"]

[tool.pytest.ini_options]
Expand Down
8 changes: 4 additions & 4 deletions src/stk/_internal/constructed_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ def get_atom_info(atom: Atom) -> AtomInfo:

canonical_building_block = building_blocks[old_building_block]

(canonical_building_block_atom,) = (
canonical_building_block.get_atoms(
atom_ids=canonical_building_block_atom_id,
)
(
canonical_building_block_atom,
) = canonical_building_block.get_atoms(
atom_ids=canonical_building_block_atom_id,
)

return AtomInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def _with_placement_results(
edge_id,
functional_groups,
) in summary.get_edge_functional_groups():
self._edge_functional_groups[edge_id] = (
self._edge_functional_groups.get(edge_id, [])
)
self._edge_functional_groups[
edge_id
] = self._edge_functional_groups.get(edge_id, [])
self._edge_functional_groups[edge_id].extend(functional_groups)
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_key(record: T) -> str:
population, keys = dedupe(
items=(
molecule_record
for molecule_record, in self._generation_selector.select(
for (molecule_record,) in self._generation_selector.select(
population=normalized_fitness_values
)
),
Expand Down
5 changes: 2 additions & 3 deletions src/stk/_internal/ea/fitness_normalizers/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ class Add(FitnessNormalizer[T]):
def __init__(
self,
number: float | Iterable[float],
filter: Callable[
[dict[T, Any], T], bool
] = lambda fitness_values, record: True,
filter: Callable[[dict[T, Any], T], bool] = lambda fitness_values,
record: True,
) -> None:
"""
Parameters:
Expand Down
5 changes: 2 additions & 3 deletions src/stk/_internal/ea/fitness_normalizers/divide_by_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ class DivideByMean(FitnessNormalizer[T]):

def __init__(
self,
filter: Callable[
[dict[T, Any], T], bool
] = lambda fitness_values, record: True,
filter: Callable[[dict[T, Any], T], bool] = lambda fitness_values,
record: True,
) -> None:
"""
Parameters:
Expand Down
5 changes: 2 additions & 3 deletions src/stk/_internal/ea/fitness_normalizers/multiply.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ class Multiply(FitnessNormalizer[T]):
def __init__(
self,
coefficient: float | Iterable[float],
filter: Callable[
[dict[T, Any], T], bool
] = lambda fitness_values, record: True,
filter: Callable[[dict[T, Any], T], bool] = lambda fitness_values,
record: True,
) -> None:
"""
Parameters:
Expand Down
5 changes: 2 additions & 3 deletions src/stk/_internal/ea/fitness_normalizers/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ class Power(FitnessNormalizer[T]):
def __init__(
self,
power: float | Iterable[float],
filter: Callable[
[dict[T, Any], T], bool
] = lambda fitness_values, record: True,
filter: Callable[[dict[T, Any], T], bool] = lambda fitness_values,
record: True,
) -> None:
"""
Parameters:
Expand Down
5 changes: 2 additions & 3 deletions src/stk/_internal/ea/fitness_normalizers/replace_fitness.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ def get_minimum_fitness_value(fitness_values):
def __init__(
self,
get_replacement: Callable[[dict[T, Any]], Any],
filter: Callable[
[dict[T, Any], T], bool
] = lambda fitness_values, record: True,
filter: Callable[[dict[T, Any], T], bool] = lambda fitness_values,
record: True,
) -> None:
"""
Parameters:
Expand Down
5 changes: 2 additions & 3 deletions src/stk/_internal/ea/fitness_normalizers/shift_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ class ShiftUp(FitnessNormalizer[T]):

def __init__(
self,
filter: Callable[
[dict[T, Any], T], bool
] = lambda fitness_values, record: True,
filter: Callable[[dict[T, Any], T], bool] = lambda fitness_values,
record: True,
) -> None:
"""
Parameters:
Expand Down
5 changes: 2 additions & 3 deletions src/stk/_internal/ea/fitness_normalizers/sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ class Sum(FitnessNormalizer[T]):

def __init__(
self,
filter: Callable[
[dict[T, Any], T], bool
] = lambda fitness_values, record: True,
filter: Callable[[dict[T, Any], T], bool] = lambda fitness_values,
record: True,
) -> None:
"""
Parameters:
Expand Down
22 changes: 11 additions & 11 deletions src/stk/_internal/reactions/ring_amine_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ def _get_new_bonds(self):
nc2h1 = C(-8)
nc2h2 = C(-9)

yield Bond(n1, n_joiner, 1),
yield Bond(n_joiner, n2, 1, self._periodicity),
yield Bond(n_joiner, nh1, 1),
yield Bond(n_joiner, nh2, 1),
yield Bond(c1, nc_joiner1, 1),
yield Bond(nc_joiner1, n2, 1, self._periodicity),
yield Bond(nc_joiner1, nc1h1, 1),
yield Bond(nc_joiner1, nc1h2, 1),
yield Bond(nc_joiner2, c2, 1, self._periodicity),
yield Bond(n1, nc_joiner2, 1),
yield Bond(nc_joiner2, nc2h1, 1),
yield (Bond(n1, n_joiner, 1),)
yield (Bond(n_joiner, n2, 1, self._periodicity),)
yield (Bond(n_joiner, nh1, 1),)
yield (Bond(n_joiner, nh2, 1),)
yield (Bond(c1, nc_joiner1, 1),)
yield (Bond(nc_joiner1, n2, 1, self._periodicity),)
yield (Bond(nc_joiner1, nc1h1, 1),)
yield (Bond(nc_joiner1, nc1h2, 1),)
yield (Bond(nc_joiner2, c2, 1, self._periodicity),)
yield (Bond(n1, nc_joiner2, 1),)
yield (Bond(nc_joiner2, nc2h1, 1),)
yield Bond(nc_joiner2, nc2h2, 1)

def _get_deleted_atoms(self):
Expand Down
6 changes: 3 additions & 3 deletions src/stk/_internal/topology_graphs/cage/cage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,9 +1378,9 @@ def _get_building_block_vertices(
for vertex in cls._vertex_prototypes:
vertex_degree = cls._vertex_degrees[vertex.get_id()]
building_block = building_blocks_by_degree[vertex_degree]
building_block_vertices[building_block] = (
building_block_vertices.get(building_block, [])
)
building_block_vertices[
building_block
] = building_block_vertices.get(building_block, [])
building_block_vertices[building_block].append(vertex)
return typing.cast(
dict[BuildingBlock, abc.Sequence[_CageVertex]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ def _update_neighbor_positions(
(functional_group,) = building_block.get_functional_groups(
fg_id
)
self._neighbor_positions[neighbor_id] = (
self._neighbor_positions.get(neighbor_id, [])
)
self._neighbor_positions[
neighbor_id
] = self._neighbor_positions.get(neighbor_id, [])
self._neighbor_positions[neighbor_id].append(
building_block.get_centroid(
atom_ids=functional_group.get_placer_ids(),
Expand Down
16 changes: 7 additions & 9 deletions src/stk/_internal/topology_graphs/cof/cof.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,10 @@ def __init__(
for building_block, ids in building_blocks.items()
}
else:
building_block_vertices = (
self._get_building_block_vertices( # type: ignore[assignment]
building_blocks=building_blocks,
vertices=vertices,
edges=edges,
)
building_block_vertices = self._get_building_block_vertices( # type: ignore[assignment]
building_blocks=building_blocks,
vertices=vertices,
edges=edges,
)

building_block_vertices = self._with_unaligning_vertices(
Expand Down Expand Up @@ -782,9 +780,9 @@ def _get_building_block_vertices(
for vertex in vertices:
vertex_degree = vertex_degrees[vertex.get_id()]
building_block = building_blocks_by_degree[vertex_degree]
building_block_vertices[building_block] = (
building_block_vertices.get(building_block, [])
)
building_block_vertices[
building_block
] = building_block_vertices.get(building_block, [])
building_block_vertices[building_block].append(vertex)
return building_block_vertices

Expand Down
3 changes: 2 additions & 1 deletion src/stk/_internal/topology_graphs/rotaxane/nrotaxane.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ def __init__(

# Save the chosen orientations for __repr__.
self._orientations = tuple(
int(vertex.get_flip()) for vertex in vertices[1:] # type:ignore
int(vertex.get_flip()) # type: ignore[union-attr]
for vertex in vertices[1:]
)

super().__init__(
Expand Down

0 comments on commit 36cdbc5

Please sign in to comment.