From b505fce818f39230f8505928610b6968302f42fb Mon Sep 17 00:00:00 2001 From: Ric Evans <19216225+ric-evans@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:13:27 -0600 Subject: [PATCH] Add Input `range` (#13) --- .gitignore | 3 +++ action.yml | 49 ++++++++++++++++++---------------------------- parse_out_range.py | 28 ++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 parse_out_range.py diff --git a/.gitignore b/.gitignore index b6e4761..d577315 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +.idea/ + diff --git a/action.yml b/action.yml index e6ecbce..f6f38d3 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,12 @@ name: 'WIPAC Dev Py Versions' description: 'GitHub Action Package for Generating a Build Matrix of Supported Python Versions for a Package' +inputs: + range: + description: 'Optional semantic versioning expression for supported Python releases (e.g., ">=3.9", ">=3.8, <3.13"), if not given then the range will be retrived from python package metadata.' + required: false + default: '' + outputs: matrix: description: "List of Supported Python Versions" @@ -16,44 +22,27 @@ runs: python -m venv action_venv . action_venv/bin/activate pip3 install -r ${{ github.action_path }}/requirements.txt - - MIN_THRU_MAX_SERIES_SPACED=$(python -c ' - import os, re + + SEMVER_RANGE="${{ inputs.range }}" + if [ -z "$SEMVER_RANGE" ]; then + SEMVER_RANGE=$(python ${{ github.action_path }}/parse_out_range.py) + fi + + MIN_THRU_MAX_SERIES_SPACED=$(python -c " from wipac_dev_tools import semver_parser_tools - - semver_range = "" - if os.path.isfile("pyproject.toml"): - # ex: requires-python = ">=3.8, <3.13" - pat = re.compile(r"requires-python = \"(?P[^\"]+)\"$") - with open("pyproject.toml") as f: - for line in f: - if m := pat.match(line): - semver_range = m.group("semver_range") - if not semver_range: - raise Exception("could not find `requires-python` entry in pyproject.toml") - elif os.path.isfile("setup.cfg"): - # ex: python_requires = >=3.8, <3.13 - pat = re.compile(r"python_requires = (?P.+)$") - with open("setup.cfg") as f: - for line in f: - if m := pat.match(line): - semver_range = m.group("semver_range") - if not semver_range: - raise Exception("could not find `python_requires` entry in setup.cfg") - else: - raise Exception("could not find pyproject.toml nor setup.cfg") - + top_python = semver_parser_tools.get_latest_py3_release() all_matches = semver_parser_tools.list_all_majmin_versions( major=top_python[0], - semver_range=semver_range, + semver_range='$SEMVER_RANGE', max_minor=top_python[1], ) - print(" ".join(f"{v[0]}.{v[1]}" for v in all_matches)) - ') + print(' '.join(f'{v[0]}.{v[1]}' for v in all_matches)) + ") echo $MIN_THRU_MAX_SERIES_SPACED - + # now, output echo "matrix=$( echo $MIN_THRU_MAX_SERIES_SPACED | jq -cR 'split(" ")' )" >> $GITHUB_OUTPUT + shell: bash diff --git a/parse_out_range.py b/parse_out_range.py new file mode 100644 index 0000000..d67a6a9 --- /dev/null +++ b/parse_out_range.py @@ -0,0 +1,28 @@ +"""A script for parsing out ranges from python package metadata files.""" + +import os +import re + +semver_range = "" +if os.path.isfile("pyproject.toml"): + # ex: requires-python = ">=3.8, <3.13" + pat = re.compile(r"requires-python = \"(?P[^\"]+)\"$") + with open("pyproject.toml") as f: + for line in f: + if m := pat.match(line): + semver_range = m.group("semver_range") + if not semver_range: + raise Exception("could not find `requires-python` entry in pyproject.toml") +elif os.path.isfile("setup.cfg"): + # ex: python_requires = >=3.8, <3.13 + pat = re.compile(r"python_requires = (?P.+)$") + with open("setup.cfg") as f: + for line in f: + if m := pat.match(line): + semver_range = m.group("semver_range") + if not semver_range: + raise Exception("could not find `python_requires` entry in setup.cfg") +else: + raise Exception("could not find pyproject.toml nor setup.cfg") + +print(semver_range)