From fec280115a76abf60ba751e74752dc89b9694951 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Tue, 24 Nov 2020 08:31:29 +0100 Subject: [PATCH 1/3] Add an option to drop Python 2 support. --- config/README.rst | 10 ++++++++++ config/buildout-recipe/tox.ini.j2 | 6 +++++- config/config-package.py | 14 ++++++++++++-- config/default/tests.yml.j2 | 6 +++++- config/pure-python/packages.txt | 1 + config/pure-python/tox.ini.j2 | 6 +++++- 6 files changed, 38 insertions(+), 5 deletions(-) diff --git a/config/README.rst b/config/README.rst index b156e96..7d5de4e 100644 --- a/config/README.rst +++ b/config/README.rst @@ -116,6 +116,11 @@ The following arguments are supported. --with-pypy Enable PyPy support. (Only needed one time as it is stored in .meta.cfg.) +--without-py2 + The package does not support Python 2, so do not test for it. Also drops + support for PyPy2 and Python 3.5 (Only needed one time as it is stored in + .meta.cfg.) + --with-docs Enable building the documentation using Sphinx. (Only needed one time as it is stored in .meta.cfg.) @@ -124,6 +129,7 @@ The following arguments are supported. Enable running the documentation as doctest using Sphinx. (Only needed one time as it is stored in .meta.cfg.) + Options +++++++ @@ -142,6 +148,7 @@ updated. Example: with-pypy = False with-docs = True with-sphinx-doctests = False + without-py2 = False additional-manifest-rules = @@ -162,6 +169,9 @@ fail-under with-pypy Does the package support PyPy: True/False +without-py2 + Do not run the tests on Python 2, PyPy2 and Python 3.5: True/False + with-docs Build the documentation via Sphinx: True/False diff --git a/config/buildout-recipe/tox.ini.j2 b/config/buildout-recipe/tox.ini.j2 index 34b5ed5..d219070 100644 --- a/config/buildout-recipe/tox.ini.j2 +++ b/config/buildout-recipe/tox.ini.j2 @@ -1,14 +1,18 @@ [tox] envlist = lint, +{% if with_py2 %} py27, py35, +{% endif %} py36, py37, py38, py39, -{% if with_pypy %} +{% if with_pypy and with_py2 %} pypy, +{% endif %} +{% if with_pypy %} pypy3, {% endif %} {% if with_docs %} diff --git a/config/config-package.py b/config/config-package.py index d0bb8dc..29daa7b 100755 --- a/config/config-package.py +++ b/config/config-package.py @@ -55,6 +55,13 @@ def copy_with_meta(template_name, destination, config_type, **kw): action='store_true', default=False, help='Activate PyPy support if not already configured in .meta.cfg.') +parser.add_argument( + '--without-py2', + dest='without_py2', + action='store_true', + default=False, + help='Disable Python 2 support if not already configured in .meta.cfg.' + ' Also disables support for PyPy2 and Python 3.5.') parser.add_argument( '--with-docs', dest='with_docs', @@ -118,6 +125,9 @@ def copy_with_meta(template_name, destination, config_type, **kw): 'git', 'log', '-n1', '--format=format:%H', capture_output=True).stdout with_pypy = meta_opts.getboolean('with-pypy', False) or args.with_pypy meta_opts['with-pypy'] = str(with_pypy) +without_py2 = meta_opts.getboolean('without-py2', False) or args.without_py2 +meta_opts['without-py2'] = str(without_py2) +with_py2 = not without_py2 with_docs = meta_opts.getboolean('with-docs', False) or args.with_docs meta_opts['with-docs'] = str(with_docs) with_sphinx_doctests = meta_opts.getboolean( @@ -145,11 +155,11 @@ def copy_with_meta(template_name, destination, config_type, **kw): fail_under = meta_opts.setdefault('fail-under', '0') copy_with_meta( 'tox.ini.j2', path / 'tox.ini', config_type, - fail_under=fail_under, with_pypy=with_pypy, + fail_under=fail_under, with_pypy=with_pypy, with_py2=with_py2, with_docs=with_docs, with_sphinx_doctests=with_sphinx_doctests) copy_with_meta( 'tests.yml.j2', workflows / 'tests.yml', config_type, - with_pypy=with_pypy, with_docs=with_docs) + with_pypy=with_pypy, with_py2=with_py2, with_docs=with_docs) # Modify MANIFEST.in with meta options diff --git a/config/default/tests.yml.j2 b/config/default/tests.yml.j2 index 5d0e378..6415f9e 100644 --- a/config/default/tests.yml.j2 +++ b/config/default/tests.yml.j2 @@ -14,14 +14,18 @@ jobs: config: # [Python version, tox env] - ["3.8", "lint"] +{% if with_py2 %} - ["2.7", "py27"] - ["3.5", "py35"] +{% endif %} - ["3.6", "py36"] - ["3.7", "py37"] - ["3.8", "py38"] - ["3.9", "py39"] -{% if with_pypy %} +{% if with_pypy and with_py2 %} - ["pypy2", "pypy"] +{% endif %} +{% if with_pypy %} - ["pypy3", "pypy3"] {% endif %} {% if with_docs %} diff --git a/config/pure-python/packages.txt b/config/pure-python/packages.txt index 1ed77d9..07507e0 100644 --- a/config/pure-python/packages.txt +++ b/config/pure-python/packages.txt @@ -17,3 +17,4 @@ grokcore.component zc.relationship bobo megrok.strictrequire +importchecker diff --git a/config/pure-python/tox.ini.j2 b/config/pure-python/tox.ini.j2 index 234453e..d17f459 100644 --- a/config/pure-python/tox.ini.j2 +++ b/config/pure-python/tox.ini.j2 @@ -1,14 +1,18 @@ [tox] envlist = lint, +{% if with_py2 %} py27, py35, +{% endif %} py36, py37, py38, py39, -{% if with_pypy %} +{% if with_pypy and with_py2 %} pypy, +{% endif %} +{% if with_pypy %} pypy3, {% endif %} {% if with_docs %} From 9da00eee91ae120118a4bd1e20cd7bd006c67b41 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Tue, 24 Nov 2020 15:58:23 +0100 Subject: [PATCH 2/3] Remove double negation in .meta.cfg. Improve naming of cmd line options. --- config/README.rst | 14 +++++++------- config/buildout-recipe/tox.ini.j2 | 4 ++-- config/config-package.py | 27 ++++++++++++++++----------- config/default/tests.yml.j2 | 4 ++-- config/pure-python/tox.ini.j2 | 4 ++-- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/config/README.rst b/config/README.rst index 7d5de4e..b5d7c05 100644 --- a/config/README.rst +++ b/config/README.rst @@ -116,10 +116,10 @@ The following arguments are supported. --with-pypy Enable PyPy support. (Only needed one time as it is stored in .meta.cfg.) ---without-py2 - The package does not support Python 2, so do not test for it. Also drops - support for PyPy2 and Python 3.5 (Only needed one time as it is stored in - .meta.cfg.) +--without-legacy-python + The package does not support Python versions which reached their end-of-life. + (Currently this means dropping support for Python 2.7 and 3.5.) This as well + drops support for PyPy2. (Only needed one time as it is stored in .meta.cfg.) --with-docs Enable building the documentation using Sphinx. (Only needed one time as it @@ -148,7 +148,7 @@ updated. Example: with-pypy = False with-docs = True with-sphinx-doctests = False - without-py2 = False + with-legacy-python = True additional-manifest-rules = @@ -169,8 +169,8 @@ fail-under with-pypy Does the package support PyPy: True/False -without-py2 - Do not run the tests on Python 2, PyPy2 and Python 3.5: True/False +with-legacy-python + Run the tests even on Python 2.7, PyPy2 and Python 3.5: True/False with-docs Build the documentation via Sphinx: True/False diff --git a/config/buildout-recipe/tox.ini.j2 b/config/buildout-recipe/tox.ini.j2 index d219070..3a9bd6d 100644 --- a/config/buildout-recipe/tox.ini.j2 +++ b/config/buildout-recipe/tox.ini.j2 @@ -1,7 +1,7 @@ [tox] envlist = lint, -{% if with_py2 %} +{% if with_legacy_python %} py27, py35, {% endif %} @@ -9,7 +9,7 @@ envlist = py37, py38, py39, -{% if with_pypy and with_py2 %} +{% if with_pypy and with_legacy_python %} pypy, {% endif %} {% if with_pypy %} diff --git a/config/config-package.py b/config/config-package.py index 29daa7b..b02b171 100755 --- a/config/config-package.py +++ b/config/config-package.py @@ -56,12 +56,13 @@ def copy_with_meta(template_name, destination, config_type, **kw): default=False, help='Activate PyPy support if not already configured in .meta.cfg.') parser.add_argument( - '--without-py2', - dest='without_py2', - action='store_true', - default=False, - help='Disable Python 2 support if not already configured in .meta.cfg.' - ' Also disables support for PyPy2 and Python 3.5.') + '--without-legacy-python', + dest='with_legacy_python', + action='store_false', + default=None, + help='Disable support for Python versions which reached their end-of-life.' + ' (aka 2.7 and 3.5) if not already configured in .meta.cfg.' + ' Also disables support for PyPy2.') parser.add_argument( '--with-docs', dest='with_docs', @@ -125,9 +126,11 @@ def copy_with_meta(template_name, destination, config_type, **kw): 'git', 'log', '-n1', '--format=format:%H', capture_output=True).stdout with_pypy = meta_opts.getboolean('with-pypy', False) or args.with_pypy meta_opts['with-pypy'] = str(with_pypy) -without_py2 = meta_opts.getboolean('without-py2', False) or args.without_py2 -meta_opts['without-py2'] = str(without_py2) -with_py2 = not without_py2 +if args.with_legacy_python is None: + with_legacy_python = meta_opts.getboolean('with-legacy-python', True) +else: + with_legacy_python = args.with_legacy_python +meta_opts['with-legacy-python'] = str(with_legacy_python) with_docs = meta_opts.getboolean('with-docs', False) or args.with_docs meta_opts['with-docs'] = str(with_docs) with_sphinx_doctests = meta_opts.getboolean( @@ -155,11 +158,13 @@ def copy_with_meta(template_name, destination, config_type, **kw): fail_under = meta_opts.setdefault('fail-under', '0') copy_with_meta( 'tox.ini.j2', path / 'tox.ini', config_type, - fail_under=fail_under, with_pypy=with_pypy, with_py2=with_py2, + fail_under=fail_under, with_pypy=with_pypy, + with_legacy_python=with_legacy_python, with_docs=with_docs, with_sphinx_doctests=with_sphinx_doctests) copy_with_meta( 'tests.yml.j2', workflows / 'tests.yml', config_type, - with_pypy=with_pypy, with_py2=with_py2, with_docs=with_docs) + with_pypy=with_pypy, with_legacy_python=with_legacy_python, + with_docs=with_docs) # Modify MANIFEST.in with meta options diff --git a/config/default/tests.yml.j2 b/config/default/tests.yml.j2 index 6415f9e..0394b32 100644 --- a/config/default/tests.yml.j2 +++ b/config/default/tests.yml.j2 @@ -14,7 +14,7 @@ jobs: config: # [Python version, tox env] - ["3.8", "lint"] -{% if with_py2 %} +{% if with_legacy_python %} - ["2.7", "py27"] - ["3.5", "py35"] {% endif %} @@ -22,7 +22,7 @@ jobs: - ["3.7", "py37"] - ["3.8", "py38"] - ["3.9", "py39"] -{% if with_pypy and with_py2 %} +{% if with_pypy and with_legacy_python %} - ["pypy2", "pypy"] {% endif %} {% if with_pypy %} diff --git a/config/pure-python/tox.ini.j2 b/config/pure-python/tox.ini.j2 index d17f459..9e9d6ba 100644 --- a/config/pure-python/tox.ini.j2 +++ b/config/pure-python/tox.ini.j2 @@ -1,7 +1,7 @@ [tox] envlist = lint, -{% if with_py2 %} +{% if with_legacy_python %} py27, py35, {% endif %} @@ -9,7 +9,7 @@ envlist = py37, py38, py39, -{% if with_pypy and with_py2 %} +{% if with_pypy and with_legacy_python %} pypy, {% endif %} {% if with_pypy %} From adca9ce08d7d7ef02cd8e6f95f92715ed873b36a Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Tue, 24 Nov 2020 16:09:41 +0100 Subject: [PATCH 3/3] Add ability to set additional-flake8-config in .meta.cfg. --- config/README.rst | 7 +++++++ config/config-package.py | 8 ++++++-- .../setup.cfg => default/setup.cfg.j2} | 9 +++++++++ config/pure-python/setup.cfg | 12 ------------ 4 files changed, 22 insertions(+), 14 deletions(-) rename config/{buildout-recipe/setup.cfg => default/setup.cfg.j2} (54%) delete mode 100644 config/pure-python/setup.cfg diff --git a/config/README.rst b/config/README.rst index b5d7c05..16af92e 100644 --- a/config/README.rst +++ b/config/README.rst @@ -150,6 +150,8 @@ updated. Example: with-sphinx-doctests = False with-legacy-python = True additional-manifest-rules = + additional-flake8-config = + ignore = D203 Meta Options @@ -181,6 +183,11 @@ with-sphinx-doctests additional-manifest-rules Additional rules to be added at the end of the MANIFEST.in file. +additional-flake8-config + Additional configuration options be added at the end of the flake8 + configuration section in ``setup.cfg``. + + Hints ----- diff --git a/config/config-package.py b/config/config-package.py index b02b171..9c0c3d2 100755 --- a/config/config-package.py +++ b/config/config-package.py @@ -37,7 +37,7 @@ def copy_with_meta(template_name, destination, config_type, **kw): with open(destination, 'w') as f_: f_.write(META_HINT.format(config_type=config_type)) template = jinja_env.get_template(template_name) - f_.write(template.render(**kw)) + f_.write(template.render(config_type=config_type, **kw)) parser = argparse.ArgumentParser( @@ -138,7 +138,11 @@ def copy_with_meta(template_name, destination, config_type, **kw): meta_opts['with-sphinx-doctests'] = str(with_sphinx_doctests) # Copy template files -copy_with_meta('setup.cfg', path / 'setup.cfg', config_type) +additional_flake8_config = meta_opts.get( + 'additional-flake8-config', '').strip() +copy_with_meta('setup.cfg.j2', path / 'setup.cfg', config_type, + additional_flake8_config=additional_flake8_config, + with_docs=with_docs, with_sphinx_doctests=with_sphinx_doctests) copy_with_meta('editorconfig', path / '.editorconfig', config_type) copy_with_meta('gitignore', path / '.gitignore', config_type) workflows = path / '.github' / 'workflows' diff --git a/config/buildout-recipe/setup.cfg b/config/default/setup.cfg.j2 similarity index 54% rename from config/buildout-recipe/setup.cfg rename to config/default/setup.cfg.j2 index ad7ed17..a986fd0 100644 --- a/config/buildout-recipe/setup.cfg +++ b/config/default/setup.cfg.j2 @@ -3,12 +3,21 @@ universal = 1 [flake8] doctests = 1 +{% if config_type == 'buildout-recipe' %} # provided to doctests by buildoutSetUp() builtins = write, system, cat, join +{% endif %} +{% if additional_flake8_config %} +%(additional_flake8_config)s +{% endif %} [check-manifest] ignore = .editorconfig .meta.cfg +{% if with_docs %} docs/_build/html/_sources/* +{% endif %} +{% if with_sphinx_doctests %} docs/_build/doctest/* +{% endif %} diff --git a/config/pure-python/setup.cfg b/config/pure-python/setup.cfg deleted file mode 100644 index 4c17add..0000000 --- a/config/pure-python/setup.cfg +++ /dev/null @@ -1,12 +0,0 @@ -[bdist_wheel] -universal = 1 - -[flake8] -doctests = 1 - -[check-manifest] -ignore = - .editorconfig - .meta.cfg - docs/_build/html/_sources/* - docs/_build/doctest/*