Skip to content
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
15 changes: 7 additions & 8 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ jobs:
strategy:
fail-fast: false
matrix:
tox-environment:
- docs
- linter
- pkglint
- spelling
- isolated
hatch-environment:
- docs:build
- docs:check
- test:lint
- test:pkglint

steps:
- uses: actions/checkout@v4
Expand All @@ -30,7 +29,7 @@ jobs:
python-version: '3.x'

- name: Install dependencies
run: python -m pip install tox
run: python -m pip install hatch

- name: Run
run: tox -e ${{ matrix.tox-environment }}
run: hatch run ${{ matrix.hatch-environment }}
6 changes: 3 additions & 3 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
python-version: '3.x'

- name: Install dependencies
run: python3 -m pip install tox
run: python3 -m pip install hatch

- name: Build docs
run: python3 ./integration_tests/build_django.py
- name: Test
run: hatch run integration:django
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: python -m pip install tox
run: python -m pip install hatch

- name: Run tests
run: tox -e py
run: hatch run test:test
7 changes: 3 additions & 4 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ pull_request_rules:
- name: Automatic merge on approval
conditions:
- and:
- "check-success=build (docs)"
- "check-success=build (isolated)"
- "check-success=build (linter)"
- "check-success=build (spelling)"
- "check-success=build (docs:build)"
- "check-success=build (test:linter)"
- "check-success=build (docs:spelling)"
- "check-success=django"
- "check-success=build (3.10)"
- "check-success=build (3.11)"
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions docs/source/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
Next
====

- Modernize packaging using setuptools, build, and setuptools_scm
instead of pbr.
- Modernize packaging using hatch and hatchling.

Bug Fixes
---------
Expand Down
66 changes: 39 additions & 27 deletions integration_tests/build_django.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3
#
"""Try to build the Django documentation.
"""
"""Try to build the Django documentation."""

import argparse
import os
Expand All @@ -10,70 +9,83 @@
import tempfile


def doit(*cmd, description='', cwd=None):
print(f'\n[{description}]\nrunning: {" ".join(cmd)}')
def doit(*cmd, description="", cwd=None):
print(f"\n[{description}]\nrunning: {' '.join(cmd)}")
completed = subprocess.run(cmd, cwd=cwd)
try:
completed.check_returncode()
except subprocess.CalledProcessError as err:
raise RuntimeError(f'command failed {description}') from err
raise RuntimeError(f"command failed {description}") from err


def try_build(workdir, srcdir, django_repo):
print(f'working in {workdir}')
print(f"working in {workdir}")
doit(
'git', 'clone', '--depth', '1', django_repo, 'django',
description='clone django',
"git",
"clone",
"--depth",
"1",
django_repo,
"django",
description="clone django",
cwd=workdir,
)
djangodir = workdir + '/django'
djangodir = workdir + "/django"
doit(
'tox', '-e', 'docs', '--notest',
description='build django docs virtualenv',
"tox",
"-e",
"docs",
"--notest",
description="build django docs virtualenv",
cwd=djangodir,
)
doit(
'.tox/docs/bin/pip', 'uninstall', '-y', 'sphinxcontrib-spelling',
description='uninstall packaged sphinxcontrib-spelling',
".tox/docs/bin/pip",
"uninstall",
"-y",
"sphinxcontrib-spelling",
description="uninstall packaged sphinxcontrib-spelling",
cwd=djangodir,
)
doit(
'.tox/docs/bin/pip', 'install', srcdir,
description='install sphinxcontrib-spelling from source',
".tox/docs/bin/pip",
"install",
srcdir,
description="install sphinxcontrib-spelling from source",
cwd=djangodir,
)
doit(
'tox', '-e', 'docs',
description='build django docs',
"tox",
"-e",
"docs",
description="build django docs",
cwd=djangodir,
)


