Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sbachmei/mic 5755/improve supported py version handling #136

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}
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.1, 3.2**
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this to test that the update-readme action kicks off and changes these back automatically


.. _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)
Loading