Skip to content

Commit

Permalink
- automatically generate Python version lists
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Sep 16, 2024
1 parent 83abfe7 commit 0e4cc21
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 56 deletions.
23 changes: 10 additions & 13 deletions config/c-code/manylinux-install.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ yum -y install libffi-devel

tox_env_map() {
case $1 in
*"cp38"*) echo 'py38';;
*"cp39"*) echo 'py39';;
*"cp310"*) echo 'py310';;
*"cp311"*) echo 'py311';;
*"cp312"*) echo 'py312';;
*"cp313"*) echo 'py313';;
{% for py_version in supported_python_versions %}
*"cp%(py_version)s"*) echo 'py%(py_version)s';;
{% endfor %}
{% if with_future_python %}
*"cp%(future_python_shortversion)s"*) echo 'py%(future_python_shortversion)s';;
{% endif %}
Expand All @@ -45,15 +42,15 @@ tox_env_map() {
# Compile wheels
for PYBIN in /opt/python/*/bin; do
if \
[[ "${PYBIN}" == *"cp311/"* ]] || \
[[ "${PYBIN}" == *"cp312/"* ]] || \
[[ "${PYBIN}" == *"cp313/"* ]] || \
{% for py_version in supported_python_versions %}
[[ "${PYBIN}" == *"cp%(py_version)s/"* ]] {% if py_version != stop_at %}|| \
{% endif %}
{% endfor %}
{% if with_future_python %}
[[ "${PYBIN}" == *"cp%(future_python_shortversion)s/"* ]] || \
[[ "${PYBIN}" == *"cp%(future_python_shortversion)s/"* ]] ; then
{% else %}
; then
{% endif %}
[[ "${PYBIN}" == *"cp38/"* ]] || \
[[ "${PYBIN}" == *"cp39/"* ]] || \
[[ "${PYBIN}" == *"cp310/"* ]] ; then
{% if with_future_python %}
if [[ "${PYBIN}" == *"cp%(future_python_shortversion)s/"* ]] ; then
"${PYBIN}/pip" install --pre -e /io/
Expand Down
9 changes: 3 additions & 6 deletions config/c-code/tests-strategy.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
{% if with_pypy %}
- "pypy-%(pypy_version)s"
{% endif %}
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
{% for (py_long_version, py_short_version) in supported_python_versions %}
- "%(py_long_version)s"
{% endfor %}
{% if with_future_python %}
- "%(future_python_version)s"
{% endif %}
Expand Down
9 changes: 3 additions & 6 deletions config/c-code/tox.ini.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
minversion = 4.0
envlist =
lint
py38,py38-pure
py39,py39-pure
py310,py310-pure
py311,py311-pure
py312,py312-pure
py313,py313-pure
{% for py_version in supported_python_versions %}
py%(py_version)s,py%(py_version)s-pure
{% endfor %}
{% if with_future_python %}
py%(future_python_shortversion)s,py%(future_python_shortversion)s-pure
{% endif %}
Expand Down
12 changes: 12 additions & 0 deletions config/config-package.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
from shared.packages import MANYLINUX_I686
from shared.packages import MANYLINUX_PYTHON_VERSION
from shared.packages import MANYLINUX_X86_64
from shared.packages import NEWEST_PYTHON_VERSION
from shared.packages import OLDEST_PYTHON_VERSION
from shared.packages import PYPY_VERSION
from shared.packages import SETUPTOOLS_VERSION_SPEC
from shared.packages import get_pyproject_toml_defaults
from shared.packages import parse_additional_config
from shared.packages import supported_python_versions
from shared.path import change_dir
import argparse
import collections
Expand All @@ -38,6 +40,7 @@


FUTURE_PYTHON_SHORTVERSION = FUTURE_PYTHON_VERSION.replace('.', '')
NEWEST_PYTHON_SHORTVERSION = NEWEST_PYTHON_VERSION.replace('.', '')
META_HINT = """\
# Generated from:
# https://github.com/zopefoundation/meta/tree/master/config/{config_type}"""
Expand Down Expand Up @@ -374,6 +377,9 @@ def manylinux_sh(self):
self.copy_with_meta(
'manylinux.sh', self.path / '.manylinux.sh', self.config_type)
(self.path / '.manylinux.sh').chmod(0o755)
stop_at = None
if not self.with_future_python:
stop_at = NEWEST_PYTHON_SHORTVERSION
self.copy_with_meta(
'manylinux-install.sh.j2', self.path / '.manylinux-install.sh',
self.config_type,
Expand All @@ -382,6 +388,8 @@ def manylinux_sh(self):
manylinux_aarch64_tests=manylinux_aarch64_tests,
with_future_python=self.with_future_python,
future_python_shortversion=FUTURE_PYTHON_SHORTVERSION,
supported_python_versions=supported_python_versions(True),
stop_at=stop_at,
)
(self.path / '.manylinux-install.sh').chmod(0o755)
self.add_manylinux = True
Expand Down Expand Up @@ -465,6 +473,7 @@ def tox(self):
docs_deps=docs_deps,
setuptools_version_spec=SETUPTOOLS_VERSION_SPEC,
future_python_shortversion=FUTURE_PYTHON_SHORTVERSION,
supported_python_versions=supported_python_versions(True),
)

def tests_yml(self):
Expand All @@ -482,6 +491,8 @@ def tests_yml(self):
gha_test_commands = self.gh_option('test-commands')
require_cffi = self.meta_cfg.get(
'c-code', {}).get('require-cffi', False)
py_version_matrix = [x for x in zip(supported_python_versions(False),
supported_python_versions(True))]
self.copy_with_meta(
'tests.yml.j2',
workflows / 'tests.yml',
Expand Down Expand Up @@ -510,6 +521,7 @@ def tests_yml(self):
pypy_version=PYPY_VERSION,
setuptools_version_spec=SETUPTOOLS_VERSION_SPEC,
future_python_shortversion=FUTURE_PYTHON_SHORTVERSION,
supported_python_versions=py_version_matrix,
)

def pre_commit_yml(self):
Expand Down
31 changes: 14 additions & 17 deletions config/default/tests.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,21 @@ jobs:
{% endif %}
config:
# [Python version, tox env]
- ["3.11", "release-check"]
- ["3.8", "py38"]
- ["3.9", "py39"]
- ["3.10", "py310"]
- ["3.11", "py311"]
- ["3.12", "py312"]
- ["3.13", "py313"]
- ["3.11", "release-check"]
{% for (py_long_version, py_short_version) in supported_python_versions %}
- ["%(py_long_version)s", "py%(py_short_version)s"]
{% endfor %}
{% if with_future_python %}
- ["%(future_python_version)s", "py%(future_python_shortversion)s"]
- ["%(future_python_version)s", "py%(future_python_shortversion)s"]
{% endif %}
{% if with_pypy %}
- ["pypy-3.10", "pypy3"]
- ["pypy-%(pypi_version)s", "pypy3"]
{% endif %}
{% if with_docs %}
- ["3.11", "docs"]
- ["3.11", "docs"]
{% endif %}
{% if with_coverage %}
- ["3.11", "coverage"]
- ["3.11", "coverage"]
{% endif %}
{% for line in gha_additional_config %}
%(line)s
Expand All @@ -61,18 +58,18 @@ jobs:
exclude:
{% endif %}
{% if with_windows %}
- { os: ["windows", "windows-latest"], config: ["3.11", "release-check"] }
- { os: ["windows", "windows-latest"], config: ["3.11", "release-check"] }
{% if with_docs %}
- { os: ["windows", "windows-latest"], config: ["3.11", "docs"] }
- { os: ["windows", "windows-latest"], config: ["3.11", "docs"] }
{% endif %}
- { os: ["windows", "windows-latest"], config: ["3.11", "coverage"] }
- { os: ["windows", "windows-latest"], config: ["3.11", "coverage"] }
{% endif %}
{% if with_macos %}
- { os: ["macos", "macos-latest"], config: ["3.11", "release-check"] }
- { os: ["macos", "macos-latest"], config: ["3.11", "release-check"] }
{% if with_docs %}
- { os: ["macos", "macos-latest"], config: ["3.11", "docs"] }
- { os: ["macos", "macos-latest"], config: ["3.11", "docs"] }
{% endif %}
- { os: ["macos", "macos-latest"], config: ["3.11", "coverage"] }
- { os: ["macos", "macos-latest"], config: ["3.11", "coverage"] }
{% endif %}
{% for line in gha_additional_exclude %}
%(line)s
Expand Down
9 changes: 3 additions & 6 deletions config/default/tox-envlist.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ minversion = 3.18
envlist =
release-check
lint
py38
py39
py310
py311
py312
py313
{% for py_version in supported_python_versions %}
py%(py_version)s
{% endfor %}
{% if with_future_python %}
py%(future_python_shortversion)s
{% endif %}
Expand Down
30 changes: 26 additions & 4 deletions config/shared/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@
import configparser
import itertools
import pathlib
from packaging.version import parse as parse_version


TYPES = ['buildout-recipe', 'c-code', 'pure-python', 'zope-product', 'toolkit']
ORG = 'zopefoundation'
BASE_PATH = pathlib.Path(__file__).parent.parent
OLDEST_PYTHON_VERSION = '3.8'
NEWEST_PYTHON_VERSION = '3.13'
SUPPORTED_PYTHON_VERSIONS = [
f'3.{i}' for i in range(int(OLDEST_PYTHON_VERSION.replace('3.', '')),
int(NEWEST_PYTHON_VERSION.replace('3.', '')) + 1)
]
FUTURE_PYTHON_VERSION = '3.14'
PYPY_VERSION = '3.10'
SETUPTOOLS_VERSION_SPEC = '<74'
Expand Down Expand Up @@ -147,6 +144,31 @@ def parse_additional_config(cfg):
return data


def supported_python_versions(short_version=False):
"""Create a list containing all supported Python versions
Uses the configured oldest and newest Python versions to compute a list
containing all versions from oldest to newest that can be iterated over in
the templates.
Kwargs:
short_version (bool):
Return short versions like "313" instead of "3.13"
"""
minor_versions = []
oldest_python = parse_version(OLDEST_PYTHON_VERSION)
newest_python = parse_version(NEWEST_PYTHON_VERSION)
for minor in range(oldest_python.minor, newest_python.minor+1):
minor_versions.append(minor)
supported = [f'{oldest_python.major}.{minor}' for minor in minor_versions]

if short_version:
return [x.replace('.', '') for x in supported]

return supported


def list_packages(path: pathlib.Path) -> list:
"""List the packages in ``path``.
Expand Down
8 changes: 4 additions & 4 deletions config/update-python-support.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from shared.git import get_branch_name
from shared.git import git_branch
from shared.packages import OLDEST_PYTHON_VERSION
from shared.packages import SUPPORTED_PYTHON_VERSIONS
from shared.packages import supported_python_versions
from shared.path import change_dir
import argparse
import collections
Expand Down Expand Up @@ -85,8 +85,8 @@ def get_tox_ini_python_versions(path):

current_python_versions = get_tox_ini_python_versions('tox.ini')
no_longer_supported = (set(current_python_versions) -
set(SUPPORTED_PYTHON_VERSIONS))
not_yet_supported = (set(SUPPORTED_PYTHON_VERSIONS) -
set(supported_python_versions()))
not_yet_supported = (set(supported_python_versions()) -
set(current_python_versions))

non_interactive_params = []
Expand All @@ -97,7 +97,7 @@ def get_tox_ini_python_versions(path):

if no_longer_supported or not_yet_supported:
call(bin_dir / 'bumpversion', '--feature', *non_interactive_params)
python_versions_args = ['--add=' + ','.join(SUPPORTED_PYTHON_VERSIONS)]
python_versions_args = ['--add=' + ','.join(supported_python_versions())]
if no_longer_supported:
for version in sorted(list(no_longer_supported)):
call(bin_dir / 'addchangelogentry',
Expand Down

0 comments on commit 0e4cc21

Please sign in to comment.