Skip to content

Commit 4212679

Browse files
Replace black with ruff-format
1 parent fdab13b commit 4212679

File tree

130 files changed

+2401
-4337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+2401
-4337
lines changed

.git-blame-ignore-revs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-FileCopyrightText: 2019–2024 Pynguin Contributors
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# Replace black with ruff-format
6+
0729abe647ddd0ab6a7fc33fbbcec10a16819d07

.pre-commit-config.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,12 @@ repos:
4040
- id: isort
4141
args: [--profile, black]
4242

43-
- repo: https://github.com/psf/black
44-
rev: 24.10.0
45-
hooks:
46-
- id: black
47-
args: [--config, ./pyproject.toml]
48-
4943
- repo: https://github.com/astral-sh/ruff-pre-commit
5044
rev: v0.8.0
5145
hooks:
5246
- id: ruff
5347
args: [ --fix ]
48+
- id: ruff-format
5449

5550
- repo: https://github.com/fsfe/reuse-tool
5651
rev: v5.0.2

Makefile

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ ifeq ($(STRICT), 1)
1010
POETRY_COMMAND_FLAG =
1111
PIP_COMMAND_FLAG =
1212
SECRETS_COMMAND_FLAG =
13-
BLACK_COMMAND_FLAG =
1413
ISORT_COMMAND_FLAG =
1514
MYPY_COMMAND_FLAG =
1615
else
1716
POETRY_COMMAND_FLAG = -
1817
PIP_COMMAND_FLAG = -
1918
SECRETS_COMMAND_FLAG = -
20-
BLACK_COMMAND_FLAG = -
2119
ISORT_COMMAND_FLAG = -
2220
MYPY_COMMAND_FLAG = -
2321
endif
@@ -40,12 +38,6 @@ else ifeq ($(SECRETS_STRICT), 0)
4038
SECRETS_COMMAND_FLAG = -
4139
endif
4240

43-
ifeq ($(BLACK_STRICT), 1)
44-
BLACK_COMMAND_FLAG =
45-
else ifeq ($(BLACK_STRICT), 0)
46-
BLACK_COMMAND_FLAG = -
47-
endif
48-
4941
ifeq ($(ISORT_STRICT), 1)
5042
ISORT_COMMAND_FLAG =
5143
else ifeq ($(ISORT_STRICT), 0)
@@ -78,7 +70,6 @@ check-safety:
7870

7971
.PHONY: check-style
8072
check-style:
81-
$(BLACK_COMMAND_FLAG)poetry run black --diff --check ./
8273
$(ISORT_COMMAND_FLAG)poetry run isort --check-only .
8374
$(MYPY_COMMAND_FLAG)poetry run mypy
8475

@@ -102,15 +93,15 @@ ruff:
10293
isort:
10394
poetry run isort .
10495

105-
.PHONY: black
106-
black:
107-
poetry run black .
96+
.PHONY: ruff-format
97+
ruff-format:
98+
poetry run ruff format .
10899

109100
update-docs-requirements:
110101
poetry export -o docs/requirements.txt --with docs --without-hashes
111102

112103
.PHONY: check
113-
check: update-docs-requirements isort black mypy ruff test
104+
check: update-docs-requirements isort mypy ruff ruff-format test
114105

115106
.PHONY: lint
116107
lint: test check-safety check-style

pyproject.toml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,6 @@ pytest-sugar = "^1.0.0"
8383
[tool.poetry.scripts]
8484
pynguin = "pynguin.cli:main"
8585

