-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sbachmei/mic 5755/improve supported py version handling (#136)
* 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
1 parent
6bef110
commit d315713
Showing
8 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[build-system] | ||
requires = ["packaging", "setuptools"] | ||
|
||
[tool.black] | ||
line_length = 94 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["3.11", "3.12"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |