Skip to content

Commit

Permalink
use hatch and hatch-vcs
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Nov 23, 2024
1 parent 0ad7fc0 commit 3bcce04
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 19 deletions.
128 changes: 128 additions & 0 deletions hatch.toml
Original file line number Diff line number Diff line change
@@ -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",
]
20 changes: 4 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions src/subliminal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 3bcce04

Please sign in to comment.