Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ci: Merge sdist and wheel building workflows #25473

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

Merged
merged 1 commit into from
Jun 1, 2023
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
74 changes: 0 additions & 74 deletions .github/workflows/cibuildsdist.yml

This file was deleted.

95 changes: 78 additions & 17 deletions .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,59 @@ permissions:
contents: read

jobs:
build_sdist:
if: |
github.event_name == 'push' ||
github.event_name == 'pull_request' && (
(
github.event.action == 'labeled' &&
github.event.label.name == 'CI: Run cibuildwheel'
) ||
contains(github.event.pull_request.labels.*.name,
'CI: Run cibuildwheel')
)
name: Build sdist
runs-on: ubuntu-20.04
outputs:
SDIST_NAME: ${{ steps.sdist.outputs.SDIST_NAME }}

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v4
name: Install Python
with:
python-version: 3.9

# Something changed somewhere that prevents the downloaded-at-build-time
# licenses from being included in built wheels, so pre-download them so
# that they exist before the build and are included.
- name: Pre-download bundled licenses
run: >
curl -Lo LICENSE/LICENSE_QHULL
https://github.com/qhull/qhull/raw/2020.2/COPYING.txt

- name: Install dependencies
run: python -m pip install build twine

- name: Build sdist
id: sdist
run: |
python -m build --sdist
python ci/export_sdist_name.py

