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

Fix and test sdist builds; reduce sdist size #337

Merged
merged 22 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 20 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
5 changes: 3 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Added by versioneer
euphonic/_version.py export-subst
.github/** export-ignore
tests_and_analysis/** export-ignore
tox.ini export-ignore
100 changes: 83 additions & 17 deletions .github/workflows/build_upload_pypi_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:

jobs:
build:
build-wheels:
strategy:
matrix:
os: [windows-latest, macos-13, macos-latest, ubuntu-latest]
Expand All @@ -33,13 +33,14 @@ jobs:
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensure tags are fetched for versioning
- name: Checkout project (for test files)
uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install llvm on Macos
if: startsWith(matrix.os, 'macos')
shell: bash -l {0}
Expand Down Expand Up @@ -75,7 +76,7 @@ jobs:
run: |
python -m pip install --upgrade pip build wheel twine

- name: Build wheels
- name: Build wheels from git checkout
uses: pypa/[email protected]
env:
CIBW_BUILD_FRONTEND: build
Expand All @@ -86,34 +87,99 @@ jobs:
CIBW_REPAIR_WHEEL_COMMAND_MACOS: ""

CIBW_TEST_EXTRAS: "test,brille,phonopy_reader,matplotlib"
CIBW_TEST_COMMAND: python {package}/tests_and_analysis/test/run_tests.py
CIBW_TEST_COMMAND: "python {package}/tests_and_analysis/test/run_tests.py"

with:
output-dir: wheelhouse

- name: Upload wheels as build artifacts
uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.wheelname }}-${{ matrix.python-version }}-${{ matrix.cibw_archs }}
path: wheelhouse/*-${{ matrix.wheelname }}*_${{ matrix.cibw_archs }}.whl
if-no-files-found: error

build-sdist:
name: Build sdist
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensure tags are fetched for versioning

- name: Create source distribution
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
shell: bash -l {0}
run: |
python -m build --sdist .
pipx run build --sdist .

- name: Upload source dist as build artifact
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' && github.event_name == 'release'
uses: actions/upload-artifact@v4
with:
name: python-source-distribution
path: dist
path: dist/
if-no-files-found: error

- name: Upload wheels as build artifacts
uses: actions/upload-artifact@v4
test-sdist:
needs: build-sdist
name: Test build from sdist on Windows
runs-on: windows-latest
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
name: wheel-${{ matrix.wheelname }}-${{ matrix.python-version }}-${{ matrix.cibw_archs }}
path: wheelhouse/*-${{ matrix.wheelname }}*_${{ matrix.cibw_archs }}.whl
if-no-files-found: error
python-version: 3.11

- name: Find MSVC and set environment variables
shell: bash -l {0}
env:
MSVC_PREFIX: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC'
run: |
echo "Available MSVC installations:"
ls "$MSVC_PREFIX"

MSVC_BIN=$(ls "$MSVC_PREFIX" | tail -n 1)\\bin\\HostX64\\x64
CC="$MSVC_PREFIX\\$MSVC_BIN\\cl.exe"
echo "CC: $CC"
echo "CC=$CC" >> $GITHUB_ENV

CC_LD="$MSVC_PREFIX\\$MSVC_BIN\\link.exe"
echo "CC_LD: $CC_LD"
echo "CC_LD=$CC_LD" >> $GITHUB_ENV

- name: Download sdist
uses: actions/download-artifact@v4
with:
path: dist/
merge-multiple: true

- name: List downloaded sdist
run: |
ls -R dist/

- name: Update pip
shell: bash -l {0}
run: |
python -m pip install --upgrade pip

- name: Install from sdist
shell: bash -l {0}
run: python -m pip install $(find dist -name 'euphonic-*.tar.gz')[matplotlib,phonopy_reader,brille,test]
oerc0122 marked this conversation as resolved.
Show resolved Hide resolved

- name: Checkout repository (for tests and test data)
uses: actions/checkout@v4

- name: Delete source (to ensure we are testing INSTALLED version)
shell: bash -l {0}
run: rm -rf euphonic

- name: run tests
shell: bash -l {0}
run: python tests_and_analysis/test/run_tests.py --report

publish:
if: github.event_name == 'release'
needs: build
needs: [build-wheels,test-sdist]
name: Upload release to PyPI
runs-on: ubuntu-latest
environment:
Expand All @@ -134,7 +200,7 @@ jobs:
merge-multiple: true

- name: List Files
run: ls -R
run: ls -R dist/

- name: Upload wheels to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
`Unreleased <https://github.com/pace-neutrons/Euphonic/compare/v1.4.0...HEAD>`_
-------------------------------------------------------------------------------

- Bug fixes

- Fixed a bug in the version numbering mechanism affecting source
builds on Windows and environments where Git is unavailable

- Maintenance

- Source builds automatically tested on Windows as part of
build/deployment process

`v1.4.0 <https://github.com/pace-neutrons/Euphonic/compare/v1.3.2...v1.4.0>`_
-----------------------------------------------------------------------------

Expand Down
10 changes: 8 additions & 2 deletions build_utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@

for gitcmd in gits:
try:
print(f"Trying {gitcmd} ...", file=sys.stderr)
proc = subprocess.run([gitcmd, "describe", "--tags", "--dirty"],
capture_output=True, check=True, text=True)
except subprocess.CalledProcessError as err:
except FileNotFoundError as err:
print(f"Tried {gitcmd}, File Not Found", file=sys.stderr)
continue

except (subprocess.CalledProcessError) as err:
print(f"Tried {gitcmd}, returned: {err}", file=sys.stderr)
print(f"Stdout: '{err.stdout.strip()}'", file=sys.stderr)
print(f"Stdout: '{err.stderr.strip()}'", file=sys.stderr)
print(f"Stderr: '{err.stderr.strip()}'", file=sys.stderr)
continue

version, *dirty = proc.stdout.strip().split("-")
Expand All @@ -53,6 +58,7 @@
break

else: # Can't use git
print("All git implementations failed, reading version file", file=sys.stderr)
version = version_file.read_text().split("=")[1].strip('"\n ')

match COMMAND:
Expand Down
3 changes: 1 addition & 2 deletions tests_and_analysis/tox_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
mock
pytest~=7.0
pytest==7.*
coverage
pytest-mock
pytest-lazy-fixture
pytest-xvfb
python-slugify
toolz
wheel==0.43
setuptools==71.1.0
Loading