Skip to content

Commit

Permalink
Prepare for a 0.0.1 (#2)
Browse files Browse the repository at this point in the history
* Use [hatch](https://hatch.pypa.io/latest/) as build system

* Add `pyproject.toml` and `tox.ini` linters

* Add GitHub actions workflows
  • Loading branch information
flaeppe authored Dec 14, 2023
1 parent 413eb65 commit be20387
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 83 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
69 changes: 69 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: CI

on:
push:
branches:
- main
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref | github.run_id }}
cancel-in-progress: true

jobs:
test:
name: Test ${{ matrix.py }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
py:
- "3.12"
- "3.11"
- "3.10"
- "3.9"
steps:
- uses: actions/checkout@v4
- name: Setup python for tox
uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: python -m pip install tox
- uses: actions/checkout@v4
- name: Setup python for test ${{ matrix.py }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.py }}
- name: Pick environment to test
shell: python
run: |
import codecs; import os; import sys
env = "TOXENV=py{}{}\n".format(*sys.version_info[:2])
print(f"Picked:\n{env}for{sys.version}")
with codecs.open(os.environ["GITHUB_ENV"], "a", "utf-8") as file_handler:
file_handler.write(env)
- name: Setup test suite
run: tox -vv --notest
- name: Run test suite
run: tox --skip-pkg-install

static-typing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- run: python -m pip install tox
- name: Run mypy
run: tox -e mypy

lint:
name: Lint
uses: less-action/reusables/.github/workflows/pre-commit.yaml@main
with:
python-version: "3.12"

check-build:
name: Check packaging
uses: less-action/reusables/.github/workflows/python-test-build.yaml@main
11 changes: 11 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Release

on:
release:
types: [published]

jobs:
build-and-publish:
uses: less-action/reusables/.github/workflows/python-publish.yaml@v8
secrets:
pypi_api_token: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
src/bankid_sdk/__version__.py
src/bankid_sdk/_version.py

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
18 changes: 16 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.9
python: python3.12
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
Expand All @@ -12,6 +12,15 @@ repos:
- id: trailing-whitespace
- id: debug-statements
- id: detect-private-key
- repo: https://github.com/tox-dev/tox-ini-fmt
rev: "1.3.1"
hooks:
- id: tox-ini-fmt
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "1.5.3"
hooks:
- id: pyproject-fmt
additional_dependencies: ["tox>=4.9"]
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
Expand All @@ -20,6 +29,11 @@ repos:
rev: 'v0.1.5'
hooks:
- id: ruff
- repo: https://github.com/sirosen/check-jsonschema
rev: 0.27.3
hooks:
- id: check-github-workflows
args: ["--verbose"]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.37.0
hooks:
Expand All @@ -41,7 +55,7 @@ exclude: |
| build
| dist
)/
| ^src/bankid_api/__version__\.py$
| ^src/bankid_api/_version\.py$
| ^tests/fixtures/fake_cert\.pem$
| ^tests/fixtures/fake_client\.key$
)
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
${pkgs.python39}/bin/python -m \
venv --copies --upgrade-deps .venv > /dev/null
source .venv/bin/activate
pip install --require-virtualenv --no-input tox
'';
};
});
Expand Down
134 changes: 89 additions & 45 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,68 +1,73 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
build-backend = "hatchling.build"
requires = [
"hatch-vcs",
"hatchling",
]

[project]
name = "bankid-sdk"
version = "0.0.1"
description = "A Python SDK for BankID"
readme = "README.md"
keywords = [
"bankid",
"client",
"django",
"rest",
]
license = "BSD-3-Clause"
authors = [{ name = "Jonas Lundberg", email = "jonas@5monkeys.se" }]
requires-python = ">=3.9"
classifiers = [
"Development Status :: 4 - Beta",
"Framework :: Django",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Typing :: Typed",
]
dynamic = [
"version",
]
dependencies = [
"abcattrs",
"httpx",
]

