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

support PEP517 #24

Merged
merged 3 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .github/test_files/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# THIS IS A TEST FILE

[metadata]
name = test-project
version = attr: .__version__
description = This is a test project
22 changes: 18 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
test-stage-1:
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
pep517: [true, false]
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand Down Expand Up @@ -64,11 +67,15 @@ jobs:
assert_equal "$HEAD_REF" 'prepare-9.2.3'
assert_equal "$( git branch --show-current )" 'prepare-9.2.3'

- name: Setup mock __init__.py, setup.py & changelog files
- name: Setup mock project files
run: |
cp .github/test_files/__init__.py ./__init__.py
cp .github/test_files/setup.py ./setup.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

echo "[command]git add ."; git add .
echo "[command]git commit"
Expand All @@ -88,8 +95,15 @@ jobs:
from __init__ import __version__
assert __version__ == '9.2.3', f'::error:: assert version {__version__} == 9.2.3'
"
setup_py_version='${{ steps.set-package-version.outputs.setup-py-version }}'
assert_equal "$setup_py_version" '1!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"
# Check changes to init file are staged
exact_grep "M __init__.py" <(git status -s)

Expand Down
19 changes: 14 additions & 5 deletions build-python-package/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ inputs:
runs:
using: composite
steps:
- name: Install dependencies
shell: bash
run: python3 -m pip install wheel

- name: Build
shell: bash
run: python3 setup.py bdist_wheel sdist
run: |
if [[ -f setup.py ]]; then
# old style setup.py project
# (must manually install build dependencies)
echo "setup.py detected"
python3 -m pip install wheel
python3 setup.py bdist_wheel sdist
oliver-sanders marked this conversation as resolved.
Show resolved Hide resolved
else
# PEP517 project
# (must install a builder, this installs build deps for us)
echo "PEP 517 project detected"
python3 -m pip install build
python3 -m build
oliver-sanders marked this conversation as resolved.
Show resolved Hide resolved
fi
28 changes: 19 additions & 9 deletions stage-1/set-python-package-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ inputs:
required: false
default: true
outputs:
setup-py-version:
package-version:
description: Version number as outputted by setup.py (might be different from __init__.py, e.g. if epoch prefixed)
value: ${{ steps.get-setup-py-version.outputs.version }}
value: ${{ steps.get-package-version.outputs.version }}
runs:
using: composite
steps:
Expand Down Expand Up @@ -53,21 +53,31 @@ runs:
git add "$INIT_FILE"
fi

- name: Get setup.py version
- name: Get package version
# Might differ slightly from __init__.py, e.g. if epoch prefixed
id: get-setup-py-version
id: get-package-version
shell: bash
run: |
setup_py_version=$( python setup.py --version )
if [[ -f setup.py ]]; then
# get version from the setup.py for pre PEP517 projects
echo "setup.py detected"
package_version=$( python setup.py --version )
oliver-sanders marked this conversation as resolved.
Show resolved Hide resolved
else
# shim to get the project version from a PEP517 project
echo "PEP 517 project detected"
echo 'from setuptools import setup; setup()' > setup.py
oliver-sanders marked this conversation as resolved.
Show resolved Hide resolved
package_version=$( python setup.py --version )
rm setup.py
fi
# Check version number is valid:
cmp_py_versions "$setup_py_version" "$setup_py_version"
echo "setup.py version: ${setup_py_version}"
echo "::set-output name=version::$setup_py_version"
cmp_py_versions "$package_version" "$package_version"
echo "package version: ${package_version}"
echo "::set-output name=version::$package_version"

- name: Check version doesn't already exist on PyPI.org
shell: bash
working-directory: ${{ github.action_path }}
env:
PYPI_PACKAGE_NAME: ${{ inputs.pypi-package-name }}
SETUP_PY_VERSION: ${{ steps.get-setup-py-version.outputs.version }}
SETUP_PY_VERSION: ${{ steps.get-package-version.outputs.version }}
run: node check-pypi.js
6 changes: 5 additions & 1 deletion stage-2/comment-on-pr/comment-on-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ You can still publish the dist to PyPI manually:

(Make sure you have commit \`${pr_event.merge_commit_sha}\` checked out)
\`\`\`shell
# Create the build
# Create the build (old style for setup.py projects)
python3 setup.py bdist_wheel sdist

# Create the build (PEP517)
python -m build

# Upload your build to PyPI
twine upload dist/*
\`\`\`
Expand Down