def main(args=sys.argv[1:]):
parser = argparse.ArgumentParser()
parser.add_argument('--debug', action='store_true', default=False,
help='show full tracebacks')
parser.add_argument('--src', help='source directory')
parser.add_argument('--django-repo',
default='https://github.com/django/django.git')
parser.add_argument(
"--debug", action="store_true", default=False, help="show full tracebacks"
)
parser.add_argument("--src", help="source directory")
parser.add_argument("--django-repo", default="https://github.com/django/django.git")
parsed = parser.parse_args(args)

srcdir = parsed.src
if not srcdir:
srcdir = os.path.realpath(
os.path.dirname(os.path.dirname(sys.argv[0]))
)
srcdir = os.path.realpath(os.path.dirname(os.path.dirname(sys.argv[0])))

try:
with tempfile.TemporaryDirectory() as dirname:
try_build(dirname, srcdir, parsed.django_repo)
except Exception as err:
if parsed.debug:
raise
print(f'ERROR: {err}')
print(f"ERROR: {err}")
return 1
return 0


if __name__ == '__main__':
if __name__ == "__main__":
sys.exit(main())
64 changes: 54 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[build-system]
requires = ["setuptools", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "sphinxcontrib-spelling"
readme = "README"
readme = "README.rst"
authors = [{ name = "Doug Hellmann", email = "doug@doughellmann.com" }]
description = "Sphinx spelling extension"
dynamic = ["version"]
Expand Down Expand Up @@ -42,11 +42,55 @@ spelling = "sphinxcontrib.spelling"
homepage = "https://sphinxcontrib-spelling.readthedocs.io/en/latest/"
repository = "https://github.com/sphinx-contrib/spelling"

# https://github.com/pypa/setuptools_scm/
[tool.setuptools_scm]
write_to = "sphinxcontrib/spelling/version.py"
[tool.hatch.version]
source = "vcs"

[tool.setuptools]
# Be explicit to avoid an error because build finds cover,
# sphinxcontrib, and integration_tests as potential packages.
packages = ["sphinxcontrib.spelling"]
[tool.hatch.build.hooks.vcs]
version-file = "sphinxcontrib/spelling/version.py"

[tool.hatch.build.targets.sdist]
exclude = [".github", "cover", ".mergify.yml", ".gitignore"]
[tool.hatch.build.targets.wheel]
only-include = ["sphinxcontrib"]

[tool.hatch.envs.docs]
dependencies = ["sphinx"]
[tool.hatch.envs.docs.env]
ENABLE_SPELLING = "1"
[tool.hatch.envs.docs.scripts]
build = [
"sphinx-build -W -j auto -b html -d docs/build/doctrees docs/source docs/build/html",
"sphinx-build -W -j auto -b linkcheck -d docs/build/doctrees docs/source docs/build/linkcheck",
"sphinx-build -W -j auto -b spelling -d docs/build/doctrees docs/source docs/build/spelling",
]
check = "sphinx-build -W -j auto -b spelling -d docs/build/doctrees docs/source docs/build/spelling"

[tool.hatch.envs.test]
dependencies = [
"pytest",
"pytest-cov",
"coverage!=4.4,>=4.0",
"ruff",
"twine",
"check-python-versions",
]
[tool.hatch.envs.test.scripts]
test = "python -m pytest --cov=sphinxcontrib.spelling --cov-report term-missing --log-level DEBUG tests"
lint = [
"ruff check sphinxcontrib integration_tests tests",
"ruff format --check sphinxcontrib integration_tests tests",
]
lint-fix = ["ruff format sphinxcontrib integration_tests tests"]
pkglint = [
"hatch build",
"twine check dist/*.tar.gz dist/*.whl",
"check-python-versions --only pyproject.toml,.github/workflows/test.yml",
]

[tool.hatch.envs.integration]
dependencies = ["tox"]
[tool.hatch.envs.integration.scripts]
django = "./integration_tests/build_django.py"

[tool.ruff]
exclude = ["sphinxcontrib/spelling/version.py"]
38 changes: 19 additions & 19 deletions sphinxcontrib/spelling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,51 @@


def setup(app):
version = importlib_metadata.version('sphinxcontrib-spelling')
logger.info('Initializing Spelling Checker %s', version)
version = importlib_metadata.version("sphinxcontrib-spelling")
logger.info("Initializing Spelling Checker %s", version)
app.add_builder(builder.SpellingBuilder)
# Register the 'spelling' directive for setting parameters within
# a document
app.add_directive('spelling', directive.LegacySpellingDirective)
app.add_directive("spelling", directive.LegacySpellingDirective)
app.add_domain(domain.SpellingDomain)
# Register an environment collector to merge data gathered by the
# directive in parallel builds
app.add_env_collector(asset.SpellingCollector)
# Report guesses about correct spelling
app.add_config_value('spelling_show_suggestions', False, 'env')
app.add_config_value("spelling_show_suggestions", False, "env")
# Limit the number of suggestions output
app.add_config_value('spelling_suggestion_limit', 0, 'env')
app.add_config_value("spelling_suggestion_limit", 0, "env")
# Report the whole line that has the error
app.add_config_value('spelling_show_whole_line', True, 'env')
app.add_config_value("spelling_show_whole_line", True, "env")
# Emit misspelling as a sphinx warning instead of info message
app.add_config_value('spelling_warning', False, 'env')
app.add_config_value("spelling_warning", False, "env")
# Set the language for the text
app.add_config_value('spelling_lang', 'en_US', 'env')
app.add_config_value("spelling_lang", "en_US", "env")
# Set the language for the tokenizer
app.add_config_value('tokenizer_lang', 'en_US', 'env')
app.add_config_value("tokenizer_lang", "en_US", "env")
# Set a user-provided list of words known to be spelled properly
app.add_config_value('spelling_word_list_filename', None, 'env')
app.add_config_value("spelling_word_list_filename", None, "env")
# Assume anything that looks like a PyPI package name is spelled properly
app.add_config_value('spelling_ignore_pypi_package_names', False, 'env')
app.add_config_value("spelling_ignore_pypi_package_names", False, "env")
# Assume words that look like wiki page names are spelled properly
app.add_config_value('spelling_ignore_wiki_words', True, 'env')
app.add_config_value("spelling_ignore_wiki_words", True, "env")
# Assume words that are all caps, or all caps with trailing s, are
# spelled properly
app.add_config_value('spelling_ignore_acronyms', True, 'env')
app.add_config_value("spelling_ignore_acronyms", True, "env")
# Assume words that are part of __builtins__ are spelled properly
app.add_config_value('spelling_ignore_python_builtins', True, 'env')
app.add_config_value("spelling_ignore_python_builtins", True, "env")
# Assume words that look like the names of importable modules are
# spelled properly
app.add_config_value('spelling_ignore_importable_modules', True, 'env')
app.add_config_value("spelling_ignore_importable_modules", True, "env")
# Treat contributor names from git history as spelled correctly
app.add_config_value('spelling_ignore_contributor_names', True, 'env')
app.add_config_value("spelling_ignore_contributor_names", True, "env")
# Add any user-defined filter classes
app.add_config_value('spelling_filters', [], 'env')
app.add_config_value("spelling_filters", [], "env")
# Set a user-provided list of files to ignore
app.add_config_value('spelling_exclude_patterns', [], 'env')
app.add_config_value("spelling_exclude_patterns", [], "env")
# Choose whether or not the misspelled output should be displayed
# in the terminal
app.add_config_value('spelling_verbose', True, 'env')
app.add_config_value("spelling_verbose", True, "env")
return {
"parallel_read_safe": True,
"parallel_write_safe": True,
Expand Down
3 changes: 1 addition & 2 deletions sphinxcontrib/spelling/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class SpellingCollector(EnvironmentCollector):

def clear_doc(self, app, env, docname) -> None:
with contextlib.suppress(AttributeError, KeyError):
del env.spelling_document_words[docname]
Expand All @@ -24,7 +23,7 @@ def merge_other(self, app, env, docnames, other):
except AttributeError:
other_words = {}

if not hasattr(env, 'spelling_document_words'):
if not hasattr(env, "spelling_document_words"):
env.spelling_document_words = collections.defaultdict(list)
env.spelling_document_words.update(other_words)

Expand Down
Loading