Skip to content

Commit 2a6420a

Browse files
committed
Add ruff
Change-Id: I2518e0cf928210acf9cfb2e5f4c19f973df64485 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent e2cabcc commit 2a6420a

195 files changed

Lines changed: 9229 additions & 6129 deletions

File tree

Some content is hidden

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

.pre-commit-config.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ repos:
1212
- id: debug-statements
1313
- id: check-yaml
1414
files: .*\.(yaml|yml)$
15+
- repo: https://github.com/astral-sh/ruff-pre-commit
16+
rev: v0.15.5
17+
hooks:
18+
- id: ruff-check
19+
args: ['--fix', '--unsafe-fixes']
20+
- id: ruff-format
1521
- repo: https://opendev.org/openstack/hacking
1622
rev: 8.0.0
1723
hooks:
1824
- id: hacking
1925
additional_dependencies: []
2026
exclude: '^(doc|releasenotes|tools)/.*$'
21-
- repo: https://github.com/asottile/pyupgrade
22-
rev: v3.21.2
23-
hooks:
24-
- id: pyupgrade
25-
args: [--py310-plus]

doc/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
'sphinx.ext.extlinks',
2626
'sphinx.ext.inheritance_diagram',
2727
'sphinx.ext.viewcode',
28-
'openstackdocstheme'
28+
'openstackdocstheme',
2929
]
3030

3131
# openstackdocstheme options

pyproject.toml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,21 @@ parallel = "taskflow.engines.action_engine.engine:ParallelActionEngine"
9595
worker-based = "taskflow.engines.worker_based.engine:WorkerBasedActionEngine"
9696
workers = "taskflow.engines.worker_based.engine:WorkerBasedActionEngine"
9797

98-
[tool.setuptools]
99-
packages = [
100-
"taskflow"
101-
]
98+
[tool.setuptools.packages.find]
99+
include = ["taskflow"]
100+
101+
[tool.ruff]
102+
line-length = 79
103+
104+
[tool.ruff.format]
105+
quote-style = "preserve"
106+
docstring-code-format = true
107+
108+
[tool.ruff.lint]
109+
select = ["E4", "E5", "E7", "E9", "F", "G", "LOG", "S"]
110+
external = ["H"]
111+
ignore = ["E402", "E721", "E731", "E741"]
112+
113+
[tool.ruff.lint.per-file-ignores]
114+
"taskflow/examples/*" = ["S"]
115+
"taskflow/tests/*" = ["S"]

releasenotes/source/conf.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,13 @@
8888
# (source start file, target name, title,
8989
# author, documentclass [howto, manual, or own class]).
9090
latex_documents = [
91-
('index', 'taskflowReleaseNotes.tex',
92-
'taskflow Release Notes Documentation',
93-
'taskflow Developers', 'manual'),
91+
(
92+
'index',
93+
'taskflowReleaseNotes.tex',
94+
'taskflow Release Notes Documentation',
95+
'taskflow Developers',
96+
'manual',
97+
),
9498
]
9599

96100

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@
1515

1616
import setuptools
1717

18-
setuptools.setup(
19-
setup_requires=['pbr>=2.0.0'],
20-
pbr=True)
18+
setuptools.setup(setup_requires=['pbr>=2.0.0'], pbr=True)

taskflow/atom.py

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,20 @@ def _save_as_to_mapping(save_as):
5252
# NOTE(harlowja): this means that your atom will return a indexable
5353
# object, like a list or tuple and the results can be mapped by index
5454
# to that tuple/list that is returned for others to use.
55-
return collections.OrderedDict((key, num)
56-
for num, key in enumerate(save_as))
55+
return collections.OrderedDict(
56+
(key, num) for num, key in enumerate(save_as)
57+
)
5758
elif isinstance(save_as, _set_types):
5859
# NOTE(harlowja): in the case where a set is given we will not be
5960
# able to determine the numeric ordering in a reliable way (since it
6061
# may be an unordered set) so the only way for us to easily map the
6162
# result of the atom will be via the key itself.
6263
return collections.OrderedDict((key, key) for key in save_as)
6364
else:
64-
raise TypeError('Atom provides parameter '
65-
'should be str, set or tuple/list, not %r' % save_as)
65+
raise TypeError(
66+
'Atom provides parameter '
67+
'should be str, set or tuple/list, not %r' % save_as
68+
)
6669

