Skip to content

Commit 96d2db1

Browse files
committed
Replace flake8 with ruff
1 parent 1ede538 commit 96d2db1

File tree

29 files changed

+314
-226
lines changed

29 files changed

+314
-226
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ repos:
3030
- id: check-executables-have-shebangs
3131
- id: check-merge-conflict
3232
- id: debug-statements
33-
- repo: https://github.com/PyCQA/flake8
34-
rev: 6.0.0
33+
- repo: https://github.com/charliermarsh/ruff-pre-commit
34+
rev: "v0.0.262"
3535
hooks:
36-
- id: flake8
37-
additional_dependencies:
38-
- flake8-black
36+
- id: ruff
37+
args: [--fix, --exit-non-zero-on-fix]
3938
- repo: https://github.com/ansible/ansible-lint.git
4039
rev: v6.14.6
4140
hooks:

conftest.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import string
55

66
import pytest
7+
78
from molecule import config, logger, util
89
from molecule.scenario import ephemeral_directory
910

@@ -23,9 +24,9 @@ def _rebake_command(cmd, env, out=LOG.info, err=LOG.error):
2324
return cmd.bake(_env=env, _out=out, _err=err)
2425

2526

26-
@pytest.fixture
27+
@pytest.fixture()
2728
def random_string(length=5):
28-
return "".join((random.choice(string.ascii_uppercase) for _ in range(length)))
29+
return "".join(random.choice(string.ascii_uppercase) for _ in range(length))
2930

3031

3132
@contextlib.contextmanager
@@ -36,15 +37,15 @@ def change_dir_to(dir_name):
3637
os.chdir(cwd)
3738

3839

39-
@pytest.fixture
40+
@pytest.fixture()
4041
def temp_dir(tmpdir, random_string, request):
4142
directory = tmpdir.mkdir(random_string)
4243

4344
with change_dir_to(directory.strpath):
4445
yield directory
4546

4647

47-
@pytest.fixture
48+
@pytest.fixture()
4849
def resources_folder_path():
4950
resources_folder_path = os.path.join(os.path.dirname(__file__), "resources")
5051
return resources_folder_path
@@ -77,9 +78,9 @@ def get_molecule_file(path):
7778

7879
@pytest.helpers.register
7980
def molecule_ephemeral_directory(_fixture_uuid):
80-
project_directory = "test-project-{}".format(_fixture_uuid)
81+
project_directory = f"test-project-{_fixture_uuid}"
8182
scenario_name = "test-instance"
8283

8384
return ephemeral_directory(
84-
os.path.join("molecule_test", project_directory, scenario_name)
85+
os.path.join("molecule_test", project_directory, scenario_name),
8586
)

pyproject.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,44 @@ selinux = [
7979
'selinux; sys_platform=="linux"',
8080
]
8181

82+
[tool.ruff]
83+
ignore = [
84+
"E501", # we use black
85+
# we deliberately ignore these:
86+
"EM102",
87+
# temporary disabled until we either fix them or decide to ignore them:
88+
"A001",
89+
"ANN",
90+
"ARG",
91+
"B006",
92+
"B028",
93+
"BLE",
94+
"C901",
95+
"D",
96+
"DTZ",
97+
"EXE",
98+
"FBT",
99+
"INP",
100+
"ISC",
101+
"N",
102+
"PGH",
103+
"PLR",
104+
"PT",
105+
"PTH",
106+
"RET",
107+
"S",
108+
"TRY",
109+
]
110+
select = ["ALL"]
111+
target-version = "py39"
112+
# Same as Black.
113+
line-length = 88
114+
115+
[tool.ruff.flake8-pytest-style]
116+
parametrize-values-type = "tuple"
117+
118+
[tool.ruff.isort]
119+
known-first-party = ["molecule_plugins"]
82120

83121
[project.entry-points."molecule.driver"]
84122
azure = "molecule_plugins.azure.driver:Azure"

requirements.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ collections:
66
- name: community.docker
77
version: ">=3.0.2"
88
- name: containers.podman
9+
- name: community.crypto
10+
- name: community.vagrant

