Skip to content

Commit

Permalink
Fix set-python-package-version for Python 3.12 (#61)
Browse files Browse the repository at this point in the history
Add pyproject.toml example to tests
  • Loading branch information
MetRonnie committed Oct 27, 2023
1 parent 920e17b commit 8e7e442
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/test_files/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# THIS IS A TEST FILE

__version__ = "2.0.2"

FULL_VERSION = f"1!{__version__}"
15 changes: 15 additions & 0 deletions .github/test_files/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# THIS IS A TEST FILE

[project]
name = "test-project"
description = "This is a test project"
dynamic = ["version"]

[tool.setuptools]
platforms = ["any"]

[tool.setuptools.dynamic]
version = {attr = ".FULL_VERSION"}

[tool.setuptools.packages.find]
include = ["*"]
5 changes: 4 additions & 1 deletion .github/test_files/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

[metadata]
name = test-project
version = attr: .__version__
version = attr: .FULL_VERSION
description = This is a test project

[options]
packages = find_namespace:
17 changes: 3 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
timeout-minutes: 5
strategy:
matrix:
pep517: [true, false]
project-file: ['setup.py', 'setup.cfg', 'pyproject.toml']
steps:
- name: Checkout repo
uses: actions/checkout@v4
Expand Down Expand Up @@ -86,11 +86,7 @@ jobs:
run: |
cp .github/test_files/__init__.py ./__init__.py
cp .github/test_files/CHANGES.md ./CHANGES.md
if ${{ matrix.pep517 }}; then
cp .github/test_files/setup.cfg ./setup.cfg
else
cp .github/test_files/setup.py ./setup.py
fi
cp .github/test_files/${{ matrix.project-file }} ./${{ matrix.project-file }}
echo "[command]git add ."; git add .
echo "[command]git commit"
Expand All @@ -111,14 +107,7 @@ jobs:
assert __version__ == '9.2.3', f'::error:: assert version {__version__} == 9.2.3'
"
package_version='${{ steps.set-package-version.outputs.package-version }}'
# In setup.py projects, the __init__.py __version__ may be different to the setup.py version
# but in PEP 517 projects, the setup.cfg version will be the same as __init__.py __version__
if ${{ matrix.pep517 }}; then
expected_version="9.2.3"
else
expected_version="1!9.2.3"
fi
assert_equal "$package_version" "$expected_version"
assert_equal "$package_version" "1!9.2.3"
# Check changes to init file are staged
exact_grep "M __init__.py" <(git status -s)
Expand Down
6 changes: 2 additions & 4 deletions stage-1/set-python-package-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ runs:
- name: Install utils
shell: bash
run: |
python3 -m pip install -q packaging
python3 -m pip install -q setuptools packaging
echo "${{ github.action_path }}/../../bin" >> $GITHUB_PATH # Note: this persists in the workflow after the action is called
- name: Update version in __init__.py
Expand Down Expand Up @@ -65,9 +65,7 @@ runs:
else
# shim to get the project version from a PEP517 project
echo "PEP 517 project detected"
echo 'from setuptools import setup; setup()' > setup.py
package_version=$( python setup.py --version )
rm setup.py
package_version=$( python -c 'from setuptools import setup; setup()' --version )
fi
# Check version number is valid:
cmp_py_versions "$package_version" "$package_version"
Expand Down

0 comments on commit 8e7e442

Please sign in to comment.