[project.optional-dependencies]
dev = [
optional-dependencies.dev = [
"bankid-sdk[test]",
"mypy",
"pre-commit",
]
optional-dependencies.django = [
"django",
]
optional-dependencies.test = [
"bankid-sdk[django]",
"dirty-equals",
"django-stubs",
"freezegun",
"mypy",
"pre-commit",
"pytest",
"pytest-asyncio",
"pytest-cov",
"pytest-django",
"pytest-randomly",
"respx",
]
urls.Homepage = "https://github.com/5monkeys/bankid-sdk"
urls.Source = "https://github.com/5monkeys/bankid-sdk"
urls.Tracker = "https://github.com/5monkeys/bankid-sdk/issues"

[tool.pytest.ini_options]
testpaths = ["tests", "src"]
addopts = "--cov --no-cov-on-fail"
asyncio_mode = "auto"

[tool.coverage.report]
skip_covered = true
show_missing = true
exclude_also = [
# ignore non-implementations
'^\s*\.\.\.',
"if TYPE_CHECKING:",
'^\s*(def\s)?assert_never(.*)$',
]
fail_under = 100

[tool.coverage.run]
branch = true
source = ["src/"]
omit = [
"src/bankid_sdk/__version__.py",
]

[tool.mypy]
python_version = "3.9"
pretty = true
show_error_codes = true
files = "src, tests"
exclude = '''(?x)(
^src/bankid_sdk/__version__\.py$
)'''

no_implicit_optional = true
strict_optional = true
ignore_missing_imports = false
warn_unreachable = true
strict = true
[tool.hatch]
build.hooks.vcs.version-file = "src/bankid_sdk/_version.py"
version.source = "vcs"

[tool.black]
target-version = ["py39"]
Expand Down Expand Up @@ -124,3 +129,42 @@ ignore = [
[tool.ruff.isort]
known-first-party = ["bankid_sdk", "tests"]
combine-as-imports = true

[tool.pytest.ini_options]
testpaths = ["tests", "src"]
addopts = "--cov --no-cov-on-fail"
asyncio_mode = "auto"

[tool.coverage.paths]
source = [
"src/bankid_sdk",
".tox/*/lib/*/site-packages/bankid_sdk",
]

[tool.coverage.report]
skip_covered = true
show_missing = true
exclude_also = [
# ignore non-implementations
'^\s*\.\.\.',
"if TYPE_CHECKING:",
'^\s*(def\s)?assert_never(.*)$',
]
fail_under = 100

[tool.coverage.run]
parallel = true
branch = true
source = ["bankid_sdk", "tests"]

[tool.mypy]
python_version = "3.9"
pretty = true
show_error_codes = true
files = "src, tests"

no_implicit_optional = true
strict_optional = true
ignore_missing_imports = false
warn_unreachable = true
strict = true
13 changes: 6 additions & 7 deletions src/bankid_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from importlib.metadata import PackageNotFoundError, version

from ._actions import (
Action,
AuthAction,
Expand Down Expand Up @@ -30,7 +28,13 @@
from .errors import BankIDAPIError, BankIDHTTPError
from .typing import OrderRef, PersonalNumber

try:
from ._version import __version__
except ImportError: # pragma: no cover
__version__ = "unknown"

__all__ = [
"__version__",
"Action",
"AuthAction",
"AsyncV60",
Expand Down Expand Up @@ -64,8 +68,3 @@
"generate_qr_code",
"init_auth",
]

try:
__version__ = version(__name__)
except PackageNotFoundError:
__version__ = "unknown"
12 changes: 0 additions & 12 deletions src/bankid_sdk/_storage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from typing import Protocol
from uuid import uuid4

from bankid_sdk.typing import TransactionID

Expand All @@ -17,14 +16,3 @@ def load(self, key: TransactionID, /) -> Transaction | None:

def delete(self, key: TransactionID, /) -> None:
...


class NoStorage(Storage):
def save(self, obj: Transaction, /) -> TransactionID:
return TransactionID(str(uuid4()))

def load(self, key: TransactionID, /) -> Transaction | None:
return None

def delete(self, key: TransactionID, /) -> None:
...
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def configure_django() -> None:
try:
import django
except ImportError:
except ImportError: # pragma: no cover
return

from django.conf import settings
Expand Down
Loading

0 comments on commit be20387

Please sign in to comment.