6770

6871
def _build_rebind_dict(req_args, rebind_args):
@@ -84,17 +87,19 @@ def _build_rebind_dict(req_args, rebind_args):
8487
# Extra things were rebound, that may be because of *args
8588
# or **kwargs (or some other reason); so just keep all of them
8689
# using 1:1 rebinding...
87-
rebind.update((a, a) for a in rebind_args[len(req_args):])
90+
rebind.update((a, a) for a in rebind_args[len(req_args) :])
8891
return rebind
8992
elif isinstance(rebind_args, dict):
9093
return rebind_args
9194
else:
92-
raise TypeError("Invalid rebind value '%s' (%s)"
93-
% (rebind_args, type(rebind_args)))
95+
raise TypeError(
96+
"Invalid rebind value '%s' (%s)" % (rebind_args, type(rebind_args))
97+
)
9498

9599

96-
def _build_arg_mapping(atom_name, reqs, rebind_args, function, do_infer,
97-
ignore_list=None):
100+
def _build_arg_mapping(
101+
atom_name, reqs, rebind_args, function, do_infer, ignore_list=None
102+
):
98103
"""Builds an input argument mapping for a given function.
99104
100105
Given a function, its requirements and a rebind mapping this helper
@@ -135,8 +140,9 @@ def _build_arg_mapping(atom_name, reqs, rebind_args, function, do_infer,
135140
# Determine if there are optional arguments that we may or may not take.
136141
if do_infer:
137142
opt_args = sets.OrderedSet(all_args)
138-
opt_args = opt_args - set(itertools.chain(required.keys(),
139-
iter(ignore_list)))
143+
opt_args = opt_args - set(
144+
itertools.chain(required.keys(), iter(ignore_list))
145+
)
140146
optional = collections.OrderedDict((a, a) for a in opt_args)
141147
else:
142148
optional = collections.OrderedDict()
@@ -146,14 +152,17 @@ def _build_arg_mapping(atom_name, reqs, rebind_args, function, do_infer,
146152
extra_args = sets.OrderedSet(required.keys())
147153
extra_args -= all_args
148154
if extra_args:
149-
raise ValueError('Extra arguments given to atom %s: %s'
150-
% (atom_name, list(extra_args)))
155+
raise ValueError(
156+
'Extra arguments given to atom %s: %s'
157+
% (atom_name, list(extra_args))
158+
)
151159

152160
# NOTE(imelnikov): don't use set to preserve order in error message
153161
missing_args = [arg for arg in req_args if arg not in required]
154162
if missing_args:
155-
raise ValueError('Missing arguments for atom %s: %s'
156-
% (atom_name, missing_args))
163+
raise ValueError(
164+
'Missing arguments for atom %s: %s' % (atom_name, missing_args)
165+
)
157166
return required, optional
158167

159168

@@ -244,9 +253,18 @@ class Atom(metaclass=abc.ABCMeta):
244253

245254
default_provides = None
246255

247-
def __init__(self, name=None, provides=None, requires=None,
248-
auto_extract=True, rebind=None, inject=None,
249-
ignore_list=None, revert_rebind=None, revert_requires=None):
256+
def __init__(
257+
self,
258+
name=None,
259+
provides=None,
260+
requires=None,
261+
auto_extract=True,
262+
rebind=None,
263+
inject=None,
264+
ignore_list=None,
265+
revert_rebind=None,
266+
revert_requires=None,
267+
):
250268

251269
if provides is None:
252270
provides = self.default_provides
@@ -263,8 +281,9 @@ def __init__(self, name=None, provides=None, requires=None,
263281
self.rebind, exec_requires, self.optional = self._build_arg_mapping(
264282
self.execute,
265283
requires=requires,
266-
rebind=rebind, auto_extract=auto_extract,
267-
ignore_list=ignore_list
284+
rebind=rebind,
285+
auto_extract=auto_extract,
286+
ignore_list=ignore_list,
268287
)
269288

270289
revert_ignore = ignore_list + list(_default_revert_args)
@@ -273,29 +292,42 @@ def __init__(self, name=None, provides=None, requires=None,
273292
requires=revert_requires or requires,
274293
rebind=revert_rebind or rebind,
275294
auto_extract=auto_extract,
276-
ignore_list=revert_ignore
295+
ignore_list=revert_ignore,
296+
)
297+
(self.revert_rebind, addl_requires, self.revert_optional) = (
298+
revert_mapping
277299
)
278-
(self.revert_rebind, addl_requires,
279-
self.revert_optional) = revert_mapping
280300

281301
# TODO(bnemec): This should be documented as an ivar, but can't be due
282302
# to https://github.com/sphinx-doc/sphinx/issues/2549
283303
#: A :py:class:`~taskflow.types.sets.OrderedSet` of inputs this atom
284304
#: requires to function.
285305
self.requires = exec_requires.union(addl_requires)
286306

287-
def _build_arg_mapping(self, executor, requires=None, rebind=None,
288-
auto_extract=True, ignore_list=None):
289-
290-
required, optional = _build_arg_mapping(self.name, requires, rebind,
291-
executor, auto_extract,
292-
ignore_list=ignore_list)
307+
def _build_arg_mapping(
308+
self,
309+
executor,
310+
requires=None,
311+
rebind=None,
312+
auto_extract=True,
313+
ignore_list=None,
314+
):
315+
316+
required, optional = _build_arg_mapping(
317+
self.name,
318+
requires,
319+
rebind,
320+
executor,
321+
auto_extract,
322+
ignore_list=ignore_list,
323+
)
293324
# Form the real rebind mapping, if a key name is the same as the
294325
# key value, then well there is no rebinding happening, otherwise
295326
# there will be.
296327
rebind = collections.OrderedDict()
297-
for (arg_name, bound_name) in itertools.chain(required.items(),
298-
optional.items()):
328+
for arg_name, bound_name in itertools.chain(
329+
required.items(), optional.items()
330+
):
299331
rebind.setdefault(arg_name, bound_name)
300332
requires = sets.OrderedSet(required.values())
301333
optional = sets.OrderedSet(optional.values())

taskflow/conductors/backends/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ def fetch(kind, name, jobboard, namespace=CONDUCTOR_NAMESPACE, **kwargs):
3434
LOG.debug('Looking for %r conductor driver in %r', kind, namespace)
3535
try:
3636
mgr = stevedore.driver.DriverManager(
37-
namespace, kind,
37+
namespace,
38+
kind,
3839
invoke_on_load=True,
3940
invoke_args=(name, jobboard),
40-
invoke_kwds=kwargs)
41+
invoke_kwds=kwargs,
42+
)
4143
return mgr.driver
4244
except RuntimeError as e:
4345
raise exc.NotFound("Could not find conductor %s" % (kind), e)

taskflow/conductors/backends/impl_blocking.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,24 @@ class BlockingConductor(impl_executor.ExecutorConductor):
2727
def _executor_factory():
2828
return futurist.SynchronousExecutor()
2929

30-
def __init__(self, name, jobboard,
31-
persistence=None, engine=None,
32-
engine_options=None, wait_timeout=None,
33-
log=None, max_simultaneous_jobs=MAX_SIMULTANEOUS_JOBS):
30+
def __init__(
31+
self,
32+
name,
33+
jobboard,
34+
persistence=None,
35+
engine=None,
36+
engine_options=None,
37+
wait_timeout=None,
38+
log=None,
39+
max_simultaneous_jobs=MAX_SIMULTANEOUS_JOBS,
40+
):
3441
super().__init__(
35-
name, jobboard,
36-
persistence=persistence, engine=engine,
42+
name,
43+
jobboard,
44+
persistence=persistence,
45+
engine=engine,
3746
engine_options=engine_options,
38-
wait_timeout=wait_timeout, log=log,
39-
max_simultaneous_jobs=max_simultaneous_jobs)
47+
wait_timeout=wait_timeout,
48+
log=log,
49+
max_simultaneous_jobs=max_simultaneous_jobs,
50+
)

0 commit comments

Comments
 (0)