Skip to content

Commit

Permalink
Sbachmei/mic 5755/improve supported py version handling (#136)
Browse files Browse the repository at this point in the history
* validate python version during setup

* automatically update README with supported py versions

* auto-generate github action build matrix

---------

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
stevebachmeier and actions-user authored Jan 7, 2025
1 parent 6bef110 commit d315713
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 2 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,25 @@ name: build
on: [push, pull_request, workflow_dispatch]

jobs:
get-python-versions:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install jq
run: sudo apt-get install jq
- name: Get Python versions
id: set-matrix
run: |
echo "MATRIX_RESULT=$(jq -c . python_versions.json)" >> $GITHUB_ENV
outputs:
matrix: ${{ env.MATRIX_RESULT }}
build:
needs: get-python-versions
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12"]
python-version: ${{ fromJSON(needs.get-python-versions.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/update_readme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -----------------------------------------------------------------------------
# - invoked on push to any branch
# -----------------------------------------------------------------------------
name: update README

on: push

jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Update README
run: |
pip install packaging
python update_readme.py
- name: Commit and push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "github-actions"
git diff --quiet && git diff --staged --quiet || (
git add README.rst
git commit -am "update README with supported Python versions"
git pull --rebase origin ${{ github.ref_name }}
git push origin ${{ github.ref_name }}
)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
**0.1.3 - 1/6/25**

- Validate currently-installed python version during setup
- Automatically update README when supported python versions change
- Automatically extract github actions supported python version test matrix

**0.1.2 - 12/16/24**

- Add optional arg to pass allowable schemas to the Config constructor
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ entity resolution (ER) pipelines.

.. _python_support:

Supported Python versions: 3.11, 3.12
**Supported Python versions: 3.11, 3.12**

.. _end_python_support:

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[build-system]
requires = ["packaging", "setuptools"]

[tool.black]
line_length = 94

Expand Down
1 change: 1 addition & 0 deletions python_versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["3.11", "3.12"]
28 changes: 28 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
#!/usr/bin/env python
import json
import os
import sys

from packaging.version import parse
from setuptools import find_packages, setup

with open("python_versions.json", "r") as f:
supported_python_versions = json.load(f)

python_versions = [parse(v) for v in supported_python_versions]
min_version = min(python_versions)
max_version = max(python_versions)
if not (
min_version <= parse(".".join([str(v) for v in sys.version_info[:2]])) <= max_version
):
py_version = ".".join([str(v) for v in sys.version_info[:3]])
# NOTE: Python 3.5 does not support f-strings
error = (
"\n--------------------------------------------\n"
"Error: EasyLink runs under python {min_version}-{max_version}.\n"
"You are running python {py_version}.\n".format(
min_version=min_version.base_version,
max_version=max_version.base_version,
py_version=py_version,
)
+ "--------------------------------------------\n"
)
print(error, file=sys.stderr)
sys.exit(1)


if __name__ == "__main__":
base_dir = os.path.dirname(__file__)
src_dir = os.path.join(base_dir, "src")
Expand Down
32 changes: 32 additions & 0 deletions update_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
""" This script updates the README.rst file with the latest information about
the project. It is intended to be run from the github "update README" workflow.
"""

import json
import re

from packaging.version import parse

# Load supported python versions
with open("python_versions.json", "r") as f:
versions = json.load(f)
versions_str = ", ".join(versions)
versions = [parse(v) for v in versions]
max_version = max(versions).base_version

# Open README and replace python versions
with open("README.rst", "r") as file:
readme = file.read()
# Update the list of supported python versions
# NOTE: this regex assumes the version format is always major.minor
readme = re.sub(
r"Supported Python versions:\s*(?:\d+\.\d+\s*,\s*)+\d+\.\d+",
r"Supported Python versions: " + versions_str,
readme,
)
# Update the python version used in the installation code snipped example
readme = re.sub(r"python=\d+\.\d+", "python=" + max_version, readme)

# Write the updated README back to file
with open("README.rst", "w") as file:
file.write(readme)

0 comments on commit d315713

Please sign in to comment.