Skip to content

Commit

Permalink
Move to Hatch (#131)
Browse files Browse the repository at this point in the history
* Move to Hatch

* Remove empty .gitmodules

* Make packaging metadata dynamic

* Get real version when checking package

* Use real versions with system-package

* Simplify tox.ini
  • Loading branch information
hynek committed Aug 24, 2022
1 parent 1e77c0a commit 3368bb1
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 48 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
env:
FORCE_COLOR: "1" # Make tools pretty.
TOX_TESTENV_PASSENV: FORCE_COLOR
SETUPTOOLS_SCM_PRETEND_VERSION: "1.0" # avoid warnings about shallow checkout
PYTHON_LATEST: "3.10"

jobs:
Expand Down Expand Up @@ -83,9 +84,13 @@ jobs:
system-package:
name: Install & test with system package of Argon2.
runs-on: ubuntu-latest
env:
SETUPTOOLS_SCM_PRETEND_VERSION: "" # inconsistency error otherwise

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: ${{env.PYTHON_LATEST}}
Expand All @@ -102,9 +107,13 @@ jobs:
package:
name: Build & verify package
runs-on: ubuntu-latest
env:
SETUPTOOLS_SCM_PRETEND_VERSION: ""

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: hynek/build-and-inspect-python-package@v1

install-dev:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
.coverage
.coverage.*
.direnv
.envrc
.hypothesis
.mypy_cache
.pytest_cache/
.tox
.vscode
Expand Down
Empty file removed .gitmodules
Empty file.
2 changes: 1 addition & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Credits & License

*argon2-cffi* is maintained by `Hynek Schlawack <https://hynek.me/>`_ and released under the `MIT license <https://github.com/hynek/argon2-cffi/blob/main/LICENSE>`_.

The development is kindly supported by `Variomedia AG <https://www.variomedia.de/>`_, *argon2-cffi* `Tidelift subscribers <https://tidelift.com/subscription/pkg/pypi-argon2-cffi?utm_source=pypi-argon2-cffi&utm_medium=referral&utm_campaign=enterprise&utm_term=repo>`_, and all my amazing `GitHub Sponsors <https://github.com/sponsors/hynek>`_.
The development is kindly supported by my employer `Variomedia AG <https://www.variomedia.de/>`_, *argon2-cffi* `Tidelift subscribers <https://tidelift.com/subscription/pkg/pypi-argon2-cffi?utm_source=pypi-argon2-cffi&utm_medium=referral&utm_campaign=enterprise&utm_term=repo>`_, and all my amazing `GitHub Sponsors <https://github.com/sponsors/hynek>`_.

A full list of contributors can be found in GitHub's `overview <https://github.com/hynek/argon2-cffi/graphs/contributors>`_.
38 changes: 19 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# SPDX-License-Identifier: MIT

[build-system]
requires = ["flit_core >=3.4,<4"]
build-backend = "flit_core.buildapi"
requires = ["hatchling", "hatch-vcs", "hatch-fancy-pypi-readme"]
build-backend = "hatchling.build"


[tool.hatch.build.targets.wheel]
packages = ["src/argon2"]


[project]
name = "argon2-cffi"
description = "Argon2 for Python"
authors = [{ name = "Hynek Schlawack", email = "hs@ox.cx" }]
dynamic = ["version"]
dynamic = ["version", "readme"]
requires-python = ">=3.7"
license = { file = "LICENSE" }
readme = "README.rst"
keywords = ["password", "hash", "hashing", "security"]
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand Down Expand Up @@ -47,29 +50,24 @@ docs = ["sphinx", "sphinx-notfound-page", "furo"]
dev = ["argon2-cffi[tests,docs]", "mypy"]

[project.urls]
Changelog = "https://github.com/hynek/argon2-cffi/blob/main/CHANGELOG.md"
Documentation = "https://argon2-cffi.readthedocs.io/"
Changelog = "https://github.com/hynek/argon2-cffi/blob/main/CHANGELOG.md"
"Source Code" = "https://github.com/hynek/argon2-cffi"
Funding = "https://github.com/sponsors/hynek"
Tidelift = "https://tidelift.com/subscription/pkg/pypi-argon2-cffi?utm_source=pypi-argon2-cffi&utm_medium=pypi"
Ko-fi = "https://ko-fi.com/the_hynek"


[tool.flit.module]
name = "argon2"
[tool.hatch.version]
source = "vcs"
raw-options = { version_scheme = "no-guess-dev" }

[tool.flit.sdist]
include = [
".github",
".pre-commit-config.yaml",
".readthedocs.yml",
"*.ini",
"*.md",
"*.rst",
"docs",
"tests",
]
exclude = ["docs/_build", "tests/__pycache__", "tests/.mypy_cache"]

[tool.hatch.metadata.hooks.fancy-pypi-readme]
content-type = "text/x-rst"

[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
path = "README.rst"


[tool.pytest.ini_options]
Expand Down Expand Up @@ -110,6 +108,8 @@ omit = []


[tool.mypy]
show_error_codes = true

# show error messages from unrelated files
follow_imports = "normal"

Expand Down
46 changes: 38 additions & 8 deletions src/argon2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,11 @@
from .low_level import Type


__version__ = "22.1.0.dev0"

__title__ = "argon2-cffi"
__description__ = (__doc__ or "").strip()
__url__ = "https://argon2-cffi.readthedocs.io/"
__uri__ = __url__

__author__ = "Hynek Schlawack"
__email__ = "hs@ox.cx"

__license__ = "MIT"
__copyright__ = "Copyright (c) 2015 " + __author__
__license__ = "MIT"


__all__ = [
Expand All @@ -49,3 +42,40 @@
"profiles",
"verify_password",
]


def __getattr__(name: str) -> str:
dunder_to_metadata = {
"__version__": "version",
"__description__": "summary",
"__uri__": "",
"__url__": "",
"__email__": "",
}
if name not in dunder_to_metadata.keys():
raise AttributeError(f"module {__name__} has no attribute {name}")

import sys
import warnings

if sys.version_info < (3, 8):
from importlib_metadata import metadata
else:
from importlib.metadata import metadata

warnings.warn(
f"Accessing argon2.{name} is deprecated and will be "
"removed in a future release. Use importlib.metadata directly "
"to query for structlog's packaging metadata.",
DeprecationWarning,
stacklevel=2,
)

meta = metadata("argon2-cffi")

if name in ("__uri__", "__url__"):
return meta["Project-URL"].split(" ", 1)[-1]
elif name == "__email__":
return meta["Author-email"].split("<", 1)[1].rstrip(">")

return meta[dunder_to_metadata[name]]
55 changes: 55 additions & 0 deletions tests/test_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SPDX-License-Identifier: MIT

import sys

import pytest

import argon2


if sys.version_info < (3, 8):
import importlib_metadata as metadata
else:
from importlib import metadata


class TestLegacyMetadataHack:
def test_version(self):
"""
argon2.__version__ returns the correct version.
"""
with pytest.deprecated_call():
assert metadata.version("argon2-cffi") == argon2.__version__

def test_description(self):
"""
argon2.__description__ returns the correct description.
"""
with pytest.deprecated_call():
assert "Argon2 for Python" == argon2.__description__

def test_uri(self):
"""
argon2.__uri__ returns the correct project URL.
"""
with pytest.deprecated_call():
assert "https://argon2-cffi.readthedocs.io/" == argon2.__uri__

with pytest.deprecated_call():
assert "https://argon2-cffi.readthedocs.io/" == argon2.__url__

def test_email(self):
"""
argon2.__email__ returns Hynek's email address.
"""
with pytest.deprecated_call():
assert "hs@ox.cx" == argon2.__email__

def test_does_not_exist(self):
"""
Asking for unsupported dunders raises an AttributeError.
"""
with pytest.raises(
AttributeError, match="module argon2 has no attribute __yolo__"
):
argon2.__yolo__
32 changes: 12 additions & 20 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,20 @@ commands = pre-commit run --all-files

[testenv:mypy]
description = Check types
basepython = python3.9
extras = tests
deps = mypy
commands = mypy src typing_examples.py


[testenv]
description = Run tests and do NOT measure coverage.
extras = tests
commands =
python -m pytest {posargs}
python -m argon2 -n 1 -t 1 -m 8 -p 1


[testenv:py37]
description = Run tests and measure coverage.
extras = tests
deps = coverage[toml]
commands =
coverage run -m pytest {posargs}
Expand All @@ -65,7 +70,6 @@ commands =

[testenv:py310]
description = Run tests and measure coverage.
extras = tests
deps = coverage[toml]
commands =
coverage run -m pytest {posargs}
Expand All @@ -75,30 +79,20 @@ commands =

[testenv:coverage-report]
description = Report coverage over all test runs.
skip_install = true
depends =
py37
py310
basepython = python3.10
deps = coverage[toml]
skip_install = true
commands =
coverage combine
coverage report


[testenv]
description = Run tests and do NOT measure coverage.
extras = tests
commands =
python -m pytest {posargs}
python -m argon2 -n 1 -t 1 -m 8 -p 1


[testenv:system-argon2]
description = Run tests against bindings that use a system installation of Argon2.
basepython = python3.8
setenv = ARGON2_CFFI_USE_SYSTEM=1
extras = tests
install_command =
pip install {opts} --no-binary=argon2-cffi-bindings {packages}
commands =
Expand All @@ -108,18 +102,16 @@ commands =

[testenv:bindings-main]
description = Run tests against the current main branch of argon2-cffi-bindings
basepython = python3.10
extras = tests
install_command =
pip install {opts} --no-deps {packages}
install_command = pip install {opts} --no-deps {packages}
extras =
commands =
pip install hypothesis pytest git+https://github.com/hynek/argon2-cffi-bindings
python -m pytest {posargs}
python -m argon2 -n 1 -t 1 -m 8 -p 1


[testenv:pypi-description]
description = Ensure README.rst renders on PyPI.
description = Ensure README renders on PyPI.
skip_install = true
deps =
twine
Expand Down

0 comments on commit 3368bb1

Please sign in to comment.