Skip to content

Commit 322ad6e

Browse files
authored
Merge pull request sphinx-contrib#233 from dhellmann/switch-to-hatch
Switch to hatch
2 parents 58821a6 + ab84297 commit 322ad6e

File tree

17 files changed

+209
-250
lines changed

17 files changed

+209
-250
lines changed

.github/workflows/check.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
tox-environment:
16-
- docs
17-
- linter
18-
- pkglint
19-
- spelling
20-
- isolated
15+
hatch-environment:
16+
- docs:build
17+
- docs:check
18+
- test:lint
19+
- test:pkglint
2120

2221
steps:
2322
- uses: actions/checkout@v4
@@ -30,7 +29,7 @@ jobs:
3029
python-version: '3.x'
3130

3231
- name: Install dependencies
33-
run: python -m pip install tox
32+
run: python -m pip install hatch
3433

3534
- name: Run
36-
run: tox -e ${{ matrix.tox-environment }}
35+
run: hatch run ${{ matrix.hatch-environment }}

.github/workflows/integration.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
python-version: '3.x'
2424

2525
- name: Install dependencies
26-
run: python3 -m pip install tox
26+
run: python3 -m pip install hatch
2727

28-
- name: Build docs
29-
run: python3 ./integration_tests/build_django.py
28+
- name: Test
29+
run: hatch run integration:django

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
python-version: ${{ matrix.python-version }}
2929

3030
- name: Install dependencies
31-
run: python -m pip install tox
31+
run: python -m pip install hatch
3232

3333
- name: Run tests
34-
run: tox -e py
34+
run: hatch run test:test

.mergify.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ pull_request_rules:
2424
- name: Automatic merge on approval
2525
conditions:
2626
- and:
27-
- "check-success=build (docs)"
28-
- "check-success=build (isolated)"
29-
- "check-success=build (linter)"
30-
- "check-success=build (spelling)"
27+
- "check-success=build (docs:build)"
28+
- "check-success=build (test:linter)"
29+
- "check-success=build (docs:spelling)"
3130
- "check-success=django"
3231
- "check-success=build (3.10)"
3332
- "check-success=build (3.11)"
File renamed without changes.

docs/source/history.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
Next
2525
====
2626

27-
- Modernize packaging using setuptools, build, and setuptools_scm
28-
instead of pbr.
27+
- Modernize packaging using hatch and hatchling.
2928

3029
Bug Fixes
3130
---------

integration_tests/build_django.py

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22
#
3-
"""Try to build the Django documentation.
4-
"""
3+
"""Try to build the Django documentation."""
54

65
import argparse
76
import os
@@ -10,70 +9,83 @@
109
import tempfile
1110

1211

13-
def doit(*cmd, description='', cwd=None):
14-
print(f'\n[{description}]\nrunning: {" ".join(cmd)}')
12+
def doit(*cmd, description="", cwd=None):
13+
print(f"\n[{description}]\nrunning: {' '.join(cmd)}")
1514
completed = subprocess.run(cmd, cwd=cwd)
1615
try:
1716
completed.check_returncode()
1817
except subprocess.CalledProcessError as err:
19-
raise RuntimeError(f'command failed {description}') from err
18+
raise RuntimeError(f"command failed {description}") from err
2019

2120

2221
def try_build(workdir, srcdir, django_repo):
23-
print(f'working in {workdir}')
22+
print(f"working in {workdir}")
2423
doit(
25-
'git', 'clone', '--depth', '1', django_repo, 'django',
26-
description='clone django',
24+
"git",
25+
"clone",
26+
"--depth",
27+
"1",
28+
django_repo,
29+
"django",
30+
description="clone django",
2731
cwd=workdir,
2832
)
29-
djangodir = workdir + '/django'
33+
djangodir = workdir + "/django"
3034
doit(
31-
'tox', '-e', 'docs', '--notest',
32-
description='build django docs virtualenv',
35+
"tox",
36+
"-e",
37+
"docs",
38+
"--notest",
39+
description="build django docs virtualenv",
3340
cwd=djangodir,
3441
)
3542
doit(
36-
'.tox/docs/bin/pip', 'uninstall', '-y', 'sphinxcontrib-spelling',
37-
description='uninstall packaged sphinxcontrib-spelling',
43+
".tox/docs/bin/pip",
44+
"uninstall",
45+
"-y",
46+
"sphinxcontrib-spelling",
47+
description="uninstall packaged sphinxcontrib-spelling",
3848
cwd=djangodir,
3949
)
4050
doit(
41-
'.tox/docs/bin/pip', 'install', srcdir,
42-
description='install sphinxcontrib-spelling from source',
51+
".tox/docs/bin/pip",
52+
"install",
53+
srcdir,
54+
description="install sphinxcontrib-spelling from source",
4355
cwd=djangodir,
4456
)
4557
doit(
46-
'tox', '-e', 'docs',
47-
description='build django docs',
58+
"tox",
59+
"-e",
60+
"docs",
61+
description="build django docs",
4862
cwd=djangodir,
4963
)
5064

