Skip to content

Commit

Permalink
Add Input range (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
ric-evans authored Nov 14, 2024
1 parent df0627a commit b505fce
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

.idea/

49 changes: 19 additions & 30 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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<semver_range>[^\"]+)\"$")
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<semver_range>.+)$")
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
28 changes: 28 additions & 0 deletions parse_out_range.py
Original file line number Diff line number Diff line change
@@ -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<semver_range>[^\"]+)\"$")
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<semver_range>.+)$")
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)

0 comments on commit b505fce

Please # to comment.