From c0f26cc156584b92a8ebf4b486a763f93483b936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 25 Nov 2024 10:32:09 +0100 Subject: [PATCH] Introduce ruff code checker and formatter - make code formatting consistent - discover issues like #6 earlier --- .github/workflows/pre-commit.yml | 27 +++++++++++++++++++++++++++ .pre-commit-config.yaml | 9 +++++++++ setup.py | 24 ++++++++++++------------ tests/test_altcha.py | 12 +++++++----- 4 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..4306816 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,27 @@ +name: pre-commit check + +on: + push: + pull_request: + +permissions: + contents: read + +jobs: + pre-commit: + runs-on: ubuntu-24.04 + + steps: + - uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.13' + - uses: astral-sh/setup-uv@v4 + - name: pre-commit + run: uvx pre-commit run --all + env: + RUFF_OUTPUT_FORMAT: github + - name: show diff + run: git diff + if: always() diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..739e997 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,9 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.8.0 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format diff --git a/setup.py b/setup.py index 7cff781..bb09779 100644 --- a/setup.py +++ b/setup.py @@ -1,21 +1,21 @@ from setuptools import setup, find_packages setup( - name='altcha', - version='0.1.5', - description='A library for creating and verifying challenges for ALTCHA.', - long_description=open('README.md').read(), - long_description_content_type='text/markdown', - author='Daniel Regeci', - author_email='536331+ovx@users.noreply.github.com', - url='https://github.com/altcha-org/altcha-lib-py', + name="altcha", + version="0.1.5", + description="A library for creating and verifying challenges for ALTCHA.", + long_description=open("README.md").read(), + long_description_content_type="text/markdown", + author="Daniel Regeci", + author_email="536331+ovx@users.noreply.github.com", + url="https://github.com/altcha-org/altcha-lib-py", packages=find_packages(), classifiers=[ - 'Programming Language :: Python :: 3', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", ], - python_requires='>=3.6', + python_requires=">=3.6", install_requires=[ # Add any dependencies here ], diff --git a/tests/test_altcha.py b/tests/test_altcha.py index 93c58e5..c6db5dd 100644 --- a/tests/test_altcha.py +++ b/tests/test_altcha.py @@ -19,7 +19,6 @@ class TestALTCHA(unittest.TestCase): - def setUp(self): self.hmac_key = "test-key" @@ -90,7 +89,8 @@ def test_verify_solution_not_expired(self): hmac_key=self.hmac_key, salt="somesalt", number=123, - expires=datetime.datetime.now().astimezone() + datetime.timedelta(minutes=1) + expires=datetime.datetime.now().astimezone() + + datetime.timedelta(minutes=1), ) challenge = create_challenge(options) payload = Payload( @@ -114,7 +114,8 @@ def test_verify_solution_expired(self): hmac_key=self.hmac_key, salt="somesalt", number=123, - expires=datetime.datetime.now().astimezone() - datetime.timedelta(minutes=1) + expires=datetime.datetime.now().astimezone() + - datetime.timedelta(minutes=1), ) challenge = create_challenge(options) payload = Payload( @@ -138,14 +139,15 @@ def test_verify_solution_malformed_expiry(self): hmac_key=self.hmac_key, salt="somesalt", number=123, - expires=datetime.datetime.now().astimezone() + datetime.timedelta(minutes=1) + expires=datetime.datetime.now().astimezone() + + datetime.timedelta(minutes=1), ) challenge = create_challenge(options) payload = Payload( algorithm="SHA-256", challenge=challenge.challenge, number=123, - salt='somesalt?expires=foobar', + salt="somesalt?expires=foobar", signature=challenge.signature, ) payload_encoded = base64.b64encode(