src/molecule_plugins/azure/driver.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1919
# DEALINGS IN THE SOFTWARE.
2020
import os
21-
from molecule import logger
22-
from molecule.api import Driver
2321

24-
from molecule import util
22+
from molecule import logger, util
23+
from molecule.api import Driver
2524

2625
LOG = logger.get_logger(__name__)
2726

@@ -72,10 +71,10 @@ class Azure(Driver):
7271
- foo
7372
7473
.. _`Azure`: https://azure.microsoft.com
75-
""" # noqa
74+
"""
7675

77-
def __init__(self, config=None):
78-
super(Azure, self).__init__(config)
76+
def __init__(self, config=None) -> None:
77+
super().__init__(config)
7978
self._name = "azure"
8079

8180
@property
@@ -125,7 +124,7 @@ def ansible_connection_options(self, instance_name):
125124
}
126125
except StopIteration:
127126
return {}
128-
except IOError:
127+
except OSError:
129128
# Instance has yet to be provisioned , therefore the
130129
# instance_config is not on disk.
131130
return {}

src/molecule_plugins/containers/driver.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
"""Containers Driver Module."""
2-
from __future__ import absolute_import
32

43
import inspect
54
import os
65
import shutil
7-
from typing import Dict
86

97
from molecule import logger
108

@@ -34,9 +32,9 @@ class Container(DriverBackend):
3432
3533
This class aims to provide an agnostic container enginer implementation,
3634
which should allow users to consume whichever enginer they have available.
37-
""" # noqa
35+
"""
3836

39-
def __init__(self, config=None):
37+
def __init__(self, config=None) -> None:
4038
"""Construct Container."""
4139
super().__init__(config)
4240
self._name = "containers"
@@ -45,7 +43,7 @@ def __init__(self, config=None):
4543
self._path = os.path.abspath(os.path.dirname(inspect.getfile(DriverBackend)))
4644

