Skip to content

Commit

Permalink
Migrate to pre-commit
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin committed Sep 4, 2023
1 parent c718dce commit 84854f3
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 41 deletions.
40 changes: 40 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
---
default_language_version:
# force all unspecified python hooks to run python3
python: python3
repos:
- repo: https://github.com/ambv/black
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: mixed-line-ending
args: ['--fix', 'lf']
- id: check-byte-order-marker
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: debug-statements
- id: end-of-file-fixer
- id: check-yaml
files: .*\.(yaml|yml)$
- id: check-added-large-files
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
additional_dependencies:
- types-docutils
args: ['--explicit-package-bases']
exclude: |
(?x)(
tests/.*
)
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.black]
line-length = 88
target-version = ['py38']
skip-string-normalization = true
exclude = '''
(
/(
\.eggs
| \.git
| \.tox
| \.venv
| build
| dist
)
)
'''
7 changes: 4 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ packages =
namespace_packages =
sphinxcontrib

[flake8]
max-line-length = 88
ignore = E203,E501,E741,W503

[mypy]
show_column_numbers = true
show_error_context = true
Expand All @@ -41,6 +45,3 @@ follow_imports = skip
incremental = true
check_untyped_defs = true
warn_unused_ignores = true

[flake8]
show-source = True
2 changes: 1 addition & 1 deletion sphinxcontrib/apidoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


def setup(app):
# type: (Sphinx) -> Dict[unicode, Any]
# type: (Sphinx) -> Dict[str, Any]
app.setup_extension('sphinx.ext.autodoc') # We need autodoc to function

app.connect('builder-inited', ext.builder_inited)
Expand Down
17 changes: 12 additions & 5 deletions sphinxcontrib/apidoc/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

try:
from sphinx.ext import apidoc # Sphinx >= 1.7

_ignore_first_arg = False
except ImportError:
from sphinx import apidoc # Sphinx < 1.7

_ignore_first_arg = True

if False:
Expand All @@ -38,13 +40,16 @@ def builder_inited(app):
extra_args = app.config.apidoc_extra_args

if toc_file and sphinx.version_info < (1, 8, 0):
logger.warning("'apidoc_toc_file' is only supported by Sphinx "
"1.8+; skipping API doc generation")
logger.warning(
"'apidoc_toc_file' is only supported by Sphinx "
"1.8+; skipping API doc generation"
)
return

if not module_dir:
logger.warning("No 'apidoc_module_dir' specified; skipping API doc "
"generation")
logger.warning(
"No 'apidoc_module_dir' specified; skipping API doc " "generation"
)
return

# if the path is relative, make it relative to the 'conf.py' directory
Expand All @@ -54,7 +59,9 @@ def builder_inited(app):
if not path.exists(module_dir):
logger.warning(
"The path defined in 'apidoc_module_dir' does not "
"exist; skipping API doc generation; %s", module_dir)
"exist; skipping API doc generation; %s",
module_dir,
)
return

# refactor this module so that we can call 'recurse_tree' like a sane
Expand Down
8 changes: 2 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ def sphinx_test_tempdir():
from pathlib import Path

return Path(
os.environ.get(
'SPHINX_TEST_TEMPDIR', tempfile.mkdtemp(prefix='apidoc-'),
)
os.environ.get('SPHINX_TEST_TEMPDIR', tempfile.mkdtemp(prefix='apidoc-'))
).resolve()
else:
from sphinx.testing.path import path

return path(
os.environ.get(
'SPHINX_TEST_TEMPDIR', tempfile.mkdtemp(prefix='apidoc-'),
)
os.environ.get('SPHINX_TEST_TEMPDIR', tempfile.mkdtemp(prefix='apidoc-'))
).abspath()


Expand Down
20 changes: 10 additions & 10 deletions tests/test_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def test_advanced(app, status, warning):
assert is_dir(app.srcdir / 'api')
assert (app.srcdir / 'api' / 'custom.rst').exists()
for module in [
'apidoc_dummy_module.rst',
'apidoc_dummy_package.apidoc_dummy_submodule_a.rst',
'apidoc_dummy_package.apidoc_dummy_submodule_b.rst',
'apidoc_dummy_package._apidoc_private_dummy_submodule.rst',
'apidoc_dummy_module.rst',
'apidoc_dummy_package.apidoc_dummy_submodule_a.rst',
'apidoc_dummy_package.apidoc_dummy_submodule_b.rst',
'apidoc_dummy_package._apidoc_private_dummy_submodule.rst',
]:
assert (app.srcdir / 'api' / module).exists()
assert (app.srcdir / 'api' / 'apidoc_dummy_package.rst').exists()
Expand All @@ -68,10 +68,10 @@ def test_advanced(app, status, warning):
assert is_dir(app.outdir / 'api')
assert (app.outdir / 'api' / 'custom.html').exists()
for module in [
'apidoc_dummy_module.html',
'apidoc_dummy_package.apidoc_dummy_submodule_a.html',
'apidoc_dummy_package.apidoc_dummy_submodule_b.html',
'apidoc_dummy_package._apidoc_private_dummy_submodule.html',
'apidoc_dummy_module.html',
'apidoc_dummy_package.apidoc_dummy_submodule_a.html',
'apidoc_dummy_package.apidoc_dummy_submodule_b.html',
'apidoc_dummy_package._apidoc_private_dummy_submodule.html',
]:
assert (app.outdir / 'api' / module).exists()
assert (app.outdir / 'api' / 'apidoc_dummy_package.html').exists()
Expand All @@ -88,7 +88,7 @@ def test_advanced_negative(app, status, warning):

assert is_dir(app.srcdir / 'api')
for module in [
'apidoc_dummy_module.rst',
'apidoc_dummy_module.rst',
]:
assert (app.srcdir / 'api' / module).exists()
assert (app.srcdir / 'api' / 'apidoc_dummy_package.rst').exists()
Expand All @@ -103,7 +103,7 @@ def test_advanced_negative(app, status, warning):

assert is_dir(app.outdir / 'api')
for module in [
'apidoc_dummy_module.html',
'apidoc_dummy_module.html',
]:
assert (app.outdir / 'api' / module).exists()
assert (app.outdir / 'api' / 'apidoc_dummy_package.html').exists()
Expand Down
22 changes: 6 additions & 16 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,19 @@ minversion = 4.4
envlist = py{38,39,310,311},style

[testenv]
setenv =
PYTHONDEVMODE = 1
PYTHONWARNINGS = all
PYTEST_ADDOPTS = {env:PYTEST_ADDOPTS:} --color yes
deps =
-r{toxinidir}/test-requirements.txt
commands=
pytest

[testenv:mypy]
description =
Run type checks.
deps =
mypy
commands=
mypy sphinxcontrib

[testenv:style]
description =
Run style checks.
deps =
flake8
isort
yapf
doc8
pre-commit
commands =
isort -rc -c -df sphinxcontrib tests
yapf -rd sphinxcontrib tests
flake8 sphinxcontrib tests setup.py
doc8 -q README.rst
pre-commit run --all-files --show-diff-on-failure

0 comments on commit 84854f3

Please sign in to comment.