Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Python 2 code. #174

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 0 additions & 2 deletions docs/reference/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ Unsorted Misc

.. autoclass:: exhale.utils.AnsiColors

.. autofunction:: exhale.utils.indent

.. autofunction:: exhale.utils.prefix

.. autofunction:: exhale.utils.exclaim
Expand Down
1 change: 0 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ sphinx-issues
beautifulsoup4
lxml
breathe
six
# test imports
pytest
pytest-raises>=0.10
2 changes: 0 additions & 2 deletions exhale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
# https://github.com/svenevs/exhale/blob/master/LICENSE #
########################################################################################

from __future__ import unicode_literals

__version__ = "0.3.7.dev"


Expand Down
69 changes: 30 additions & 39 deletions exhale/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,15 @@
options are to modify the behavior of Exhale.
'''

from __future__ import unicode_literals

import os
import six
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__)
"""
Expand Down Expand Up @@ -1337,7 +1328,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:
Expand All @@ -1351,7 +1342,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."
)
Expand Down Expand Up @@ -1387,9 +1378,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
Expand Down Expand Up @@ -1472,51 +1463,51 @@ 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
("customSpecificationsMapping", dict),
# Doxygen Execution and Customization
("exhaleExecutesDoxygen", bool),
("exhaleUseDoxyfile", bool),
("exhaleDoxygenStdin", six.string_types),
("exhaleDoxygenStdin", str),
("exhaleSilentDoxygen", bool),
# Programlisting Customization
("lexerMapping", dict)
Expand Down Expand Up @@ -1546,7 +1537,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,
Expand Down Expand Up @@ -1590,7 +1581,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:
Expand Down Expand Up @@ -1624,7 +1615,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:
Expand Down Expand Up @@ -1766,7 +1757,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
Expand Down
14 changes: 3 additions & 11 deletions exhale/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
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

import os
import sys
import six
import re
import codecs
import tempfile
Expand Down Expand Up @@ -80,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"
Expand All @@ -106,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
)
Expand Down Expand Up @@ -215,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):
Expand Down
15 changes: 2 additions & 13 deletions exhale/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,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"]

Expand Down Expand Up @@ -4038,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 = {}
Expand Down
2 changes: 0 additions & 2 deletions exhale/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
# https://github.com/svenevs/exhale/blob/master/LICENSE #
########################################################################################

from __future__ import unicode_literals

from . import configs
from . import utils

Expand Down
34 changes: 5 additions & 29 deletions exhale/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +18,6 @@
import os
import re
import sys
import six
import textwrap
import time
import traceback
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -690,37 +689,14 @@ 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))


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
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:
Expand All @@ -734,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):
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
The testing package for Exhale.
"""

from __future__ import unicode_literals
import os


Expand Down
Loading