4745
@property
48-
def required_collections(self) -> Dict[str, str]:
46+
def required_collections(self) -> dict[str, str]:
4947
"""Return collections dict containing names and versions required."""
5048
return {
5149
"ansible.posix": "1.3.0",

src/molecule_plugins/docker/driver.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
# DEALINGS IN THE SOFTWARE.
2020
"""Docker Driver Module."""
2121

22-
from __future__ import absolute_import
2322

2423
import os
25-
from typing import Dict
2624

2725
from molecule import logger
2826
from molecule.api import Driver
@@ -187,13 +185,13 @@ class Docker(Driver):
187185
.. _`Docker`: https://www.docker.com
188186
.. _`systemd`: https://www.freedesktop.org/wiki/Software/systemd/
189187
.. _`CMD`: https://docs.docker.com/engine/reference/builder/#cmd
190-
""" # noqa
188+
"""
191189

192190
_passed_sanity = False
193191

194-
def __init__(self, config=None):
192+
def __init__(self, config=None) -> None:
195193
"""Construct Docker."""
196-
super(Docker, self).__init__(config)
194+
super().__init__(config)
197195
self._name = "docker"
198196

199197
@property
@@ -269,7 +267,7 @@ def reset(self):
269267
n.remove()
270268

271269
@property
272-
def required_collections(self) -> Dict[str, str]:
270+
def required_collections(self) -> dict[str, str]:
273271
"""Return collections dict containing names and versions required."""
274272
# https://galaxy.ansible.com/community/docker
275273
return {"community.docker": "3.0.2", "ansible.posix": "1.4.0"}

src/molecule_plugins/docker/playbooks/filter_plugins/get_docker_networks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_docker_networks(data, labels={}):
2828
return network_list
2929

3030

31-
class FilterModule(object):
31+
class FilterModule:
3232
"""Core Molecule filter plugins."""
3333

3434
def filters(self):

src/molecule_plugins/ec2/driver.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1919
# DEALINGS IN THE SOFTWARE.
2020

21-
from base64 import b64decode
2221
import os
2322
import sys
23+
from base64 import b64decode
2424

2525
try:
2626
from cryptography.hazmat.backends import default_backend
@@ -38,11 +38,9 @@
3838
except ImportError:
3939
HAS_BOTO3 = False
4040

41-
from molecule import logger
41+
from molecule import logger, util
4242
from molecule.api import Driver
4343

44-
from molecule import util
45-
4644
LOG = logger.get_logger(__name__)
4745

4846

@@ -153,10 +151,10 @@ class EC2(Driver):
153151
- foo
154152
155153
.. _`EC2`: https://aws.amazon.com/ec2/
156-
""" # noqa
154+
"""
157155

158-
def __init__(self, config=None):
159-
super(EC2, self).__init__(config)
156+
def __init__(self, config=None) -> None:
157+
super().__init__(config)
160158
self._name = "ec2"
161159

162160
@property
@@ -181,13 +179,12 @@ def login_cmd_template(self):
181179
if ansible_connection_options.get("ansible_connection") == "winrm":
182180
return (
183181
"xfreerdp "
184-
'"/u:%s" '
185-
'"/p:%s" '
186-
"/v:%s "
182+
'"/u:{}" '
183+
'"/p:{}" '
184+
"/v:{} "
187185
"/cert-tofu "
188186
"+clipboard "
189-
"/grab-keyboard"
190-
% (
187+
"/grab-keyboard".format(
191188
ansible_connection_options["ansible_user"],
192189
ansible_connection_options["ansible_password"],
193190
ansible_connection_options["ansible_host"],
@@ -244,12 +241,13 @@ def ansible_connection_options(self, instance_name):
244241
not conn_opts.get("ansible_password")
245242
):
246243
conn_opts["ansible_password"] = self._get_windows_instance_pass(
247-
d["instance_ids"][0], d["identity_file"]
244+
d["instance_ids"][0],
245+
d["identity_file"],
248246
)
249247
return conn_opts
250248
except StopIteration:
251249
return {}
252-
except IOError:
250+
except OSError:
253251
# Instance has yet to be provisioned , therefore the
254252
# instance_config is not on disk.
255253
return {}

src/molecule_plugins/gce/driver.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1818
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1919
# DEALINGS IN THE SOFTWARE.
20-
from typing import Dict
2120
import os
22-
from molecule import logger
23-
from molecule.api import Driver
2421

25-
from molecule import util
22+
from molecule import logger, util
23+
from molecule.api import Driver
2624

2725
LOG = logger.get_logger(__name__)
2826

@@ -77,10 +75,10 @@ class GCE(Driver):
7775
- foo
7876
7977
.. _`GCE`: https://cloud.google.com/compute/docs/
80-
""" # noqa
78+
"""
8179

82-
def __init__(self, config=None):
83-
super(GCE, self).__init__(config)
80+
def __init__(self, config=None) -> None:
81+
super().__init__(config)
8482
self._name = "gce"
8583

8684
@property
@@ -129,7 +127,7 @@ def ansible_connection_options(self, instance_name):
129127
"ansible_private_key_file": d["identity_file"],
130128
"ansible_connection": "ssh",
131129
"ansible_ssh_common_args": " ".join(
132-
self.ssh_connection_options
130+
self.ssh_connection_options,
133131
),
134132
}
135133

@@ -148,7 +146,7 @@ def ansible_connection_options(self, instance_name):
148146
}
149147
except StopIteration:
150148
return {}
151-
except IOError:
149+
except OSError:
152150
# Instance has yet to be provisioned , therefore the
153151
# instance_config is not on disk.
154152
return {}
@@ -171,6 +169,6 @@ def template_dir(self):
171169
return os.path.join(os.path.dirname(__file__), "cookiecutter")
172170

173171
@property
174-
def required_collections(self) -> Dict[str, str]:
172+
def required_collections(self) -> dict[str, str]:
175173
# https://galaxy.ansible.com/google/cloud
176174
return {"google.cloud": "1.0.2", "community.crypto": "1.8.0"}

0 commit comments

Comments
 (0)