From 3194e0a8c290ab81bec37a553ed60cf8473cb52b Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Wed, 20 Apr 2022 14:51:38 +0200 Subject: [PATCH 1/2] Use generated version for __version__ --- .gitignore | 1 + pyproject.toml | 4 ++++ setup.py | 3 +-- sphinx_automodapi/__init__.py | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8f9b3ad..60842bf 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ __pycache__ # Other generated files MANIFEST +sphinx_automodapi/version.py # Sphinx _build diff --git a/pyproject.toml b/pyproject.toml index 590e0b1..e06fcb3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,3 +3,7 @@ requires = ["setuptools>=30.3.0", "setuptools_scm", "wheel"] build-backend = 'setuptools.build_meta' + + +[tool.setuptools_scm] +write_to = "sphinx_automodapi/version.py" diff --git a/setup.py b/setup.py index 21f6163..beda28e 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -import os from setuptools import setup -setup(use_scm_version={'write_to': os.path.join('sphinx_automodapi', 'version.py')}) +setup() diff --git a/sphinx_automodapi/__init__.py b/sphinx_automodapi/__init__.py index b5e195e..e0fcb47 100644 --- a/sphinx_automodapi/__init__.py +++ b/sphinx_automodapi/__init__.py @@ -1 +1 @@ -__version__ = '0.14.dev0' +from .version import version as __version__ # noqa From e1d71c5349b43b41c29e378fb29d212350a01ccd Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Wed, 20 Apr 2022 14:53:55 +0200 Subject: [PATCH 2/2] Remove old py2 compat code --- sphinx_automodapi/automodapi.py | 16 ++++--------- sphinx_automodapi/automodsumm.py | 3 +-- sphinx_automodapi/tests/helpers.py | 5 ++-- .../tests/test_autodoc_enhancements.py | 24 ++++--------------- sphinx_automodapi/tests/test_automodapi.py | 8 +------ sphinx_automodapi/tests/test_cases.py | 10 ++++---- sphinx_automodapi/utils.py | 7 ------ 7 files changed, 18 insertions(+), 55 deletions(-) diff --git a/sphinx_automodapi/automodapi.py b/sphinx_automodapi/automodapi.py index 28cff8a..f993cf5 100644 --- a/sphinx_automodapi/automodapi.py +++ b/sphinx_automodapi/automodapi.py @@ -101,7 +101,6 @@ class are included in the generated documentation. Defaults to ``False``. # actually built. import inspect -import io import os import re import sys @@ -112,11 +111,6 @@ class are included in the generated documentation. Defaults to ``False``. __all__ = [] -if sys.version_info[0] == 3: - text_type = str -else: - text_type = unicode # noqa - automod_templ_modheader = """ {modname} {pkgormod} {modhds}{pkgormodhds} @@ -377,14 +371,14 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None, if app.config.automodapi_writereprocessed: # sometimes they are unicode, sometimes not, depending on how # sphinx has processed things - if isinstance(newsourcestr, text_type): + if isinstance(newsourcestr, str): ustr = newsourcestr else: ustr = newsourcestr.decode(app.config.source_encoding) if docname is None: - with io.open(os.path.join(app.srcdir, 'unknown.automodapi'), - 'a', encoding='utf8') as f: + with open(os.path.join(app.srcdir, 'unknown.automodapi'), + 'a', encoding='utf8') as f: f.write(u'\n**NEW DOC**\n\n') f.write(ustr) else: @@ -394,8 +388,8 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None, filename = docname + os.path.splitext(env.doc2path(docname))[1] filename += '.automodapi' - with io.open(os.path.join(app.srcdir, filename), 'w', - encoding='utf8') as f: + with open(os.path.join(app.srcdir, filename), 'w', + encoding='utf8') as f: f.write(ustr) return newsourcestr diff --git a/sphinx_automodapi/automodsumm.py b/sphinx_automodapi/automodsumm.py index 30979cc..bd6d9f1 100644 --- a/sphinx_automodapi/automodsumm.py +++ b/sphinx_automodapi/automodsumm.py @@ -87,7 +87,6 @@ class members that are inherited from a base class. This value can be import inspect import os import re -import io from sphinx.util import logging from sphinx.ext.autosummary import Autosummary @@ -312,7 +311,7 @@ def automodsumm_to_autosummary_lines(fn, app): fullfn = os.path.join(app.builder.env.srcdir, fn) - with io.open(fullfn, encoding='utf8') as fr: + with open(fullfn, encoding='utf8') as fr: # Note: we use __name__ here instead of just writing the module name in # case this extension is bundled into another package from . import automodapi diff --git a/sphinx_automodapi/tests/helpers.py b/sphinx_automodapi/tests/helpers.py index 01b3510..5fb34a0 100644 --- a/sphinx_automodapi/tests/helpers.py +++ b/sphinx_automodapi/tests/helpers.py @@ -2,7 +2,6 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst import os -import sys from copy import deepcopy from sphinx.cmd.build import build_main @@ -13,8 +12,8 @@ intersphinx_mapping = { - 'python': ('https://docs.python.org/{0}/'.format(sys.version_info[0]), None) - } + 'python': ('https://docs.python.org/3/', None) +} DEFAULT_CONF = {'source_suffix': '.rst', 'master_doc': 'index', diff --git a/sphinx_automodapi/tests/test_autodoc_enhancements.py b/sphinx_automodapi/tests/test_autodoc_enhancements.py index 3f3860c..5e3f6de 100644 --- a/sphinx_automodapi/tests/test_autodoc_enhancements.py +++ b/sphinx_automodapi/tests/test_autodoc_enhancements.py @@ -1,5 +1,3 @@ -import sys - from textwrap import dedent import pytest @@ -15,23 +13,11 @@ def foo(cls): return 'foo' -if sys.version_info[0] < 3: - exec(dedent(""" - class MyClass(object): - __metaclass__ = Meta - @property - def foo(self): - \"\"\"Docstring for MyClass.foo property.\"\"\" - return 'myfoo' - """)) -else: - exec(dedent(""" - class MyClass(metaclass=Meta): - @property - def foo(self): - \"\"\"Docstring for MyClass.foo property.\"\"\" - return 'myfoo' - """)) +class MyClass(metaclass=Meta): + @property + def foo(self): + """Docstring for MyClass.foo property.""" + return 'myfoo' def test_type_attrgetter(): diff --git a/sphinx_automodapi/tests/test_automodapi.py b/sphinx_automodapi/tests/test_automodapi.py index 72e52fd..1cf21e2 100644 --- a/sphinx_automodapi/tests/test_automodapi.py +++ b/sphinx_automodapi/tests/test_automodapi.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # Licensed under a 3-clause BSD style license - see LICENSE.rst -import sys from copy import copy import pytest @@ -10,11 +9,6 @@ from . import cython_testpackage # noqa from .helpers import run_sphinx_in_tmpdir -if sys.version_info[0] == 2: - from io import open as io_open -else: - io_open = open - def setup_function(func): # This can be replaced with the docutils_namespace context manager once @@ -104,7 +98,7 @@ def test_am_replacer_writereprocessed(tmpdir, writereprocessed): Tests the automodapi_writereprocessed option """ - with io_open(tmpdir.join('index.rst').strpath, 'w', encoding='utf-8') as f: + with open(tmpdir.join('index.rst').strpath, 'w', encoding='utf-8') as f: f.write(am_replacer_repr_str.format(options='')) run_sphinx_in_tmpdir(tmpdir, additional_conf={'automodapi_writereprocessed': writereprocessed}) diff --git a/sphinx_automodapi/tests/test_cases.py b/sphinx_automodapi/tests/test_cases.py index 72f6140..351e388 100644 --- a/sphinx_automodapi/tests/test_cases.py +++ b/sphinx_automodapi/tests/test_cases.py @@ -4,8 +4,6 @@ # We store different cases in the cases sub-directory of the tests directory import os -import io -import sys import glob import shutil from itertools import product @@ -26,8 +24,8 @@ intersphinx_mapping = { - 'python': ('https://docs.python.org/{0}/'.format(sys.version_info[0]), None) - } + 'python': ('https://docs.python.org/3/', None) +} DEFAULT_CONF = {'source_suffix': '.rst', 'master_doc': 'index', @@ -112,8 +110,8 @@ def test_run_full_case(tmpdir, case_dir, parallel): path_relative = os.path.relpath(path_reference, output_dir) path_actual = os.path.join(docs_dir, path_relative) assert os.path.exists(path_actual) - with io.open(path_actual, encoding='utf8') as f: + with open(path_actual, encoding='utf8') as f: actual = f.read() - with io.open(path_reference, encoding='utf8') as f: + with open(path_reference, encoding='utf8') as f: reference = f.read() assert actual.strip() == reference.strip() diff --git a/sphinx_automodapi/utils.py b/sphinx_automodapi/utils.py index 1716874..f0b1fff 100644 --- a/sphinx_automodapi/utils.py +++ b/sphinx_automodapi/utils.py @@ -9,13 +9,6 @@ __all__ = ['cleanup_whitespace', 'find_mod_objs', 'find_autosummary_in_lines_for_automodsumm'] -if sys.version_info[0] >= 3: - def iteritems(dictionary): - return dictionary.items() -else: - def iteritems(dictionary): - return dictionary.iteritems() - # We use \n instead of os.linesep because even on Windows, the generated files # use \n as the newline character. SPACE_NEWLINE = ' \n'