86-
[tool.black]
87-
line-length = 88
88-
target_version = ['py310']
89-
include = '\.pyi?$'
90-
exclude = '''
91-
92-
(
93-
/(
94-
\.eggs # exclude a few common directories in the
95-
| \.git # root of the project
96-
| \.pytest_cache
97-
| \.mypy_cache
98-
| \.venv
99-
| venv
100-
| _build
101-
| build
102-
| dist
103-
| pynguin.egg-info
104-
)/
105-
)
106-
'''
107-
10886
[tool.coverage.run]
10987
branch = true
11088
source = ["src/pynguin", "tests"]
@@ -168,7 +146,7 @@ build-backend = "poetry.core.masonry.api"
168146
[tool.ruff]
169147
# Assume Python 3.10.
170148
target-version = "py310"
171-
line-length = 88
149+
line-length = 100
172150
preview = true
173151
src = ["src", "tests"]
174152
exclude = [
@@ -249,6 +227,7 @@ ignore = [
249227
"CPY001", # missing copyright notice at top of file
250228
"D105", # missing docstrings in magic methods
251229
"FIX002", # valid TODO comments
230+
"ISC001", # conflicts with ruff-format
252231
"PLR0911", # do not complain about too many return statements
253232
"PLR0912", # do not complain about too many branches
254233
"PLR0913", # do not complain about too many arguments to function call

src/pynguin/analyses/constants.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ def get_constant_for(self, tp_: type[T]) -> T | None: # noqa: D102
154154
class DelegatingConstantProvider(ConstantProvider, ABC):
155155
"""Either provides values from its own pool or delegates to another provider."""
156156

157-
def __init__(
158-
self, pool: ConstantPool, delegate: ConstantProvider, probability: float
159-
):
157+
def __init__(self, pool: ConstantPool, delegate: ConstantProvider, probability: float):
160158
"""Create a new provider.
161159
162160
Args:
@@ -170,10 +168,7 @@ def __init__(
170168
self._probability = probability
171169

172170
def get_constant_for(self, tp_: type[T]) -> T | None: # noqa: D102
173-
if (
174-
self._pool.has_constant_for(tp_)
175-
and randomness.next_float() < self._probability
176-
):
171+
if self._pool.has_constant_for(tp_) and randomness.next_float() < self._probability:
177172
return self._pool.get_constant_for(tp_)
178173
return self._delegate.get_constant_for(tp_)
179174

@@ -198,9 +193,7 @@ def __init__(
198193
max_constant_length: The maximum length of strings to store.
199194
"""
200195
super().__init__(pool, delegate, probability)
201-
assert (
202-
max_constant_length > 0
203-
), "Length limit for constant pool elements must be positive."
196+
assert max_constant_length > 0, "Length limit for constant pool elements must be positive."
204197
self._max_constant_length = max_constant_length
205198

206199
# A map containing the names of all string functions which are instrumented.
@@ -210,14 +203,10 @@ def __init__(
210203
"isalnum": lambda value: f"{value}!" if value.isalnum() else "isalnum",
211204
"islower": lambda value: value.upper() if value.islower() else value.lower(),
212205
"isupper": lambda value: value.lower() if value.isupper() else value.upper(),
213-
"isdecimal": lambda value: (
214-
"non_decimal" if value.isdecimal() else string.digits
215-
),
206+
"isdecimal": lambda value: ("non_decimal" if value.isdecimal() else string.digits),
216207
"isalpha": lambda value: f"{value}1" if value.isalpha() else "isalpha",
217208
"isdigit": lambda value: f"{value}_" if value.isdigit() else "0",
218-
"isidentifier": lambda value: (
219-
f"{value}!" if value.isidentifier() else "is_Identifier"
220-
),
209+
"isidentifier": lambda value: (f"{value}!" if value.isidentifier() else "is_Identifier"),
221210
"isnumeric": lambda value: f"{value}A" if value.isnumeric() else "012345",
222211
"isprintable": lambda value: (
223212
f"{value}{os.linesep}" if value.isprintable() else "is_printable"
@@ -235,10 +224,7 @@ def add_value(self, value: ConstantTypes) -> None:
235224
# Might be a proxy.
236225
value = unwrap(value)
237226
if type(value) in typing.get_args(ConstantTypes):
238-
if (
239-
isinstance(value, str | bytes)
240-
and len(value) > self._max_constant_length
241-
):
227+
if isinstance(value, str | bytes) and len(value) > self._max_constant_length:
242228
return
243229
self._pool.add_constant(value)
244230

src/pynguin/analyses/controlflow.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,7 @@ def copy_graph(cfg: CFG) -> CFG:
442442
Returns:
443443
The copied graph
444444
"""
445-
copy = CFG(
446-
ControlFlowGraph()
447-
) # TODO(fk) Cloning the bytecode cfg is complicated.
445+
copy = CFG(ControlFlowGraph()) # TODO(fk) Cloning the bytecode cfg is complicated.
448446

449447
copy._graph = cfg._graph.copy() # noqa: SLF001
450448
return copy
@@ -498,21 +496,18 @@ def _create_nodes_and_edges(
498496
false_branch = target_block
499497
else:
500498
raise RuntimeError(
501-
"Unknown conditional Jump instruction in bytecode "
502-
+ last_instr.name
499+
"Unknown conditional Jump instruction in bytecode " + last_instr.name
503500
)
504501
for next_branch, value in [(true_branch, True), (false_branch, False)]:
505502
next_index = blocks.get_block_index(
506503
next_branch # type: ignore[arg-type]
507504
)
508505
# 'label' is also set to value, to get a nicer DOT representation,
509506
# because 'label' is a keyword for labelling edges.
510-
edges[node_index].append(
511-
(
512-
next_index,
513-
{EDGE_DATA_BRANCH_VALUE: value, "label": value},
514-
)
515-
)
507+
edges[node_index].append((
508+
next_index,
509+
{EDGE_DATA_BRANCH_VALUE: value, "label": value},
510+
))
516511
else:
517512
if next_block:
518513
next_index = blocks.get_block_index(next_block)
@@ -557,9 +552,7 @@ def _insert_dummy_entry_node(cfg: CFG) -> CFG:
557552
# Search node with index 0. This block contains the instruction where
558553
# the execution of a code object begins.
559554
node_zero = [n for n in cfg.nodes if n.index == 0]
560-
assert (
561-
len(node_zero) == 1
562-
), "Execution has to start at exactly one node that has index 0."
555+
assert len(node_zero) == 1, "Execution has to start at exactly one node that has index 0."
563556
entry_node = node_zero[0]
564557
cfg.add_node(dummy_entry_node)
565558
cfg.add_edge(dummy_entry_node, entry_node)
@@ -692,9 +685,7 @@ def _calculate_dominance(
692685
if node == entry:
693686
continue
694687
current_dominators = dominance_map.get(node)
695-
new_dominators = DominatorTree._calculate_dominators(
696-
graph, dominance_map, node
697-
)
688+
new_dominators = DominatorTree._calculate_dominators(graph, dominance_map, node)
698689

699690
if current_dominators != new_dominators:
700691
changed = True
@@ -756,14 +747,8 @@ def compute(graph: CFG) -> ControlDependenceGraph:
756747
if source not in post_dominator_tree.get_transitive_successors(target):
757748
# Store branching data from edge, i.e., which outcome of the
758749
# branching node leads to this node.
759-
data = frozenset(
760-
augmented_cfg.graph.get_edge_data(source, target).items()
761-
)
762-
edges.add(
763-
ControlDependenceGraph._Edge(
764-
source=source, target=target, data=data
765-
)
766-
)
750+
data = frozenset(augmented_cfg.graph.get_edge_data(source, target).items())
751+
edges.add(ControlDependenceGraph._Edge(source=source, target=target, data=data))
767752

768753
# Mark nodes in the PDT and construct edges for them.
769754
for edge in edges:
@@ -787,9 +772,7 @@ def compute(graph: CFG) -> ControlDependenceGraph:
787772

788773
return filter_dead_code_nodes(cdg, entry_node_index=-sys.maxsize)
789774

790-
def get_control_dependencies(
791-
self, node: ProgramGraphNode
792-
) -> OrderedSet[ControlDependency]:
775+
def get_control_dependencies(self, node: ProgramGraphNode) -> OrderedSet[ControlDependency]:
793776
"""Get the immediate control dependencies of this node.
794777
795778
Args:

0 commit comments

Comments
 (0)