From 3bcce0432ba362f1ea79907549e6edce96ec8a2f Mon Sep 17 00:00:00 2001 From: getzze Date: Sat, 23 Nov 2024 00:42:21 +0000 Subject: [PATCH] use hatch and hatch-vcs --- hatch.toml | 128 +++++++++++++++++++++++++++++++++++++ pyproject.toml | 20 ++---- src/subliminal/__init__.py | 12 +++- 3 files changed, 141 insertions(+), 19 deletions(-) create mode 100644 hatch.toml diff --git a/hatch.toml b/hatch.toml new file mode 100644 index 00000000..0196eee7 --- /dev/null +++ b/hatch.toml @@ -0,0 +1,128 @@ +# https://hatch.pypa.io/latest/config/environment/overview/ +# --------------------------------------------------------- +[envs.default] +description = "Development environment" +installer = "uv pip install" +features = [ + "tests", + "types", + "docs", + "dev", +] + +# --------------------------------------------------------- +[envs.pkg] +description = "package information" +features = [ + "tests", + "dev", +] +[envs.pkg.scripts] +show = [ + "uv pip list --format=columns", + 'python -c "import sys; print(sys.version); print(sys.executable)"', +] + +# --------------------------------------------------------- +[envs.lint] +template = "lint" +installer = "uv pip install" +description = "lint and format" +detached = true +dependencies = ["pre-commit"] + +[envs.lint.scripts] +run = "pre-commit run --all-files --show-diff-on-failure" + +# --------------------------------------------------------- +[envs.types] +template = "types" +installer = "uv pip install" +description = "Run the type checker" +dev-mode = false +features = ["tests", "types"] + +[envs.types.scripts] +run = "mypy --install-types --non-interactive --ignore-missing-imports --config-file={root}/pyproject.toml {args:src tests}" + +# --------------------------------------------------------- +[envs.docs] +template = "docs" +installer = "uv pip install" +description = "build and check documentation" +features = ["docs"] +# Keep in sync with CI.yaml/docs, tox/docs and .readthedocs.yaml. +python = "3.12" + +[envs.docs.scripts] +build = "sphinx-build -W --keep-going --color -b html docs docs/_build" +linkcheck = "sphinx-build -W --keep-going --color -b linkcheck docs docs/_build" +doctest = "sphinx-build -W --keep-going --color -b doctest docs docs/_build" +run = ["build", "linkcheck"] +all = ["build", "linkcheck", "doctest"] + +# --------------------------------------------------------- +[envs.changelog] +template = "changelog" +installer = "uv pip install" +description = "build changelog with towncrier" +dev-mode = false +dependencies = ["towncrier"] + +[envs.changelog.scripts] +run = "towncrier build --version main --draft" + +# --------------------------------------------------------- +[envs.tests] +template = "tests" +#installer = "uv pip install" +description = "Run the tests suite" +dev-mode = false +features = ["tests"] + +[[envs.tests.matrix]] +python = ["3.9", "3.10", "3.11", "3.12", "3.13"] + +[envs.tests.env-vars] +COVERAGE_PROCESS_START = "pyproject.toml" +COVERAGE_FILE = "report/.coverage.{matrix:python}" + +[envs.tests.overrides] +# To allow environment variable overwrite +env.COVERAGE_FILE.env-vars = "COVERAGE_FILE" +env.COVERAGE_PROCESS_START.env-vars = "COVERAGE_PROCESS_START" + +[envs.tests.scripts] +run = "pytest {args:-n auto}" +test-cov = "python -m pytest --cov=subliminal --cov-report= --cov-fail-under=0 {args:-n auto}" +test-cov-core = "python -m pytest -m core --cov=subliminal --cov-report= --cov-fail-under=0 {args:-n auto}" +run-cov = [ + "test-cov", + "coverage report --skip-covered --show-missing --fail-under=80", +] +run-cov-core = [ + "test-cov-core", + """\ + coverage report --skip-covered --show-missing --fail-under=100 \ + --omit='src/subliminal/cli.py,src/subliminal/converters/*,src/subliminal/providers/*,src/subliminal/refiners/*' \ + """, +] + +# --------------------------------------------------------- +[envs.coverage] +template = "coverage" +installer = "uv pip install" +description = "combine coverage files" +detached = true +dependencies = [ + "coverage[toml]>=7.3.2", +] +env-vars = { COVERAGE_FILE = "report/.coverage" } +# To allow environment variable overwrite +overrides = { env.COVERAGE_FILE.env-vars = "COVERAGE_FILE" } + +[envs.coverage.scripts] +run = [ + "- coverage combine report", + "coverage report --sort=-Cover --show-missing --skip-covered --skip-empty", +] diff --git a/pyproject.toml b/pyproject.toml index 41e14a4f..4708a887 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ # https://packaging.python.org/en/latest/specifications/pyproject-toml/ [build-system] -requires = ["setuptools>=64"] -build-backend = "setuptools.build_meta" +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" # https://peps.python.org/pep-0621/ [project] @@ -117,21 +117,9 @@ opensubtitlescom = "subliminal.converters.opensubtitlescom:OpenSubtitlesComConve subtitulamos = "subliminal.converters.subtitulamos:SubtitulamosConverter" tvsubtitles = "subliminal.converters.tvsubtitles:TVsubtitlesConverter" -[tool.setuptools] -py-modules = ["subliminal"] -include-package-data = true -[tool.setuptools.package-data] -subliminal = [ - "py.typed", -] - -[tool.setuptools.packages.find] -namespaces = false -where = ["src"] - -[tool.setuptools.dynamic] -version = {attr = "subliminal.__version__"} +[tool.hatch.version] +source = "vcs" # https://docs.pytest.org/en/6.2.x/customize.html diff --git a/src/subliminal/__init__.py b/src/subliminal/__init__.py index be2f8027..972a4670 100644 --- a/src/subliminal/__init__.py +++ b/src/subliminal/__init__.py @@ -2,14 +2,20 @@ from __future__ import annotations -__title__: str = 'subliminal' -__version__: str = '2.2.1' +import logging +from importlib.metadata import PackageNotFoundError, version + +# Must be first, otherwise we run into ImportError: partially initialized module +try: + __version__ = version('subliminal') +except PackageNotFoundError: + __version__ = 'undefined' __short_version__: str = '.'.join(__version__.split('.')[:2]) +__title__: str = 'subliminal' __author__: str = 'Antoine Bertin' __license__: str = 'MIT' __copyright__: str = 'Copyright 2016, Antoine Bertin' -import logging from .cache import region from .core import (