From 1f39084aca23958b32ebee952ebbafa206297397 Mon Sep 17 00:00:00 2001 From: Steve Bachmeier Date: Mon, 6 Jan 2025 13:13:05 -0800 Subject: [PATCH 1/5] validate python version during setup --- pyproject.toml | 3 +++ python_versions.json | 1 + setup.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 python_versions.json diff --git a/pyproject.toml b/pyproject.toml index d787dc52..dcef0406 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,6 @@ +[build-system] +requires = ["packaging", "setuptools"] + [tool.black] line_length = 94 diff --git a/python_versions.json b/python_versions.json new file mode 100644 index 00000000..99eeb9b6 --- /dev/null +++ b/python_versions.json @@ -0,0 +1 @@ +["3.11", "3.12"] \ No newline at end of file diff --git a/setup.py b/setup.py index 55e792ff..723c4184 100644 --- a/setup.py +++ b/setup.py @@ -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") From 782c2e913e5b6ecdb2ebc4a69ded57a006aef896 Mon Sep 17 00:00:00 2001 From: Steve Bachmeier Date: Mon, 6 Jan 2025 13:16:37 -0800 Subject: [PATCH 2/5] automatically update README with supported py versions --- .github/workflows/update_readme.yml | 33 +++++++++++++++++++++++++++++ README.rst | 2 +- update_readme.py | 32 ++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/update_readme.yml create mode 100644 update_readme.py diff --git a/.github/workflows/update_readme.yml b/.github/workflows/update_readme.yml new file mode 100644 index 00000000..212ef5d0 --- /dev/null +++ b/.github/workflows/update_readme.yml @@ -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 "action@github.com" + 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 }} \ No newline at end of file diff --git a/README.rst b/README.rst index 5a3b4d46..e6c3d2ae 100644 --- a/README.rst +++ b/README.rst @@ -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: diff --git a/update_readme.py b/update_readme.py new file mode 100644 index 00000000..5ee52e0d --- /dev/null +++ b/update_readme.py @@ -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) From e88d6c301dda4b942136eb5a641bf13aff467c35 Mon Sep 17 00:00:00 2001 From: Steve Bachmeier Date: Mon, 6 Jan 2025 13:32:45 -0800 Subject: [PATCH 3/5] auto-generate github action build matrix --- .github/workflows/build.yml | 16 +++++++++++++++- README.rst | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 055fcfde..faed63ad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 }} diff --git a/README.rst b/README.rst index e6c3d2ae..117a9f82 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,7 @@ entity resolution (ER) pipelines. .. _python_support: -**Supported Python versions: 3.11, 3.12** +**Supported Python versions: 3.1, 3.2** .. _end_python_support: From f9ca85a10cbc23ddbf4cb55b65848839bccdadcb Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 6 Jan 2025 21:34:21 +0000 Subject: [PATCH 4/5] update README with supported Python versions --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 117a9f82..e6c3d2ae 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,7 @@ entity resolution (ER) pipelines. .. _python_support: -**Supported Python versions: 3.1, 3.2** +**Supported Python versions: 3.11, 3.12** .. _end_python_support: From 1cc10bf84435466e1ca9e6525195c7eebf9e47d3 Mon Sep 17 00:00:00 2001 From: Steve Bachmeier Date: Mon, 6 Jan 2025 13:43:33 -0800 Subject: [PATCH 5/5] changelog --- CHANGELOG.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a21f9c34..8805e631 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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