5165

5266
def main(args=sys.argv[1:]):
5367
parser = argparse.ArgumentParser()
54-
parser.add_argument('--debug', action='store_true', default=False,
55-
help='show full tracebacks')
56-
parser.add_argument('--src', help='source directory')
57-
parser.add_argument('--django-repo',
58-
default='https://github.com/django/django.git')
68+
parser.add_argument(
69+
"--debug", action="store_true", default=False, help="show full tracebacks"
70+
)
71+
parser.add_argument("--src", help="source directory")
72+
parser.add_argument("--django-repo", default="https://github.com/django/django.git")
5973
parsed = parser.parse_args(args)
6074

6175
srcdir = parsed.src
6276
if not srcdir:
63-
srcdir = os.path.realpath(
64-
os.path.dirname(os.path.dirname(sys.argv[0]))
65-
)
77+
srcdir = os.path.realpath(os.path.dirname(os.path.dirname(sys.argv[0])))
6678

6779
try:
6880
with tempfile.TemporaryDirectory() as dirname:
6981
try_build(dirname, srcdir, parsed.django_repo)
7082
except Exception as err:
7183
if parsed.debug:
7284
raise
73-
print(f'ERROR: {err}')
85+
print(f"ERROR: {err}")
7486
return 1
7587
return 0
7688

7789

78-
if __name__ == '__main__':
90+
if __name__ == "__main__":
7991
sys.exit(main())

pyproject.toml

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[build-system]
2-
requires = ["setuptools", "setuptools_scm[toml]>=6.2"]
3-
build-backend = "setuptools.build_meta"
2+
requires = ["hatchling", "hatch-vcs"]
3+
build-backend = "hatchling.build"
44

55
[project]
66
name = "sphinxcontrib-spelling"
7-
readme = "README"
7+
readme = "README.rst"
88
authors = [{ name = "Doug Hellmann", email = "[email protected]" }]
99
description = "Sphinx spelling extension"
1010
dynamic = ["version"]
@@ -42,11 +42,55 @@ spelling = "sphinxcontrib.spelling"
4242
homepage = "https://sphinxcontrib-spelling.readthedocs.io/en/latest/"
4343
repository = "https://github.com/sphinx-contrib/spelling"
4444

45-
# https://github.com/pypa/setuptools_scm/
46-
[tool.setuptools_scm]
47-
write_to = "sphinxcontrib/spelling/version.py"
45+
[tool.hatch.version]
46+
source = "vcs"
4847

49-
[tool.setuptools]
50-
# Be explicit to avoid an error because build finds cover,
51-
# sphinxcontrib, and integration_tests as potential packages.
52-
packages = ["sphinxcontrib.spelling"]
48+
[tool.hatch.build.hooks.vcs]
49+
version-file = "sphinxcontrib/spelling/version.py"
50+
51+
[tool.hatch.build.targets.sdist]
52+
exclude = [".github", "cover", ".mergify.yml", ".gitignore"]
53+
[tool.hatch.build.targets.wheel]
54+
only-include = ["sphinxcontrib"]
55+
56+
[tool.hatch.envs.docs]
57+
dependencies = ["sphinx"]
58+
[tool.hatch.envs.docs.env]
59+
ENABLE_SPELLING = "1"
60+
[tool.hatch.envs.docs.scripts]
61+
build = [
62+
"sphinx-build -W -j auto -b html -d docs/build/doctrees docs/source docs/build/html",
63+
"sphinx-build -W -j auto -b linkcheck -d docs/build/doctrees docs/source docs/build/linkcheck",
64+
"sphinx-build -W -j auto -b spelling -d docs/build/doctrees docs/source docs/build/spelling",
65+
]
66+
check = "sphinx-build -W -j auto -b spelling -d docs/build/doctrees docs/source docs/build/spelling"
67+
68+
[tool.hatch.envs.test]
69+
dependencies = [
70+
"pytest",
71+
"pytest-cov",
72+
"coverage!=4.4,>=4.0",
73+
"ruff",
74+
"twine",
75+
"check-python-versions",
76+
]
77+
[tool.hatch.envs.test.scripts]
78+
test = "python -m pytest --cov=sphinxcontrib.spelling --cov-report term-missing --log-level DEBUG tests"
79+
lint = [
80+
"ruff check sphinxcontrib integration_tests tests",
81+
"ruff format --check sphinxcontrib integration_tests tests",
82+
]
83+
lint-fix = ["ruff format sphinxcontrib integration_tests tests"]
84+
pkglint = [
85+
"hatch build",
86+
"twine check dist/*.tar.gz dist/*.whl",
87+
"check-python-versions --only pyproject.toml,.github/workflows/test.yml",
88+
]
89+
90+
[tool.hatch.envs.integration]
91+
dependencies = ["tox"]
92+
[tool.hatch.envs.integration.scripts]
93+
django = "./integration_tests/build_django.py"
94+
95+
[tool.ruff]
96+
exclude = ["sphinxcontrib/spelling/version.py"]