- name: Check README rendering for PyPI
run: twine check dist/*

- name: Upload sdist result
uses: actions/upload-artifact@v3
with:
name: sdist
path: dist/*.tar.gz
if-no-files-found: error

build_wheels:
if: |
github.event_name == 'push' ||
Expand All @@ -30,21 +83,31 @@ jobs:
github.event.action == 'labeled' &&
github.event.label.name == 'CI: Run cibuildwheel'
) ||
contains(github.event.pull_request.labels.*.name, 'CI: Run cibuildwheel')
contains(github.event.pull_request.labels.*.name,
'CI: Run cibuildwheel')
)
needs: build_sdist
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
CIBW_BEFORE_BUILD: >-
pip install certifi oldest-supported-numpy &&
git clean -fxd build
rm -rf {package}/build
CIBW_BEFORE_BUILD_WINDOWS: >-
pip install certifi delvewheel oldest-supported-numpy &&
git clean -fxd build
rm -rf {package}/build
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: >-
delvewheel repair -w {dest_dir} {wheel}
CIBW_AFTER_BUILD: >-
twine check {wheel} &&
python {package}/ci/check_wheel_licenses.py {wheel}
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_SKIP: "*-musllinux*"
CIBW_TEST_COMMAND: >-
python {package}/ci/check_version_number.py
# Apple Silicon machines are not available for testing, so silence the
# warning from cibuildwheel. Remove the skip when they're available.
CIBW_TEST_SKIP: "*-macosx_arm64 *-macosx_universal2:arm64"
MACOSX_DEPLOYMENT_TARGET: "10.12"
MPL_DISABLE_FH4: "yes"
strategy:
Expand All @@ -66,47 +129,45 @@ jobs:
with:
platforms: arm64

- uses: actions/checkout@v3
- name: Download sdist
uses: actions/download-artifact@v3
with:
fetch-depth: 0

# Something changed somewhere that prevents the downloaded-at-build-time
# licenses from being included in built wheels, so pre-download them so
# that they exist before the build and are included.
- name: Pre-download bundled licenses
run: >
curl -Lo LICENSE/LICENSE_QHULL
https://github.com/qhull/qhull/raw/2020.2/COPYING.txt
name: sdist
path: dist/

- name: Build wheels for CPython 3.11
uses: pypa/[email protected]
with:
package-dir: dist/${{ needs.build_sdist.outputs.SDIST_NAME }}
env:
CIBW_BUILD: "cp311-*"
CIBW_ARCHS: ${{ matrix.cibw_archs }}

- name: Build wheels for CPython 3.10
uses: pypa/[email protected]
with:
package-dir: dist/${{ needs.build_sdist.outputs.SDIST_NAME }}
env:
CIBW_BUILD: "cp310-*"
CIBW_ARCHS: ${{ matrix.cibw_archs }}

- name: Build wheels for CPython 3.9
uses: pypa/[email protected]
with:
package-dir: dist/${{ needs.build_sdist.outputs.SDIST_NAME }}
env:
CIBW_BUILD: "cp39-*"
CIBW_ARCHS: ${{ matrix.cibw_archs }}

- name: Build wheels for PyPy
uses: pypa/[email protected]
with:
package-dir: dist/${{ needs.build_sdist.outputs.SDIST_NAME }}
env:
CIBW_BUILD: "pp39-*"
CIBW_ARCHS: ${{ matrix.cibw_archs }}
if: matrix.cibw_archs != 'aarch64'

- name: Validate that LICENSE files are included in wheels
run: |
python3 ./ci/check_wheel_licenses.py

- uses: actions/upload-artifact@v3
with:
name: wheels
Expand Down
8 changes: 2 additions & 6 deletions ci/check_version_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
$ pip install dist/matplotlib*.whl for wheel
$ ./ci/check_version_number.py
"""
import matplotlib

import sys

EXIT_SUCCESS = 0
EXIT_FAILURE = 1
import matplotlib


print(f"Version {matplotlib.__version__} installed")
if matplotlib.__version__[0] == "0":
sys.exit(EXIT_FAILURE)
sys.exit(EXIT_SUCCESS)
sys.exit("Version incorrectly starts with 0")
23 changes: 10 additions & 13 deletions ci/check_wheel_licenses.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
#!/usr/bin/env python3

"""
Check that all .whl files in the dist folder have the correct LICENSE files
included.
Check that all specified .whl files have the correct LICENSE files included.

To run:
$ python3 setup.py bdist_wheel
$ ./ci/check_wheel_licenses.py
$ python3 -m build --wheel
$ ./ci/check_wheel_licenses.py dist/*.whl
"""

from pathlib import Path
import sys
import zipfile

EXIT_SUCCESS = 0
EXIT_FAILURE = 1

if len(sys.argv) <= 1:
sys.exit('At least one wheel must be specified in command-line arguments.')

project_dir = Path(__file__).parent.resolve().parent
dist_dir = project_dir / 'dist'
license_dir = project_dir / 'LICENSE'

license_file_names = {path.name for path in sorted(license_dir.glob('*'))}
for wheel in dist_dir.glob('*.whl'):
for wheel in sys.argv[1:]:
print(f'Checking LICENSE files in: {wheel}')
with zipfile.ZipFile(wheel) as f:
wheel_license_file_names = {Path(path).name
for path in sorted(f.namelist())
if '.dist-info/LICENSE' in path}
if not (len(wheel_license_file_names) and
wheel_license_file_names.issuperset(license_file_names)):
print(f'LICENSE file(s) missing:\n'
f'{wheel_license_file_names} !=\n'
f'{license_file_names}')
sys.exit(EXIT_FAILURE)
sys.exit(EXIT_SUCCESS)
sys.exit(f'LICENSE file(s) missing:\n'
f'{wheel_license_file_names} !=\n'
f'{license_file_names}')
21 changes: 21 additions & 0 deletions ci/export_sdist_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3

"""
Determine the name of the sdist and export to GitHub output named SDIST_NAME.

To run:
$ python3 -m build --sdist
$ ./ci/determine_sdist_name.py
"""
import os
from pathlib import Path
import sys


paths = [p.name for p in Path("dist").glob("*.tar.gz")]
if len(paths) != 1:
sys.exit(f"Only a single sdist is supported, but found: {paths}")

print(paths[0])
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"SDIST_NAME={paths[0]}\n")
14 changes: 0 additions & 14 deletions ci/silence

This file was deleted.