Skip to content

Commit

Permalink
Introduce ruff code checker and formatter
Browse files Browse the repository at this point in the history
- make code formatting consistent
- discover issues like #6 earlier
  • Loading branch information
nijel committed Nov 25, 2024
1 parent fd302d5 commit c0f26cc
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 12 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]',
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="[email protected]",
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
],
Expand Down
12 changes: 7 additions & 5 deletions tests/test_altcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@


class TestALTCHA(unittest.TestCase):

def setUp(self):
self.hmac_key = "test-key"

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit c0f26cc

Please sign in to comment.