From 04e0d9a65b88374008e71bec0c8ef5c29c410eee Mon Sep 17 00:00:00 2001 From: Kyle Benesch <4b796c65+github@gmail.com> Date: Mon, 29 Aug 2022 15:02:26 -0700 Subject: [PATCH 1/6] Remove unicode_literals import. This is safe to remove from Python 3 scripts. I have not changed the FAQ topic which talks about Unicode. It might be outdated. --- exhale/__init__.py | 2 -- exhale/configs.py | 2 -- exhale/deploy.py | 2 -- exhale/graph.py | 2 -- exhale/parse.py | 2 -- exhale/utils.py | 2 +- testing/__init__.py | 1 - testing/base.py | 1 - testing/conftest.py | 2 -- testing/decorators.py | 1 - testing/fixtures.py | 1 - testing/hierarchies.py | 1 - testing/tests/c_maths.py | 1 - testing/tests/configs.py | 1 - testing/tests/configs_tree_view.py | 1 - testing/tests/cpp_dir_underscores.py | 1 - testing/tests/cpp_fortran_mixed.py | 1 - testing/tests/cpp_func_overloads.py | 2 -- testing/tests/cpp_long_names.py | 1 - testing/tests/cpp_nesting.py | 2 -- testing/tests/cpp_pimpl.py | 2 -- testing/tests/cpp_with_spaces.py | 2 -- testing/utils.py | 1 - 23 files changed, 1 insertion(+), 33 deletions(-) diff --git a/exhale/__init__.py b/exhale/__init__.py index d245fc0..c9acd31 100644 --- a/exhale/__init__.py +++ b/exhale/__init__.py @@ -6,8 +6,6 @@ # https://github.com/svenevs/exhale/blob/master/LICENSE # ######################################################################################## -from __future__ import unicode_literals - __version__ = "0.3.7.dev" diff --git a/exhale/configs.py b/exhale/configs.py index 3aed787..058d588 100644 --- a/exhale/configs.py +++ b/exhale/configs.py @@ -40,8 +40,6 @@ options are to modify the behavior of Exhale. ''' -from __future__ import unicode_literals - import os import six import textwrap diff --git a/exhale/deploy.py b/exhale/deploy.py index 623c5d8..a228268 100644 --- a/exhale/deploy.py +++ b/exhale/deploy.py @@ -13,8 +13,6 @@ 2. Launching the full API generation via the :func:`~exhale.deploy.explode` function. ''' -from __future__ import unicode_literals - from . import configs from . import utils from .graph import ExhaleRoot diff --git a/exhale/graph.py b/exhale/graph.py index 1581a52..ec823ef 100644 --- a/exhale/graph.py +++ b/exhale/graph.py @@ -6,8 +6,6 @@ # https://github.com/svenevs/exhale/blob/master/LICENSE # ######################################################################################## -from __future__ import unicode_literals - from . import configs from . import parse from . import utils diff --git a/exhale/parse.py b/exhale/parse.py index 7e19094..dbd86f1 100644 --- a/exhale/parse.py +++ b/exhale/parse.py @@ -6,8 +6,6 @@ # https://github.com/svenevs/exhale/blob/master/LICENSE # ######################################################################################## -from __future__ import unicode_literals - from . import configs from . import utils diff --git a/exhale/utils.py b/exhale/utils.py index 10c7135..31cb793 100644 --- a/exhale/utils.py +++ b/exhale/utils.py @@ -6,7 +6,7 @@ # https://github.com/svenevs/exhale/blob/master/LICENSE # ######################################################################################## -from __future__ import unicode_literals, annotations +from __future__ import annotations from typing import TextIO, Union from . import configs diff --git a/testing/__init__.py b/testing/__init__.py index a86dffd..3225861 100644 --- a/testing/__init__.py +++ b/testing/__init__.py @@ -9,7 +9,6 @@ The testing package for Exhale. """ -from __future__ import unicode_literals import os diff --git a/testing/base.py b/testing/base.py index 8ec156c..949a51e 100644 --- a/testing/base.py +++ b/testing/base.py @@ -11,7 +11,6 @@ All project based test cases should inherit from :class:`testing.base.ExhaleTestCase`. """ -from __future__ import unicode_literals import os import platform import re diff --git a/testing/conftest.py b/testing/conftest.py index ab2f20f..45087cf 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -13,8 +13,6 @@ __ https://docs.pytest.org/en/latest/example/simple.html#package-directory-level-fixtures-setups """ -from __future__ import unicode_literals - pytest_plugins = [ "sphinx.testing.fixtures", "testing.fixtures" diff --git a/testing/decorators.py b/testing/decorators.py index 2b63d8d..a6e7aa2 100644 --- a/testing/decorators.py +++ b/testing/decorators.py @@ -9,7 +9,6 @@ The decorators module defines useful class / function decorators for test cases. """ -from __future__ import unicode_literals from copy import deepcopy from inspect import isclass diff --git a/testing/fixtures.py b/testing/fixtures.py index d2ca6b3..b899202 100644 --- a/testing/fixtures.py +++ b/testing/fixtures.py @@ -8,7 +8,6 @@ """ Provides fixtures to be available for all test cases. """ -from __future__ import unicode_literals from exhale import deploy import pytest diff --git a/testing/hierarchies.py b/testing/hierarchies.py index 1f1ec17..0376223 100644 --- a/testing/hierarchies.py +++ b/testing/hierarchies.py @@ -22,7 +22,6 @@ :func:`~testing.hierarchies.compare_file_hierarchy`. """ -from __future__ import unicode_literals import codecs import os import platform diff --git a/testing/tests/c_maths.py b/testing/tests/c_maths.py index d1371d0..89330ec 100644 --- a/testing/tests/c_maths.py +++ b/testing/tests/c_maths.py @@ -9,7 +9,6 @@ Tests for the ``c_maths`` project. """ -from __future__ import unicode_literals import os from testing.base import ExhaleTestCase diff --git a/testing/tests/configs.py b/testing/tests/configs.py index 6894427..802bb56 100644 --- a/testing/tests/configs.py +++ b/testing/tests/configs.py @@ -8,7 +8,6 @@ """ Tests for validating error handling with configs set in ``conf.py``. """ -from __future__ import unicode_literals import re import textwrap from pathlib import Path diff --git a/testing/tests/configs_tree_view.py b/testing/tests/configs_tree_view.py index 72a55bb..b306b5e 100644 --- a/testing/tests/configs_tree_view.py +++ b/testing/tests/configs_tree_view.py @@ -8,7 +8,6 @@ """ Tests specifically focused on the various tree view configurations. """ -from __future__ import unicode_literals import os import re diff --git a/testing/tests/cpp_dir_underscores.py b/testing/tests/cpp_dir_underscores.py index 74edd6a..862baf2 100644 --- a/testing/tests/cpp_dir_underscores.py +++ b/testing/tests/cpp_dir_underscores.py @@ -9,7 +9,6 @@ Tests for the ``cpp_dir_underscores`` project. """ -from __future__ import unicode_literals import os from testing.base import ExhaleTestCase diff --git a/testing/tests/cpp_fortran_mixed.py b/testing/tests/cpp_fortran_mixed.py index 8aaf47b..166e9e7 100644 --- a/testing/tests/cpp_fortran_mixed.py +++ b/testing/tests/cpp_fortran_mixed.py @@ -9,7 +9,6 @@ Tests for the ``cpp_fortran_mixed`` project. """ -from __future__ import unicode_literals import os import platform import re diff --git a/testing/tests/cpp_func_overloads.py b/testing/tests/cpp_func_overloads.py index 9cbcc46..075e94e 100644 --- a/testing/tests/cpp_func_overloads.py +++ b/testing/tests/cpp_func_overloads.py @@ -9,8 +9,6 @@ Tests for the ``cpp_func_overloads`` project. """ -from __future__ import unicode_literals - from testing.base import ExhaleTestCase from testing.decorators import no_cleanup from testing.hierarchies import class_hierarchy, compare_class_hierarchy, \ diff --git a/testing/tests/cpp_long_names.py b/testing/tests/cpp_long_names.py index c8336e6..8c62bba 100644 --- a/testing/tests/cpp_long_names.py +++ b/testing/tests/cpp_long_names.py @@ -9,7 +9,6 @@ Tests for the ``cpp_long_names`` project. """ -from __future__ import unicode_literals import hashlib import os import platform diff --git a/testing/tests/cpp_nesting.py b/testing/tests/cpp_nesting.py index befb7de..8abd536 100644 --- a/testing/tests/cpp_nesting.py +++ b/testing/tests/cpp_nesting.py @@ -9,8 +9,6 @@ Tests for the ``cpp_nesting`` project. """ -from __future__ import unicode_literals - import os.path as osp import re import subprocess diff --git a/testing/tests/cpp_pimpl.py b/testing/tests/cpp_pimpl.py index fb56e3b..83cf5d4 100644 --- a/testing/tests/cpp_pimpl.py +++ b/testing/tests/cpp_pimpl.py @@ -9,8 +9,6 @@ Tests for the ``cpp_nesting`` project. """ -from __future__ import unicode_literals - import os import re import textwrap diff --git a/testing/tests/cpp_with_spaces.py b/testing/tests/cpp_with_spaces.py index 27e2387..55a9bf1 100644 --- a/testing/tests/cpp_with_spaces.py +++ b/testing/tests/cpp_with_spaces.py @@ -9,8 +9,6 @@ Tests for the ``cpp_with_spaces`` project. """ -from __future__ import unicode_literals - from testing.base import ExhaleTestCase from testing.decorators import no_cleanup from testing.hierarchies import compare_file_hierarchy, file_hierarchy diff --git a/testing/utils.py b/testing/utils.py index 071b1ae..b9d1e49 100644 --- a/testing/utils.py +++ b/testing/utils.py @@ -9,7 +9,6 @@ Utility functionality for the testing suite. """ -from __future__ import unicode_literals try: from collections.abc import Mapping except ImportError: From b87c9f2755158f2920cfb82e31f8dc33d01a18a8 Mon Sep 17 00:00:00 2001 From: Kyle Benesch <4b796c65+github@gmail.com> Date: Mon, 29 Aug 2022 15:12:51 -0700 Subject: [PATCH 2/6] Remove dependency on six. Six features replaced with the Python 3 equivalents. Six removed from requirements lists. --- docs/requirements.txt | 1 - exhale/configs.py | 59 +++++++++++++++++++++---------------------- exhale/deploy.py | 12 +++------ exhale/utils.py | 5 ++-- setup.cfg | 2 -- testing/base.py | 11 +++----- testing/conftest.py | 4 +-- testing/decorators.py | 2 +- tox.ini | 1 - 9 files changed, 41 insertions(+), 56 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index f712c7a..f4ac693 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -5,7 +5,6 @@ sphinx-issues beautifulsoup4 lxml breathe -six # test imports pytest pytest-raises>=0.10 diff --git a/exhale/configs.py b/exhale/configs.py index 058d588..0b5b07c 100644 --- a/exhale/configs.py +++ b/exhale/configs.py @@ -41,7 +41,6 @@ ''' import os -import six import textwrap from pathlib import Path @@ -1335,7 +1334,7 @@ def apply_sphinx_configurations(app): breathe_default_project = app.config.breathe_default_project if not breathe_default_project: raise ConfigError("You must set the `breathe_default_project` in `conf.py`.") - elif not isinstance(breathe_default_project, six.string_types): + elif not isinstance(breathe_default_project, str): raise ConfigError("The type of `breathe_default_project` must be a string.") if breathe_default_project not in breathe_projects: @@ -1349,7 +1348,7 @@ def apply_sphinx_configurations(app): # defer validation of existence until after potentially running Doxygen based on # the configs given to exhale doxy_xml_dir = breathe_projects[breathe_default_project] - if not isinstance(doxy_xml_dir, six.string_types): + if not isinstance(doxy_xml_dir, str): raise ConfigError( "The type of `breathe_projects[breathe_default_project]` from `conf.py` was not a string." ) @@ -1385,9 +1384,9 @@ def apply_sphinx_configurations(app): val_error = "The type of the value for key `{key}` must be `{exp}`, but was `{got}`." req_kv = [ - ("containmentFolder", six.string_types, True), - ("rootFileName", six.string_types, False), - ("doxygenStripFromPath", six.string_types, True) + ("containmentFolder", str, True), + ("rootFileName", str, False), + ("doxygenStripFromPath", str, True) ] for key, expected_type, make_absolute in req_kv: # Used in error checking later @@ -1470,43 +1469,43 @@ def apply_sphinx_configurations(app): #################################################################################### # TODO: `list` -> `(list, tuple)`, update docs too. opt_kv = [ - ("rootFileTitle", six.string_types), + ("rootFileTitle", str), # Build Process Logging, Colors, and Debugging ("verboseBuild", bool), ("alwaysColorize", bool), ("generateBreatheFileDirectives", bool), # Root API Document Customization and Treeview - ("afterTitleDescription", six.string_types), - ("pageHierarchySubSectionTitle", six.string_types), - ("afterHierarchyDescription", six.string_types), - ("fullApiSubSectionTitle", six.string_types), - ("afterBodySummary", six.string_types), + ("afterTitleDescription", str), + ("pageHierarchySubSectionTitle", str), + ("afterHierarchyDescription", str), + ("fullApiSubSectionTitle", str), + ("afterBodySummary", str), ("fullToctreeMaxDepth", int), ("listingExclude", list), ("unabridgedOrphanKinds", (list, set)), # Manual Indexing - ("classHierarchyFilename", six.string_types), - ("fileHierarchyFilename", six.string_types), - ("pageHierarchyFilename", six.string_types), - ("unabridgedApiFilename", six.string_types), - ("unabridgedOrphanFilename", six.string_types), + ("classHierarchyFilename", str), + ("fileHierarchyFilename", str), + ("pageHierarchyFilename", str), + ("unabridgedApiFilename", str), + ("unabridgedOrphanFilename", str), # Clickable Hierarchies <3 ("createTreeView", bool), ("minifyTreeView", bool), ("treeViewIsBootstrap", bool), - ("treeViewBootstrapTextSpanClass", six.string_types), - ("treeViewBootstrapIconMimicColor", six.string_types), - ("treeViewBootstrapOnhoverColor", six.string_types), + ("treeViewBootstrapTextSpanClass", str), + ("treeViewBootstrapIconMimicColor", str), + ("treeViewBootstrapOnhoverColor", str), ("treeViewBootstrapUseBadgeTags", bool), - ("treeViewBootstrapExpandIcon", six.string_types), - ("treeViewBootstrapCollapseIcon", six.string_types), + ("treeViewBootstrapExpandIcon", str), + ("treeViewBootstrapCollapseIcon", str), ("treeViewBootstrapLevels", int), # Page Level Customization ("includeTemplateParamOrderList", bool), - ("pageLevelConfigMeta", six.string_types), - ("repoRedirectURL", six.string_types), + ("pageLevelConfigMeta", str), + ("repoRedirectURL", str), ("contentsDirectives", bool), - ("contentsTitle", six.string_types), + ("contentsTitle", str), ("contentsSpecifiers", list), ("kindsWithContentsDirectives", list), # Breathe Customization @@ -1514,7 +1513,7 @@ def apply_sphinx_configurations(app): # Doxygen Execution and Customization ("exhaleExecutesDoxygen", bool), ("exhaleUseDoxyfile", bool), - ("exhaleDoxygenStdin", six.string_types), + ("exhaleDoxygenStdin", str), ("exhaleSilentDoxygen", bool), # Programlisting Customization ("lexerMapping", dict) @@ -1544,7 +1543,7 @@ def apply_sphinx_configurations(app): # These two need to be lists of strings, check to make sure def _list_of_strings(lst, title): for spec in lst: - if not isinstance(spec, six.string_types): + if not isinstance(spec, str): raise ConfigError( "`{title}` must be a list of strings. `{spec}` was of type `{spec_t}`".format( title=title, @@ -1588,7 +1587,7 @@ def item_or_index(item, idx): for idx in range(len(exclusions)): # Gather the `pattern` and `flags` parameters for `re.compile` item = exclusions[idx] - if isinstance(item, six.string_types): + if isinstance(item, str): pattern = item flags = 0 else: @@ -1622,7 +1621,7 @@ def item_or_index(item, idx): for key in lexer_mapping: val = lexer_mapping[key] # Make sure both are strings - if not isinstance(key, six.string_types) or not isinstance(val, six.string_types): + if not isinstance(key, str) or not isinstance(val, str): raise ConfigError("All keys and values in `lexerMapping` must be strings.") # Make sure the key is a valid regular expression try: @@ -1764,7 +1763,7 @@ def similar(a, b): # Sanity check #3: make sure the return values are all strings for key in customSpecificationsMapping: val_t = type(customSpecificationsMapping[key]) - if not isinstance(key, six.string_types): + if not isinstance(key, str): raise ConfigError( "`customSpecificationsMapping` key `{key}` gave value type `{val_t}` (need `str`).".format( key=key, val_t=val_t diff --git a/exhale/deploy.py b/exhale/deploy.py index a228268..6c17bb1 100644 --- a/exhale/deploy.py +++ b/exhale/deploy.py @@ -19,7 +19,6 @@ import os import sys -import six import re import codecs import tempfile @@ -78,7 +77,7 @@ def _generate_doxygen(doxygen_input): method to restore some state before exiting the program (namely, the working directory before propagating an exception to ``sphinx-build``). ''' - if not isinstance(doxygen_input, six.string_types): + if not isinstance(doxygen_input, str): return "Error: the `doxygen_input` variable must be of type `str`." doxyfile = doxygen_input == "Doxyfile" @@ -104,12 +103,7 @@ def _generate_doxygen(doxygen_input): # # See excellent synopsis: # https://thraxil.org/users/anders/posts/2008/03/13/Subprocess-Hanging-PIPE-is-your-enemy/ - if six.PY2: - tempfile_kwargs = {} - else: - # encoding argument introduced in python 3 - tempfile_kwargs = {"encoding": "utf-8"} - tempfile_kwargs["mode"] = "r+" + tempfile_kwargs = {"mode": "r+", "encoding": "utf-8"} tmp_out_file = tempfile.TemporaryFile( prefix="doxygen_stdout_buff", **tempfile_kwargs ) @@ -213,7 +207,7 @@ def generateDoxygenXML(): # 1. INPUT (where doxygen should parse). # # The below is a modest attempt to validate that these were / were not given. - if not isinstance(configs.exhaleDoxygenStdin, six.string_types): + if not isinstance(configs.exhaleDoxygenStdin, str): return "`exhaleDoxygenStdin` config must be a string!" if not _valid_config("OUTPUT_DIRECTORY", False): diff --git a/exhale/utils.py b/exhale/utils.py index 31cb793..1496147 100644 --- a/exhale/utils.py +++ b/exhale/utils.py @@ -18,7 +18,6 @@ import os import re import sys -import six import textwrap import time import traceback @@ -227,7 +226,7 @@ def makeCustomSpecificationsMapping(func): specs = func(kind) bad = type(specs) is not list for s in specs: - if not isinstance(s, six.string_types): + if not isinstance(s, str): bad = True break if bad: @@ -690,7 +689,7 @@ def printAllColorsToConsole(cls): # ignore specials such as __class__ or __module__ if not elem.startswith("__"): color_fmt = cls.__dict__[elem] - if isinstance(color_fmt, six.string_types) and color_fmt != "BOLD" and color_fmt != "DIM" and \ + if isinstance(color_fmt, str) and color_fmt != "BOLD" and color_fmt != "DIM" and \ color_fmt != "UNDER" and color_fmt != "INV": print("\033[{fmt}AnsiColors.{name}\033[0m".format(fmt=color_fmt, name=elem)) diff --git a/setup.cfg b/setup.cfg index 200fac9..2e0904e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,8 +43,6 @@ install_requires = breathe>=4.32.0 beautifulsoup4 lxml - # TODO: remove this dependency - six [options.package_data] # NOTE: UserWarning from setuptools about newlines in SOURCES.txt. Not sure diff --git a/testing/base.py b/testing/base.py index 949a51e..6b3c4ed 100644 --- a/testing/base.py +++ b/testing/base.py @@ -21,8 +21,6 @@ import exhale import pytest -import six -from six import add_metaclass from sphinx.testing.path import path from . import TEST_PROJECTS_ROOT, get_exhale_root @@ -97,7 +95,7 @@ def __new__(mcs, name, bases, attrs): # noqa: N804 raise RuntimeError( "ExhaleTestCase subclasses must define a 'test_project' attribute" ) - if not isinstance(test_project, six.string_types): + if not isinstance(test_project, str): raise RuntimeError( "'test_project' in class {0} must be a string!".format(name) ) @@ -121,7 +119,7 @@ def _set_app(self, app): yield # the test runs # @no_cleanup sets self.testroot to [self.testroot] as a flag that # cleanup should not transpire - if isinstance(self.testroot, six.string_types): + if isinstance(self.testroot, str): # This cleanup happens between each test case, do not delete docs/ # until all tests for this class are done! containmentFolder = self.getAbsContainmentFolder() @@ -206,7 +204,7 @@ def _rootdir(self, app_params): # perform cleanup by deleting the docs dir # @no_cleanup sets self.testroot to [self.testroot] as a flag that # cleanup should not transpire - if isinstance(self.testroot, six.string_types) and os.path.isdir(self.testroot): + if isinstance(self.testroot, str) and os.path.isdir(self.testroot): shutil.rmtree(self.testroot) self.testroot = None @@ -253,8 +251,7 @@ def file_hierarchy_wrapper(self): ) -@add_metaclass(ExhaleTestCaseMetaclass) -class ExhaleTestCase(unittest.TestCase): +class ExhaleTestCase(unittest.TestCase, metaclass=ExhaleTestCaseMetaclass): """ The primary project based test class to inherit from. diff --git a/testing/conftest.py b/testing/conftest.py index 45087cf..f0c5175 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -33,6 +33,6 @@ def pytest_configure(config): def pytest_runtest_setup(item): """.. todo:: stop reloading configs module in 1.x.""" - from six.moves import reload_module + from importlib import reload from exhale import configs - reload_module(configs) + reload(configs) diff --git a/testing/decorators.py b/testing/decorators.py index a6e7aa2..7cc6a45 100644 --- a/testing/decorators.py +++ b/testing/decorators.py @@ -193,7 +193,7 @@ def test_being_developed(self): This decorator performs ``self.testroot = [self.testroot]`` as an internal bypass to the fixtures created in ``__new__`` for the metaclass. Specifically, the - fixtures generated check ``if isinstance(self.testroot, six.string_types)``. + fixtures generated check ``if isinstance(self.testroot, str)``. As such, since ``self.testroot`` may be desired in the given ``@no_cleanup`` function, you must acquire it with ``testroot = self.testroot[0]``. This is a diff --git a/tox.ini b/tox.ini index f12ae29..09974d7 100644 --- a/tox.ini +++ b/tox.ini @@ -22,7 +22,6 @@ deps = beautifulsoup4 # NOTE: for dev convenience, see https://github.com/svenevs/exhale/issues/131 lxml>=4.6.4 - six # testing requirements # NOTE: see .github/actions/testing_projects.yaml, updates here need to go there. pytest From 3003bf29383ffe6eac5c96dd8232852f487035fe Mon Sep 17 00:00:00 2001 From: Kyle Benesch <4b796c65+github@gmail.com> Date: Mon, 29 Aug 2022 15:25:52 -0700 Subject: [PATCH 3/6] Remove Python 2 only code. --- exhale/configs.py | 8 +------- exhale/graph.py | 13 ++----------- exhale/utils.py | 25 +------------------------ testing/utils.py | 6 +----- 4 files changed, 5 insertions(+), 47 deletions(-) diff --git a/exhale/configs.py b/exhale/configs.py index 0b5b07c..bf4b9ec 100644 --- a/exhale/configs.py +++ b/exhale/configs.py @@ -43,18 +43,12 @@ import os import textwrap from pathlib import Path +from io import StringIO from sphinx.errors import ConfigError, ExtensionError from sphinx.util import logging from types import FunctionType, ModuleType -try: - # Python 2 StringIO - from cStringIO import StringIO -except ImportError: - # Python 3 StringIO - from io import StringIO - logger = logging.getLogger(__name__) """ diff --git a/exhale/graph.py b/exhale/graph.py index ec823ef..097047a 100644 --- a/exhale/graph.py +++ b/exhale/graph.py @@ -19,15 +19,11 @@ from pathlib import Path import platform import textwrap +from io import StringIO +from collections.abc import MutableMapping from bs4 import BeautifulSoup -try: - # Python 2 StringIO - from cStringIO import StringIO -except ImportError: - # Python 3 StringIO - from io import StringIO __all__ = ["ExhaleRoot", "ExhaleNode"] @@ -4036,11 +4032,6 @@ class view hierarchy. It will be present in the file page it was declared in - Directories - Files ''' - try: - from collections.abc import MutableMapping - except ImportError: - # TODO: remove when dropping python 2.7 - from collections import MutableMapping class UnabridgedDict(MutableMapping): def __init__(self): self.items = {} diff --git a/exhale/utils.py b/exhale/utils.py index 1496147..edacef3 100644 --- a/exhale/utils.py +++ b/exhale/utils.py @@ -694,29 +694,6 @@ def printAllColorsToConsole(cls): print("\033[{fmt}AnsiColors.{name}\033[0m".format(fmt=color_fmt, name=elem)) -def indent(text, prefix, predicate=None): - ''' - This is a direct copy of ``textwrap.indent`` for availability in Python 2. - - Their documentation: - - Adds 'prefix' to the beginning of selected lines in 'text'. - If 'predicate' is provided, 'prefix' will only be added to the lines - where 'predicate(line)' is True. If 'predicate' is not provided, - it will default to adding 'prefix' to all non-empty lines that do not - consist solely of whitespace characters. - ''' - if predicate is None: - def predicate(line): - return line.strip() - - def prefixed_lines(): - for line in text.splitlines(True): - yield (prefix + line if predicate(line) else line) - - return ''.join(prefixed_lines()) - - def prefix(token, msg): ''' Wrapper call to :func:`~exhale.utils.indent` with an always-true predicate so that @@ -733,7 +710,7 @@ def prefix(token, msg): ``str`` The message ``msg``, indented by the ``token``. ''' - return indent(msg, token, predicate=lambda x: True) + return textwrap.indent(msg, token, predicate=lambda x: True) def exclaim(err_msg): diff --git a/testing/utils.py b/testing/utils.py index b9d1e49..c9c3b25 100644 --- a/testing/utils.py +++ b/testing/utils.py @@ -9,11 +9,7 @@ Utility functionality for the testing suite. """ -try: - from collections.abc import Mapping -except ImportError: - # TODO: remove when dropping python 2.7 - from collections import Mapping +from collections.abc import Mapping def deep_update(orig, override): From bdaddf8d2d8daf58e47616728e290d41a81cadfb Mon Sep 17 00:00:00 2001 From: Kyle Benesch <4b796c65+github@gmail.com> Date: Mon, 29 Aug 2022 16:27:36 -0700 Subject: [PATCH 4/6] Switch to zero argument super. --- testing/base.py | 5 ++--- testing/hierarchies.py | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/testing/base.py b/testing/base.py index 6b3c4ed..f909e34 100644 --- a/testing/base.py +++ b/testing/base.py @@ -86,7 +86,7 @@ def __new__(mcs, name, bases, attrs): # noqa: N804 """ if attrs["__module__"] == __name__: # we skip everything if we're creating ExhaleTestCase below - return super(ExhaleTestCaseMetaclass, mcs).__new__(mcs, name, bases, attrs) + return super().__new__(mcs, name, bases, attrs) # Make sure `test_project` is defined in all derived classes. test_project = attrs.get("test_project", None) @@ -246,8 +246,7 @@ def file_hierarchy_wrapper(self): # applying the default configuration override, which is overridden using the # @confoverride decorator at class or method level return default_confoverrides( - super(ExhaleTestCaseMetaclass, mcs).__new__(mcs, name, bases, attrs), - make_default_config(attrs["test_project"]) + super().__new__(mcs, name, bases, attrs), make_default_config(attrs["test_project"]) ) diff --git a/testing/hierarchies.py b/testing/hierarchies.py index 0376223..2d4c999 100644 --- a/testing/hierarchies.py +++ b/testing/hierarchies.py @@ -73,7 +73,7 @@ class node(ExhaleNode): # noqa: N801 """ def __init__(self, name, kind): - super(node, self).__init__(name, kind, "") # no Doxygen refid available + super().__init__(name, kind, "") # no Doxygen refid available def __repr__(self): """ @@ -135,7 +135,7 @@ class clike(node): # noqa: N801 """ def __init__(self, kind, name, template=[]): - super(clike, self).__init__(name, kind) + super().__init__(name, kind) self.template = template @@ -153,7 +153,7 @@ class directory(node): # noqa: N801 """ def __init__(self, name): - super(directory, self).__init__(name, "dir") + super().__init__(name, "dir") class define(node): # noqa: N801 @@ -169,7 +169,7 @@ class define(node): # noqa: N801 """ def __init__(self, name): - super(define, self).__init__(name, "define") + super().__init__(name, "define") class enum(node): # noqa: N801 @@ -186,7 +186,7 @@ class enum(node): # noqa: N801 """ def __init__(self, name, values=None): - super(enum, self).__init__(name, "enum") + super().__init__(name, "enum") self.values = values @@ -204,7 +204,7 @@ class file(node): # noqa: N801 """ def __init__(self, name): - super(file, self).__init__(name, "file") + super().__init__(name, "file") self.location = None # TODO: these should not be needed anymore self.namespaces_used = [] @@ -243,7 +243,7 @@ class function(node): # noqa: N801 """ def __init__(self, return_type, name, template=None): - super(function, self).__init__(name, "function") + super().__init__(name, "function") self.return_type = return_type self.parameters = [] # set later, required to let functions be keys in dict self.template = template @@ -288,7 +288,7 @@ class page(node): # noqa: N801 """ def __init__(self, name): - super(page, self).__init__(name, "page") + super().__init__(name, "page") self.location = None @@ -357,7 +357,7 @@ class namespace(node): # noqa: N801 """ def __init__(self, name): - super(namespace, self).__init__(name, "namespace") + super().__init__(name, "namespace") class typedef(node): # noqa: N801 @@ -378,7 +378,7 @@ class typedef(node): # noqa: N801 """ def __init__(self, new_name, old_name, template=None): - super(typedef, self).__init__(new_name, "typedef") + super().__init__(new_name, "typedef") self.old_name = old_name self.template = template @@ -395,7 +395,7 @@ class union(node): # noqa: N801 """ def __init__(self, name): - super(union, self).__init__(name, "union") + super().__init__(name, "union") class variable(node): # noqa: N801 @@ -413,7 +413,7 @@ class variable(node): # noqa: N801 """ def __init__(self, _type, name): - super(variable, self).__init__(name, "variable") + super().__init__(name, "variable") self.type = _type @@ -732,7 +732,7 @@ def test_class_hierarchy(self): """ def __init__(self, hierarchy): - super(class_hierarchy, self).__init__("class", hierarchy) + super().__init__("class", hierarchy) class file_hierarchy(root): # noqa: N801 @@ -804,7 +804,7 @@ def test_file_hierarchy(self): """ def __init__(self, hierarchy): - super(file_hierarchy, self).__init__("file", hierarchy) + super().__init__("file", hierarchy) ######################################################################################## From 3f7022f9c35e452823e7fccf0c992276268eade3 Mon Sep 17 00:00:00 2001 From: Kyle Benesch <4b796c65+github@gmail.com> Date: Mon, 29 Aug 2022 17:28:14 -0700 Subject: [PATCH 5/6] Remove indent function from docs. --- docs/reference/utils.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/reference/utils.rst b/docs/reference/utils.rst index 24b61ed..5945a13 100644 --- a/docs/reference/utils.rst +++ b/docs/reference/utils.rst @@ -31,8 +31,6 @@ Unsorted Misc .. autoclass:: exhale.utils.AnsiColors -.. autofunction:: exhale.utils.indent - .. autofunction:: exhale.utils.prefix .. autofunction:: exhale.utils.exclaim From 49fdde7f907e9f81502c53f9e38656403de445b1 Mon Sep 17 00:00:00 2001 From: Kyle Benesch <4b796c65+github@gmail.com> Date: Tue, 6 Sep 2022 17:19:13 -0700 Subject: [PATCH 6/6] Change indent reference to point at the official docs. --- exhale/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exhale/utils.py b/exhale/utils.py index edacef3..dae7970 100644 --- a/exhale/utils.py +++ b/exhale/utils.py @@ -696,7 +696,7 @@ def printAllColorsToConsole(cls): def prefix(token, msg): ''' - Wrapper call to :func:`~exhale.utils.indent` with an always-true predicate so that + Wrapper call to :func:`~textwrap.indent` with an always-true predicate so that empty lines (e.g. `\\n`) still get indented by the ``token``. :Parameters: