-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major overhaul of build system: - Migration to pyproject.toml with meson. - Migrated away from versioneer to custom version.py script. - Migrated away from miniconda/tox-conda to "regular" python install for unit tests - Migrated CI workflows to use cibuildwheel for all platforms - Move utilities related to build into <root>/build_utils. - Updated testing workflows to add appropriate compilers. - Enable testing on Intel Mac as well as ARM - Update docs on building with (and without) C extension --------- Co-authored-by: Adam J. Jackson <[email protected]>
- Loading branch information
Showing
19 changed files
with
318 additions
and
3,199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,64 +14,88 @@ jobs: | |
include: | ||
- os: windows-latest | ||
wheelname: win | ||
cibw_archs: "AMD64" | ||
- os: macos-13 | ||
wheelname: macos-intel | ||
wheelname: macosx | ||
cibw_archs: "x86_64" | ||
- os: macos-latest | ||
wheelname: macos-arm | ||
wheelname: macosx | ||
cibw_archs: "arm64" | ||
- os: ubuntu-latest | ||
wheelname: manylinux | ||
cibw_archs: "x86_64" | ||
- python-version: '3.10' | ||
manylinux-version-tag: cp310 | ||
version-tag: cp310 | ||
- python-version: '3.11' | ||
manylinux-version-tag: cp311 | ||
- python-version: '3.11' | ||
manylinux-version-tag: cp311 | ||
version-tag: cp311 | ||
- python-version: '3.12' | ||
version-tag: cp312 | ||
fail-fast: false | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Ensure tags are fetched for versioning | ||
- name: Setup Python ${{ matrix.python-version }} with Conda | ||
uses: conda-incubator/setup-miniconda@v3 | ||
- name: Setup Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
channels: conda-forge,defaults | ||
channel-priority: true | ||
- name: Update Python pip, wheel, and twine | ||
shell: bash -l {0} | ||
run: | | ||
python -m pip install --upgrade pip wheel twine | ||
- name: Install llvm on Macos | ||
if: startsWith(matrix.os, 'macos') | ||
run: brew install llvm | ||
|
||
- name: Build Python wheel | ||
shell: bash -l {0} | ||
env: | ||
# Homebrew location is different on Intel Mac | ||
LLVM_DIR: ${{ (matrix.os == 'macos-13') && '/usr/local/opt/llvm' || '/opt/homebrew/opt/llvm' }} | ||
run: | | ||
brew install llvm | ||
echo CC="${LLVM_DIR}/bin/clang" >> $GITHUB_ENV | ||
echo LDFLAGS="-L${LLVM_DIR}/lib $LDFLAGS" >> $GITHUB_ENV | ||
echo CPPFLAGS="-I${LLVM_DIR}/include $CPPFLAGS" >> $GITHUB_ENV | ||
if: matrix.os != 'ubuntu-latest' | ||
- name: Windows - find MSVC and set environment variables | ||
if: startsWith(matrix.os, 'windows') | ||
shell: bash -l {0} | ||
env: | ||
NUMPY_VERSION: 2.0 | ||
MSVC_PREFIX: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC' | ||
run: | | ||
# Build against lowest required Numpy version | ||
python -m pip install numpy==${NUMPY_VERSION} | ||
python -m pip wheel . -w wheelhouse --no-deps | ||
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 | ||
- name: Build manylinux Python wheel | ||
if: matrix.os == 'ubuntu-latest' | ||
uses: pypa/[email protected] | ||
CC_LD="$MSVC_PREFIX\\$MSVC_BIN\\link.exe" | ||
echo "CC_LD: $CC_LD" | ||
echo "CC_LD=$CC_LD" >> $GITHUB_ENV | ||
- name: Update Python pip, build, wheel, and twine | ||
shell: bash -l {0} | ||
run: | | ||
python -m pip install --upgrade pip build wheel twine | ||
- name: Build wheels | ||
uses: pypa/[email protected] | ||
env: | ||
CIBW_BUILD: ${{ matrix.manylinux-version-tag}}-manylinux* | ||
CIBW_BEFORE_BUILD: python -mpip install numpy==2.0 | ||
CIBW_ARCHS: x86_64 | ||
CIBW_BUILD_FRONTEND: build | ||
CIBW_BUILD: ${{ matrix.version-tag }}-* | ||
CIBW_ARCHS: ${{ matrix.cibw_archs }} | ||
CIBW_SKIP: "*-musllinux*" | ||
|
||
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 | ||
|
||
with: | ||
output-dir: wheelhouse | ||
|
||
- name: Create source distribution | ||
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' | ||
shell: bash -l {0} | ||
run: | | ||
python setup.py sdist | ||
python -m build --sdist . | ||
- name: Upload source dist as build artifact | ||
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' && github.event_name == 'release' | ||
|
@@ -83,8 +107,9 @@ jobs: | |
- name: Upload wheels as build artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: wheel-${{ matrix.wheelname }}-${{ matrix.python-version }} | ||
path: wheelhouse/*-${{ matrix.wheelname }}*.whl | ||
name: wheel-${{ matrix.wheelname }}-${{ matrix.python-version }}-${{ matrix.cibw_archs }} | ||
path: wheelhouse/*-${{ matrix.wheelname }}*_${{ matrix.cibw_archs }}.whl | ||
if-no-files-found: error | ||
|
||
publish: | ||
if: github.event_name == 'release' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""Script to compute version from git tags. | ||
Provides 3 means of updating: | ||
- python version.py | ||
Print computed version to stdout | ||
- python version.py --dump | ||
Update version in `euphonic/version.py` | ||
- python version.py --dist | ||
Update versions in both `euphonic/version.py` and in meson sdist build directory. | ||
""" | ||
|
||
from pathlib import Path | ||
import subprocess | ||
import sys | ||
import os | ||
|
||
if new_dir := os.getenv("MESON_SOURCE_ROOT"): | ||
os.chdir(new_dir) | ||
|
||
gits = ["git"] | ||
if sys.platform == "win32": | ||
gits += ["git.cmd", "git.exe"] | ||
|
||
match sys.argv: | ||
case [_, "--dist"]: | ||
COMMAND = "dist" | ||
case [_, "--dump"]: | ||
COMMAND = "dump" | ||
case [_]: | ||
COMMAND = "print" | ||
|
||
version_file = Path(__file__).parent.parent / "euphonic" / "version.py" | ||
|
||
for gitcmd in gits: | ||
try: | ||
proc = subprocess.run([gitcmd, "describe", "--tags", "--dirty"], | ||
capture_output=True, check=True, text=True) | ||
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) | ||
continue | ||
|
||
version, *dirty = proc.stdout.strip().split("-") | ||
if dirty: | ||
version += f"+{dirty[0]}.{dirty[1]}{'.dirty' if len(dirty) > 2 and COMMAND != 'dump' else ''}" | ||
break | ||
|
||
else: # Can't use git | ||
version = version_file.read_text().split("=")[1].strip('"\n ') | ||
|
||
match COMMAND: | ||
case "dist": | ||
version_file.write_text(f'__version__ = "{version}"', encoding="utf-8") | ||
dist_path = os.getenv("MESON_DIST_ROOT") | ||
dist_version_file = Path(dist_path) / "euphonic" / "version.py" | ||
dist_version_file.parent.mkdir(parents=True, exist_ok=True) | ||
dist_version_file.write_text(f'__version__ = "{version}"', encoding="utf-8") | ||
|
||
case "dump": | ||
version_file.write_text(f'__version__ = "{version}"', encoding="utf-8") | ||
|
||
case "print": | ||
print(version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "@VERSION@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.