Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use hatch and hatch-vcs #1192

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 37 additions & 19 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version-file: .python-version-default
- name: Install tox-uv
run: python -Im pip install tox-uv
- name: Install hatch
run: python -Im pip install hatch
- name: type-check
run: python -Im tox run -e mypy
run: hatch run types:run

docs:
name: Build docs and run doctests
Expand All @@ -59,14 +59,18 @@ jobs:
persist-credentials: false
- uses: actions/setup-python@v5
with:
# Keep in sync with tox/docs and .readthedocs.yaml.
# Keep in sync with tox/docs, hatch.toml and .readthedocs.yaml.
python-version: "3.12"
cache: pip

- name: Install tox-uv
run: python -Im pip install tox-uv
- name: Build docs
run: python -Im tox run -e docs,changelog
- name: Install hatch
run: python -Im pip install hatch
- name: Build and check docs
run: hatch run docs:run
- name: Run doctests
run: hatch run docs:doctest
- name: Check changelog
run: hatch run changelog:run

- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -118,32 +122,46 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# Created by the build-and-inspect-python-package action above.
python-version: ${{ fromJson(needs.build-package.outputs.supported-python-versions) }}
py: ${{ fromJson(needs.build-package.outputs.supported-python-versions) }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.py }}
cache: 'pip'
allow-prereleases: true
- name: Install tox-uv
run: python -Im pip install tox-uv
- name: Install hatch
run: python -Im pip install hatch

- name: Run tests
- name: Pick environment to run
env:
PYTHON_VERSION: ${{ matrix.py }}
run: |
import codecs; import os
py = f"tests.py{os.environ.get('PYTHON_VERSION')}"
print(f"Picked {py}")
with codecs.open(os.environ["GITHUB_ENV"], mode="a", encoding="utf-8") as file_handler:
file_handler.write(f"FORCE_COLOR=1\nENV={py}\n")
shell: python
- name: Setup test environment
run: |
hatch -v env create ${ENV}
shell: bash
- name: Run test suite
env:
# Make sure to add `passenv=COVERAGE_FILE` to `[testenv]` in tox.ini
COVERAGE_FILE: ".coverage.${{ matrix.os }}.${{ matrix.python-version }}"
run: >-
uvx --with=tox-uv
tox run
-e py${{ matrix.python-version }}-coverage
# Make sure to add `overrides = { env.COVERAGE_FILE.env-vars = "COVERAGE_FILE" }` to `[tests]` in hatch.toml
COVERAGE_FILE: ".coverage.${{ matrix.os }}.${{ matrix.py }}"
CI_RUN: "yes"
run: hatch -v run ${ENV}:test-cov
shell: bash

- name: Store coverage file
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.os }}-${{ matrix.python-version }}
name: coverage-${{ matrix.os }}-${{ matrix.py }}
path: .coverage*
include-hidden-files: true
if-no-files-found: error
Expand Down
1 change: 1 addition & 0 deletions changelog.d/1192.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use hatch builder and hatch-vcs
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
Loading