From 30536cfb8e53fff3db6291d30dfa7def02d62602 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 1 Aug 2023 09:43:42 +0300 Subject: [PATCH 1/3] Drop support for EOL Python <= 3.7 --- setup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 6f52f4e..b67c73d 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,6 @@ import os from setuptools import setup -install_requires = ["matplotlib", "numpy", "pandas"] - try: with open("README.md") as readme: long_description = readme.read() @@ -36,7 +34,8 @@ license="MIT License", platforms=["any"], packages=["calmap"], - install_requires=install_requires, + install_requires=["matplotlib", "numpy", "pandas"], + python_requires=">=3.8", classifiers=[ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", @@ -44,9 +43,10 @@ "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Topic :: Scientific/Engineering", ], ) From 5fa7b054289acf45f7f9a6a011f1e1e85d62221a Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 1 Aug 2023 09:45:03 +0300 Subject: [PATCH 2/3] Run: pyupgrade **/*.py --py38-plus --- calmap/__init__.py | 2 -- doc/conf.py | 12 ++++---- doc/sphinxext/plot_directive.py | 50 +++++++++++++-------------------- setup.py | 2 +- tests/test_calmap.py | 1 - 5 files changed, 26 insertions(+), 41 deletions(-) diff --git a/calmap/__init__.py b/calmap/__init__.py index 7651522..3bc48a3 100644 --- a/calmap/__init__.py +++ b/calmap/__init__.py @@ -6,8 +6,6 @@ """ -from __future__ import unicode_literals - import calendar import datetime diff --git a/doc/conf.py b/doc/conf.py index 7f64d2e..fdc48f8 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # Calmap documentation build configuration file, created by # sphinx-quickstart on Thu Nov 26 16:51:51 2015. # @@ -59,8 +57,8 @@ master_doc = "index" # General information about the project. -project = u"Calmap" -copyright = u"2015, %s" % calmap.__author__ +project = "Calmap" +copyright = "2015, %s" % calmap.__author__ author = calmap.__author__ # The version info for the project you're documenting, acts as replacement for @@ -236,7 +234,7 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, "Calmap.tex", u"Calmap Documentation", u"Martijn Vermaat", "manual") + (master_doc, "Calmap.tex", "Calmap Documentation", "Martijn Vermaat", "manual") ] # The name of an image file (relative to this directory) to place at the top of @@ -264,7 +262,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [(master_doc, "calmap", u"Calmap Documentation", [author], 1)] +man_pages = [(master_doc, "calmap", "Calmap Documentation", [author], 1)] # If true, show URL addresses after external links. # man_show_urls = False @@ -279,7 +277,7 @@ ( master_doc, "Calmap", - u"Calmap Documentation", + "Calmap Documentation", author, "Calmap", "One line description of project.", diff --git a/doc/sphinxext/plot_directive.py b/doc/sphinxext/plot_directive.py index ecbcd8b..3248ce7 100644 --- a/doc/sphinxext/plot_directive.py +++ b/doc/sphinxext/plot_directive.py @@ -130,7 +130,6 @@ plot_template Provide a customized template for preparing restructured text. """ -from __future__ import absolute_import, division, print_function, unicode_literals import six from six.moves import xrange @@ -145,9 +144,6 @@ import traceback import warnings -if not six.PY3: - import cStringIO - from docutils.parsers.rst import directives from docutils.parsers.rst.directives.images import Image @@ -247,7 +243,7 @@ def mark_plot_labels(app, document): the "htmlonly" (or "latexonly") node to the actual figure node itself. """ - for name, explicit in six.iteritems(document.nametypes): + for name, explicit in document.nametypes.items(): if not explicit: continue labelid = document.nameids[name] @@ -306,7 +302,7 @@ def setup(app): app.add_config_value("plot_working_directory", None, True) app.add_config_value("plot_template", None, True) - app.connect(str("doctree-read"), mark_plot_labels) + app.connect("doctree-read", mark_plot_labels) # ------------------------------------------------------------------------------ @@ -375,7 +371,7 @@ def remove_coding(text): """ Remove the coding comment, which six.exec_ doesn't like. """ - sub_re = re.compile("^#\s*-\*-\s*coding:\s*.*-\*-$", flags=re.MULTILINE) + sub_re = re.compile(r"^#\s*-\*-\s*coding:\s*.*-\*-$", flags=re.MULTILINE) return sub_re.sub("", text) @@ -457,14 +453,14 @@ def remove_coding(text): plot_context = dict() -class ImageFile(object): +class ImageFile: def __init__(self, basename, dirname): self.basename = basename self.dirname = dirname self.formats = [] def filename(self, format): - return os.path.join(self.dirname, "%s.%s" % (self.basename, format)) + return os.path.join(self.dirname, "{}.{}".format(self.basename, format)) def filenames(self): return [self.filename(fmt) for fmt in self.formats] @@ -494,10 +490,7 @@ def run_code(code, code_path, ns=None, function_name=None): # Change the working directory to the directory of the example, so # it can get at its data files, if any. Add its path to sys.path # so it can import any helper modules sitting beside it. - if six.PY2: - pwd = os.getcwdu() - else: - pwd = os.getcwd() + pwd = os.getcwd() old_sys_path = list(sys.path) if setup.config.plot_working_directory is not None: try: @@ -526,10 +519,7 @@ def run_code(code, code_path, ns=None, function_name=None): # Redirect stdout stdout = sys.stdout - if six.PY3: - sys.stdout = io.StringIO() - else: - sys.stdout = cStringIO.StringIO() + sys.stdout = io.StringIO() # Assign a do-nothing print function to the namespace. There # doesn't seem to be any other way to provide a way to (not) print @@ -544,22 +534,22 @@ def _dummy_print(*arg, **kwarg): ns = {} if not ns: if setup.config.plot_pre_code is None: - six.exec_( - six.text_type( + exec( + str( "import numpy as np\n" + "from matplotlib import pyplot as plt\n" ), ns, ) else: - six.exec_(six.text_type(setup.config.plot_pre_code), ns) + exec(str(setup.config.plot_pre_code), ns) ns["print"] = _dummy_print if "__main__" in code: - six.exec_("__name__ = '__main__'", ns) + exec("__name__ = '__main__'", ns) code = remove_coding(code) - six.exec_(code, ns) + exec(code, ns) if function_name is not None: - six.exec_(function_name + "()", ns) + exec(function_name + "()", ns) except (Exception, SystemExit) as err: raise PlotError(traceback.format_exc()) finally: @@ -599,13 +589,13 @@ def render_figures( default_dpi = {"png": 80, "hires.png": 200, "pdf": 200} formats = [] plot_formats = config.plot_formats - if isinstance(plot_formats, six.string_types): + if isinstance(plot_formats, str): # String Sphinx < 1.3, Split on , to mimic # Sphinx 1.3 and later. Sphinx 1.3 always # returns a list. plot_formats = plot_formats.split(",") for fmt in plot_formats: - if isinstance(fmt, six.string_types): + if isinstance(fmt, str): if ":" in fmt: suffix, dpi = fmt.split(":") formats.append((str(suffix), int(dpi))) @@ -637,7 +627,7 @@ def render_figures( all_exists = True for i, code_piece in enumerate(code_pieces): images = [] - for j in xrange(1000): + for j in range(1000): if len(code_pieces) > 1: img = ImageFile("%s_%02d_%02d" % (output_base, i, j), output_dir) else: @@ -746,7 +736,7 @@ def run(arguments, content, options, state_machine, state, lineno): else: function_name = None - with io.open(source_file_name, "r", encoding="utf-8") as fd: + with open(source_file_name, encoding="utf-8") as fd: code = fd.read() output_base = os.path.basename(source_file_name) else: @@ -857,8 +847,8 @@ def run(arguments, content, options, state_machine, state, lineno): images = [] opts = [ - ":%s: %s" % (key, val) - for key, val in six.iteritems(options) + ":{}: {}".format(key, val) + for key, val in options.items() if key in ("alt", "height", "width", "scale", "align", "class") ] @@ -908,7 +898,7 @@ def run(arguments, content, options, state_machine, state, lineno): # copy script (if necessary) target_name = os.path.join(dest_dir, output_base + source_ext) - with io.open(target_name, "w", encoding="utf-8") as f: + with open(target_name, "w", encoding="utf-8") as f: if source_file_name == rst_file: code_escaped = unescape_doctest(code) else: diff --git a/setup.py b/setup.py index b67c73d..3754697 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ try: with open("README.md") as readme: long_description = readme.read() -except IOError: +except OSError: long_description = "See https://pypi.python.org/pypi/calmap" # This is quite the hack, but we don't want to import our package from here diff --git a/tests/test_calmap.py b/tests/test_calmap.py index f4ee2d3..85c59ab 100644 --- a/tests/test_calmap.py +++ b/tests/test_calmap.py @@ -3,7 +3,6 @@ """ -from __future__ import unicode_literals import numpy as np From 4aba5166dd05e458f8ced8a04621ef14b1ce94aa Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 1 Aug 2023 09:48:43 +0300 Subject: [PATCH 3/3] Remove redundant six imports --- doc/sphinxext/plot_directive.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/doc/sphinxext/plot_directive.py b/doc/sphinxext/plot_directive.py index 3248ce7..d6f7754 100644 --- a/doc/sphinxext/plot_directive.py +++ b/doc/sphinxext/plot_directive.py @@ -131,9 +131,6 @@ Provide a customized template for preparing restructured text. """ -import six -from six.moves import xrange - import sys import os import shutil