Skip to content

Commit

Permalink
Add script to drop Python 2.7 up to 3.6 support. (#179)
Browse files Browse the repository at this point in the history
* Add script to drop Python 2.7 up to 3.6 support.
* Drop support for `--without-legacy-python` as it is the default now.
* replace macos-latest with macos-11 to work around test failures

Co-authored-by: Maurits van Rees <[email protected]>
Co-authored-by: Jens Vagelpohl <[email protected]>
  • Loading branch information
3 people authored Dec 23, 2022
1 parent 019f22e commit b274912
Show file tree
Hide file tree
Showing 20 changed files with 202 additions and 104 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cache/pip
Expand All @@ -27,7 +27,7 @@ jobs:
restore-keys: |
lint-v1-
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.x'

Expand Down
38 changes: 30 additions & 8 deletions config/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,6 @@ The following options are only needed one time as their values re stored in
a final release thus it is not yet generally supported by the zopefoundation
packages.

--without-legacy-python
The package does not support Python versions which reached their end-of-life.
(Currently this is a no-op as there are no supported legacy versions).

--with-docs
Enable building the documentation using Sphinx.

Expand Down Expand Up @@ -202,7 +198,6 @@ updated. Example:
[python]
with-appveyor = false
with-legacy-python = true
with-pypy = false
with-docs = true
with-sphinx-doctests = false
Expand Down Expand Up @@ -394,9 +389,6 @@ with-macos
with-windows
Run the tests also on Windows on GitHub Actions: true/false, default: false

with-legacy-python
Run the tests even on legacy versions (currently none): true/false

with-pypy
Does the package support PyPy: true/false

Expand Down Expand Up @@ -749,3 +741,33 @@ Usage
To run the script just call it::

$ bin/python re-enable-actions.py

Dropping support for legacy Python versions
-------------------------------------------

To drop support for Python 2.7 up to 3.6 several steps have to be done as
documented at https://zope.dev/developer/python2.html#how-to-drop-support.
There is a script to ease this process.

Preparation
+++++++++++

* The package to remove legacy python support from has to have a ``.meta.toml``
file aka it must be under control of the ``config-package.py`` script.

Usage
+++++

To run the script call::

$ bin/python drop-legacy-python.py <path-to-package>

Additional optional parameters, see above at ``config-package.py`` for a
descriptions of them:

* ``--branch``

You can call the script interactively by passing the argument
``--interactive``, this will let the various scripts prompt for information and
prevent automatic commits and pushes. That way all changes can be viewed before
committing them.
3 changes: 0 additions & 3 deletions config/buildout-recipe/coveragerc.j2
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
[run]
source = %(coverage_run_source)s
{% if with_legacy_python %}
plugins = coverage_python_version
{% endif %}
branch = true
parallel = true
{% for line in run_additional_config %}
Expand Down
3 changes: 0 additions & 3 deletions config/buildout-recipe/tox.ini.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ setenv =
{% endif %}
deps =
coverage
{% if with_legacy_python %}
coverage-python-version
{% endif %}
{% for line in testenv_deps %}
%(line)s
{% endfor %}
Expand Down
4 changes: 0 additions & 4 deletions config/c-code/manylinux-install.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ yum -y install libffi-devel

tox_env_map() {
case $1 in
{% if with_legacy_python %}
{% endif %}
{% if with_future_python %}
*"cp312"*) echo 'py312';;
{% endif %}
Expand All @@ -46,8 +44,6 @@ tox_env_map() {
# Compile wheels
for PYBIN in /opt/python/*/bin; do
if \
{% if with_legacy_python %}
{% endif %}
{% if with_future_python %}
[[ "${PYBIN}" == *"cp312"* ]] || \
{% endif %}
Expand Down
10 changes: 2 additions & 8 deletions config/c-code/tests-strategy.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
fail-fast: false
matrix:
python-version:
{% if with_legacy_python %}
{% endif %}
{% if with_pypy and with_legacy_python %}
{% endif %}
{% if with_pypy %}
- "pypy-3.7"
{% endif %}
Expand All @@ -17,16 +13,14 @@
{% if with_future_python %}
- "%(future_python_version)s"
{% endif %}
os: [ubuntu-20.04, macos-latest]
os: [ubuntu-20.04, macos-11]
{% if with_pypy or gha_additional_exclude %}
exclude:
{% endif %}
{% if with_pypy %}
- os: macos-latest
- os: macos-11
python-version: "pypy-3.7"
{% endif %}
{% if with_legacy_python %}
{% endif %}
{% for line in gha_additional_exclude %}
%(line)s
{% endfor %}
4 changes: 0 additions & 4 deletions config/c-code/tox.ini.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
minversion = 3.18
envlist =
lint
{% if with_legacy_python %}
{% endif %}
py37,py37-pure
py38,py38-pure
py39,py39-pure
Expand All @@ -16,8 +14,6 @@ envlist =
{% if with_future_python %}
py312,py312-pure
{% endif %}
{% if with_pypy and with_legacy_python %}
{% endif %}
{% if with_pypy %}
pypy3
{% endif %}
Expand Down
44 changes: 11 additions & 33 deletions config/config-package.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python3
from shared.call import abort
from shared.call import call
from shared.git import get_branch_name
from shared.git import get_commit_id
from shared.git import git_branch
from shared.path import change_dir
from shared.toml_encoder import TomlArraySeparatorEncoderWithNewline
import argparse
Expand Down Expand Up @@ -101,13 +104,6 @@ def copy_with_meta(
default=False,
help='Activate support for a future non-final Python version if not'
' already configured in .meta.toml.')
parser.add_argument(
'--without-legacy-python',
dest='with_legacy_python',
action='store_false',
default=None,
help='Disable support for Python versions which reached their end-of-life.'
' (currently no versions) if not already configured in .meta.toml.')
parser.add_argument(
'--with-docs',
# people (me) use --with-sphinx and accidentally get --with-sphinx-doctests
Expand Down Expand Up @@ -194,8 +190,7 @@ def copy_with_meta(
lstrip_blocks=True,
)

meta_cfg['meta']['commit-id'] = call(
'git', 'log', '-n1', '--format=format:%H', capture_output=True).stdout
meta_cfg['meta']['commit-id'] = get_commit_id()
with_appveyor = meta_cfg['python'].get(
'with-appveyor', False) or args.with_appveyor
meta_cfg['python']['with-appveyor'] = with_appveyor
Expand All @@ -210,17 +205,15 @@ def copy_with_meta(
with_future_python = (meta_cfg['python'].get('with-future-python', False)
or args.with_future_python)
meta_cfg['python']['with-future-python'] = with_future_python
if args.with_legacy_python is None:
with_legacy_python = meta_cfg['python'].get('with-legacy-python', True)
else:
with_legacy_python = args.with_legacy_python
meta_cfg['python']['with-legacy-python'] = with_legacy_python
with_docs = meta_cfg['python'].get('with-docs', False) or args.with_docs
meta_cfg['python']['with-docs'] = with_docs
with_sphinx_doctests = meta_cfg['python'].get(
'with-sphinx-doctests', False) or args.with_sphinx_doctests
meta_cfg['python']['with-sphinx-doctests'] = with_sphinx_doctests

try:
del meta_cfg['python']['with-legacy-python']
except KeyError:
pass

if with_sphinx_doctests and not with_docs:
print("The package is configured without sphinx docs, but with sphinx"
Expand Down Expand Up @@ -260,7 +253,6 @@ def copy_with_meta(
isort_known_first_party=isort_known_first_party,
isort_known_local_folder=isort_known_local_folder,
with_docs=with_docs, with_sphinx_doctests=with_sphinx_doctests,
with_legacy_python=with_legacy_python,
zest_releaser_options=zest_releaser_options,
)

Expand Down Expand Up @@ -291,7 +283,6 @@ def copy_with_meta(
'coveragerc.j2', path / '.coveragerc', config_type,
coverage_run_source=coverage_run_source,
run_additional_config=coverage_run_additional_config,
with_legacy_python=with_legacy_python,
)
add_coveragerc = True
elif (path / '.coveragerc').exists():
Expand All @@ -315,7 +306,6 @@ def copy_with_meta(
package_name=path.name,
setup=manylinux_install_setup,
aarch64_tests=manylinux_aarch64_tests,
with_legacy_python=with_legacy_python,
with_future_python=with_future_python,
)
(path / '.manylinux-install.sh').chmod(0o755)
Expand Down Expand Up @@ -374,7 +364,6 @@ def copy_with_meta(
testenv_setenv=testenv_setenv,
use_flake8=use_flake8,
with_docs=with_docs,
with_legacy_python=with_legacy_python,
with_future_python=with_future_python,
with_pypy=with_pypy,
with_sphinx_doctests=with_sphinx_doctests,
Expand Down Expand Up @@ -405,7 +394,6 @@ def copy_with_meta(
steps_before_checkout=gha_steps_before_checkout,
with_docs=with_docs,
with_sphinx_doctests=with_sphinx_doctests,
with_legacy_python=with_legacy_python,
with_future_python=with_future_python,
future_python_version=FUTURE_PYTHON_VERSION,
with_pypy=with_pypy,
Expand Down Expand Up @@ -442,7 +430,6 @@ def copy_with_meta(
appveyor_replacement = meta_cfg['appveyor'].get('replacement', [])
copy_with_meta(
'appveyor.yml.j2', path / 'appveyor.yml', config_type,
with_legacy_python=with_legacy_python,
with_future_python=with_future_python,
global_env_vars=appveyor_global_env_vars,
additional_matrix=appveyor_additional_matrix,
Expand All @@ -453,9 +440,7 @@ def copy_with_meta(
)


branch_name = (
args.branch_name
or f"config-with-{config_type}-template-{meta_cfg['meta']['commit-id']}")
branch_name = get_branch_name(args.branch_name, config_type)
with change_dir(path) as cwd:
if pathlib.Path('bootstrap.py').exists():
call('git', 'rm', 'bootstrap.py')
Expand All @@ -482,15 +467,8 @@ def copy_with_meta(
tox_path = shutil.which('tox') or (pathlib.Path(cwd) / 'bin' / 'tox')
call(tox_path, '-p', 'auto')

branches = call(
'git', 'branch', '--format', '%(refname:short)',
capture_output=True).stdout.splitlines()
if branch_name in branches:
call('git', 'checkout', branch_name)
updating = True
else:
call('git', 'checkout', '-b', branch_name)
updating = False
updating = git_branch(branch_name)

if not fail_under:
print('In .meta.toml in section [coverage] the option "fail-under" is'
' 0. Please enter a valid minimum coverage and rerun.')
Expand Down
2 changes: 0 additions & 2 deletions config/default/appveyor.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ environment:
{% endfor %}

matrix:
{% if with_legacy_python %}
{% endif %}
- python: 37-x64
- python: 38-x64
- python: 39-x64
Expand Down
4 changes: 0 additions & 4 deletions config/default/setup.cfg.j2
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
[bdist_wheel]
{% if with_legacy_python %}
universal = 1
{% else %}
universal = 0
{% endif %}
{% if zest_releaser_options %}

[zest.releaser]
Expand Down
18 changes: 5 additions & 13 deletions config/default/tests.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ jobs:
- ["windows", "windows-latest"]
{% endif %}
{% if with_macos %}
- ["macos", "macos-latest"]
- ["macos", "macos-11"]
{% endif %}
config:
# [Python version, tox env]
- ["3.9", "lint"]
{% if with_legacy_python %}
{% endif %}
- ["3.7", "py37"]
- ["3.8", "py38"]
- ["3.9", "py39"]
Expand All @@ -41,8 +39,6 @@ jobs:
{% if with_future_python %}
- ["%(future_python_version)s", "py312"]
{% endif %}
{% if with_pypy and with_legacy_python %}
{% endif %}
{% if with_pypy %}
- ["pypy-3.7", "pypy3"]
{% endif %}
Expand All @@ -64,14 +60,14 @@ jobs:
- { os: ["windows", "windows-latest"], config: ["3.9", "coverage"] }
{% endif %}
{% if with_macos %}
- { os: ["macos", "macos-latest"], config: ["3.9", "lint"] }
- { os: ["macos", "macos-11"], config: ["3.9", "lint"] }
{% if with_docs %}
- { os: ["macos", "macos-latest"], config: ["3.9", "docs"] }
- { os: ["macos", "macos-11"], config: ["3.9", "docs"] }
{% endif %}
- { os: ["macos", "macos-latest"], config: ["3.9", "coverage"] }
- { os: ["macos", "macos-11"], config: ["3.9", "coverage"] }
# macOS/Python 3.11 is set up for universal2 architecture
# which causes build and package selection issues.
- { os: ["macos", "macos-latest"], config: ["3.11", "py311"] }
- { os: ["macos", "macos-11"], config: ["3.11", "py311"] }
{% endif %}
{% for line in gha_additional_exclude %}
%(line)s
Expand Down Expand Up @@ -120,11 +116,7 @@ jobs:
- name: Coverage
if: matrix.config[1] == 'coverage'
run: |
{% if with_legacy_python %}
pip install coveralls coverage-python-version
{% else %}
pip install coveralls
{% endif %}
coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 0 additions & 3 deletions config/default/tox-coverage-config.j2
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

[coverage:run]
branch = True
{% if with_legacy_python %}
plugins = coverage_python_version
{% endif %}
source = %(coverage_run_source)s
{% for line in coverage_run_additional_config %}
%(line)s
Expand Down
Loading

0 comments on commit b274912

Please sign in to comment.