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/.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/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 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/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") 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)