diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4502ab3 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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/.* + ) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ceb090e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[tool.black] +line-length = 88 +target-version = ['py38'] +skip-string-normalization = true +exclude = ''' +( + /( + \.eggs + | \.git + | \.tox + | \.venv + | build + | dist + ) +) +''' diff --git a/setup.cfg b/setup.cfg index eea740d..115a992 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 @@ -41,6 +45,3 @@ follow_imports = skip incremental = true check_untyped_defs = true warn_unused_ignores = true - -[flake8] -show-source = True diff --git a/sphinxcontrib/apidoc/__init__.py b/sphinxcontrib/apidoc/__init__.py index 21f02dc..ad9196b 100644 --- a/sphinxcontrib/apidoc/__init__.py +++ b/sphinxcontrib/apidoc/__init__.py @@ -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) diff --git a/sphinxcontrib/apidoc/ext.py b/sphinxcontrib/apidoc/ext.py index 78e432d..df15e09 100644 --- a/sphinxcontrib/apidoc/ext.py +++ b/sphinxcontrib/apidoc/ext.py @@ -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: @@ -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 @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 07e8a78..a843f06 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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() diff --git a/tests/test_ext.py b/tests/test_ext.py index afd9ba5..6c84443 100644 --- a/tests/test_ext.py +++ b/tests/test_ext.py @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/tox.ini b/tox.ini index 4b1e1b8..cb294d8 100644 --- a/tox.ini +++ b/tox.ini @@ -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