sphinxcontrib/spelling/__init__.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,51 @@
1313

1414

1515
def setup(app):
16-
version = importlib_metadata.version('sphinxcontrib-spelling')
17-
logger.info('Initializing Spelling Checker %s', version)
16+
version = importlib_metadata.version("sphinxcontrib-spelling")
17+
logger.info("Initializing Spelling Checker %s", version)
1818
app.add_builder(builder.SpellingBuilder)
1919
# Register the 'spelling' directive for setting parameters within
2020
# a document
21-
app.add_directive('spelling', directive.LegacySpellingDirective)
21+
app.add_directive("spelling", directive.LegacySpellingDirective)
2222
app.add_domain(domain.SpellingDomain)
2323
# Register an environment collector to merge data gathered by the
2424
# directive in parallel builds
2525
app.add_env_collector(asset.SpellingCollector)
2626
# Report guesses about correct spelling
27-
app.add_config_value('spelling_show_suggestions', False, 'env')
27+
app.add_config_value("spelling_show_suggestions", False, "env")
2828
# Limit the number of suggestions output
29-
app.add_config_value('spelling_suggestion_limit', 0, 'env')
29+
app.add_config_value("spelling_suggestion_limit", 0, "env")
3030
# Report the whole line that has the error
31-
app.add_config_value('spelling_show_whole_line', True, 'env')
31+
app.add_config_value("spelling_show_whole_line", True, "env")
3232
# Emit misspelling as a sphinx warning instead of info message
33-
app.add_config_value('spelling_warning', False, 'env')
33+
app.add_config_value("spelling_warning", False, "env")
3434
# Set the language for the text
35-
app.add_config_value('spelling_lang', 'en_US', 'env')
35+
app.add_config_value("spelling_lang", "en_US", "env")
3636
# Set the language for the tokenizer
37-
app.add_config_value('tokenizer_lang', 'en_US', 'env')
37+
app.add_config_value("tokenizer_lang", "en_US", "env")
3838
# Set a user-provided list of words known to be spelled properly
39-
app.add_config_value('spelling_word_list_filename', None, 'env')
39+
app.add_config_value("spelling_word_list_filename", None, "env")
4040
# Assume anything that looks like a PyPI package name is spelled properly
41-
app.add_config_value('spelling_ignore_pypi_package_names', False, 'env')
41+
app.add_config_value("spelling_ignore_pypi_package_names", False, "env")
4242
# Assume words that look like wiki page names are spelled properly
43-
app.add_config_value('spelling_ignore_wiki_words', True, 'env')
43+
app.add_config_value("spelling_ignore_wiki_words", True, "env")
4444
# Assume words that are all caps, or all caps with trailing s, are
4545
# spelled properly
46-
app.add_config_value('spelling_ignore_acronyms', True, 'env')
46+
app.add_config_value("spelling_ignore_acronyms", True, "env")
4747
# Assume words that are part of __builtins__ are spelled properly
48-
app.add_config_value('spelling_ignore_python_builtins', True, 'env')
48+
app.add_config_value("spelling_ignore_python_builtins", True, "env")
4949
# Assume words that look like the names of importable modules are
5050
# spelled properly
51-
app.add_config_value('spelling_ignore_importable_modules', True, 'env')
51+
app.add_config_value("spelling_ignore_importable_modules", True, "env")
5252
# Treat contributor names from git history as spelled correctly
53-
app.add_config_value('spelling_ignore_contributor_names', True, 'env')
53+
app.add_config_value("spelling_ignore_contributor_names", True, "env")
5454
# Add any user-defined filter classes
55-
app.add_config_value('spelling_filters', [], 'env')
55+
app.add_config_value("spelling_filters", [], "env")
5656
# Set a user-provided list of files to ignore
57-
app.add_config_value('spelling_exclude_patterns', [], 'env')
57+
app.add_config_value("spelling_exclude_patterns", [], "env")
5858
# Choose whether or not the misspelled output should be displayed
5959
# in the terminal
60-
app.add_config_value('spelling_verbose', True, 'env')
60+
app.add_config_value("spelling_verbose", True, "env")
6161
return {
6262
"parallel_read_safe": True,
6363
"parallel_write_safe": True,

sphinxcontrib/spelling/asset.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
class SpellingCollector(EnvironmentCollector):
16-
1716
def clear_doc(self, app, env, docname) -> None:
1817
with contextlib.suppress(AttributeError, KeyError):
1918
del env.spelling_document_words[docname]
@@ -24,7 +23,7 @@ def merge_other(self, app, env, docnames, other):
2423
except AttributeError:
2524
other_words = {}
2625

27-
if not hasattr(env, 'spelling_document_words'):
26+
if not hasattr(env, "spelling_document_words"):
2827
env.spelling_document_words = collections.defaultdict(list)
2928
env.spelling_document_words.update(other_words)
3029

0 commit comments

Comments
 (0)