From a0d310ddb84b877299e4cac82a6b71322f740ded Mon Sep 17 00:00:00 2001 From: Paul Arthur Date: Wed, 30 Oct 2024 15:18:03 +0000 Subject: [PATCH] Replace flake8 with ruff --- .github/workflows/build.yml | 12 +++++++++--- .ruff.toml | 8 ++++++++ test/conftest.py | 15 ++++++++++----- test/test_config.py | 8 ++++---- 4 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 .ruff.toml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 45004ea..92be632 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,17 +16,23 @@ jobs: git diff git status --porcelain | grep -q '^ M' && exit 1 || exit 0 - flake8: + ruff: runs-on: ubuntu-latest steps: - name: Check out code uses: actions/checkout@v4 - name: Install flake8 - run: sudo pip install flake8 + run: sudo pip install ruff - name: Lint Python code - run: flake8 --max-line-length=160 + run: ruff check + + - name: Lint Python code formatting + run: | + ruff format + git diff + git status --porcelain | grep -q '^ M' && exit 1 || exit 0 check: runs-on: ubuntu-latest diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 0000000..639bfd4 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,8 @@ +line-length = 160 + +[lint] +select = ["F", "E", "W", "B", "RUF"] +ignore = ["B007"] + +[format] +quote-style = "single" diff --git a/test/conftest.py b/test/conftest.py index 37324e9..b2eea6b 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -14,7 +14,8 @@ def private_key(scope='session'): binargs = [ 'openssl', 'genrsa', - '-out', keypath, + '-out', + keypath, '2048', ] subprocess.run(binargs) @@ -23,7 +24,8 @@ def private_key(scope='session'): binargs = [ 'openssl', 'rsa', - '-in', keypath, + '-in', + keypath, '-pubout', ] res = subprocess.run(binargs, capture_output=True, text=True) @@ -48,6 +50,7 @@ def _tool_path(tool): binpath = os.path.dirname(os.path.realpath(__file__)) binpath = os.path.join(binpath, '..', tool) return os.path.realpath(binpath) + return _tool_path @@ -60,7 +63,7 @@ def milter_config(request, tmp_path, private_key): 'sock': tmp_path.joinpath('milter.sock'), } for candidate in [ - request.fspath.basename, # test file + request.fspath.basename, # test file request.function.__name__, # test function ]: fname = os.path.join(base_path, '.'.join([candidate, 'conf'])) @@ -77,8 +80,10 @@ def milter_cmdline(tmp_path, tool_path, milter_config): tool_path('openarc/openarc'), '-f', '-v', - '-c', milter_config['file'], - '-p', milter_config['sock'], + '-c', + milter_config['file'], + '-p', + milter_config['sock'], ] diff --git a/test/test_config.py b/test/test_config.py index f880f69..5b0747e 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -5,25 +5,25 @@ def test_config(milter_config, milter_cmdline): """A basic config should parse without error""" - res = subprocess.run(milter_cmdline + ['-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4) + res = subprocess.run([*milter_cmdline, '-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4) assert res.returncode == 0 def test_config_fail(milter_config, milter_cmdline): """An invalid config should fail and return an error""" - res = subprocess.run(milter_cmdline + ['-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4) + res = subprocess.run([*milter_cmdline, '-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4) assert res.returncode != 0 assert 'parameter "KeyFile" required when signing' in res.stderr def test_config_requiresafekeys(milter_config, milter_cmdline): """World-readable keys should be rejected""" - res = subprocess.run(milter_cmdline + ['-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4) + res = subprocess.run([*milter_cmdline, '-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4) assert res.returncode != 0 assert 'can be read or written by other users' in res.stderr def test_config_requiresafekeys_false(milter_config, milter_cmdline): """World-readable keys are okay if the user said they're okay.""" - res = subprocess.run(milter_cmdline + ['-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4) + res = subprocess.run([*milter_cmdline, '-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4) assert res.returncode == 0