Skip to content

Commit

Permalink
refactor(lib): go back to monorepo with 2 packages (#81)
Browse files Browse the repository at this point in the history
* refactor(lib): go back to monorepo with 2 packages

* fix: README

* put DiffeRT in a subfolder

* wip: ci

* fix

* fixes

* pytest fix

* some other fixes

* fix(docs): correctly escape underscore and other fixes

* fix(ci): msrv and others

* fix(ci): pytest benchmarks

* fix(docs): update

* fix(ci): lint

* fix(ci): publishing

* fix(ci): lint

* up

* run...

* format
  • Loading branch information
jeertmans authored May 2, 2024
1 parent 410191b commit 80c2529
Show file tree
Hide file tree
Showing 120 changed files with 1,805 additions and 4,373 deletions.
21 changes: 13 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,28 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: '3.11'
cache: true
- name: Setup Rye
if: matrix.os != 'windows-latest'
env:
RYE_INSTALL_OPTION: --yes
run: |
curl -sSf https://rye-up.com/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
- name: Configure Rye
shell: bash
run: rye config --set-bool behavior.use-uv=true

- name: Install Rust nightly
uses: dtolnay/rust-toolchain@nightly
with:
components: clippy,rustfmt

- name: Install dependencies
run: |
pdm install -G test,github-action
run: rye sync

- name: Run pre-commit hooks
uses: pre-commit/action@v3.0.1
run: rye run pre-commit run --all-files

- name: Apply fixes when present
uses: pre-commit-ci/lite-action@v1.0.2
Expand Down
57 changes: 49 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Python Package
name: Publish Python Packages
on:
pull_request:
branches:
Expand All @@ -15,6 +15,7 @@ permissions:

jobs:
linux:
name: Build Linux-${{ matrix.target}} wheels for differt-core
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -35,14 +36,16 @@ jobs:
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
working-directory: differt-core

- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.target }}
name: core-wheels-linux-${{ matrix.target }}
path: dist

windows:
name: Build Windows-${{ matrix.target}} wheels for differt-core
runs-on: windows-latest
strategy:
matrix:
Expand All @@ -63,14 +66,16 @@ jobs:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
working-directory: differt-core

- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.target }}
name: core-wheels-windows-${{ matrix.target }}
path: dist

macos:
name: Build macOS-${{ matrix.target }} wheels for differt-core
runs-on: macos-latest
strategy:
matrix:
Expand All @@ -90,14 +95,16 @@ jobs:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
working-directory: differt-core

- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.target }}
name: core-wheels-macos-${{ matrix.target }}
path: dist

sdist:
name: Build sdist for differt-core
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -108,15 +115,16 @@ jobs:
with:
command: sdist
args: --out dist
working-directory: differt-core

- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
name: core-wheels-sdist
path: dist

release:
name: Release
release-core:
name: Release differt-core
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs: [linux, windows, macos, sdist]
Expand All @@ -131,4 +139,37 @@ jobs:
uses: PyO3/maturin-action@v1
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
args: --non-interactive --skip-existing core-wheels-*/*

build-and-release:
name: Build and release differt
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Rye
env:
RYE_INSTALL_OPTION: --yes
run: |
curl -sSf https://rye-up.com/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
- name: Configure Rye
run: rye config --set-bool behavior.use-uv=true

- name: Build package
run: rye build -p differt

- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: differt-wheels-and-sdist
path: dist

- name: Publish to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 3 additions & 0 deletions .github/workflows/rustmsrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:

jobs:
msrv_check:
defaults:
run:
working-directory: differt-core
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
91 changes: 57 additions & 34 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Rye
if: matrix.os != 'windows-latest'
env:
RYE_TOOLCHAIN_VERSION: ${{ matrix.pyversion}}
RYE_INSTALL_OPTION: --yes
run: |
curl -sSf https://rye-up.com/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
# Stolen from https://github.com/bluss/pyproject-local-kernel/blob/2b641290694adc998fb6bceea58d3737523a68b7/.github/workflows/ci.yaml
- name: Install Rye (Windows)
if: matrix.os == 'windows-latest'
shell: bash
run: |
C:/msys64/usr/bin/wget.exe -q 'https://github.com/astral-sh/rye/releases/latest/download/rye-x86_64-windows.exe' -O rye-x86_64-windows.exe
./rye-x86_64-windows.exe self install --toolchain-version ${{ matrix.pyversion }} --modify-path -y
echo "$HOME\\.rye\\shims" >> $GITHUB_PATH
- name: Configure Rye
shell: bash
run: |
rye config --set-bool behavior.use-uv=true
rye pin ${{ matrix.pyversion }}
- name: Install Linux dependencies
if: matrix.os == 'ubuntu-latest'
run: |
Expand All @@ -35,34 +59,30 @@ jobs:
if: matrix.os == 'windows-latest'
uses: ssciwr/setup-mesa-dist-win@v2

- name: Install PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ matrix.pyversion }}
cache: true

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Install dependencies
run: |
pdm install -G test,github-action
shell: bash
run: rye sync

- name: Run Pytest
if: matrix.os != 'ubuntu-latest' || matrix.pyversion != '3.12'
shell: bash
run: |
pdm run pytest -n auto
rye run pytest -n auto
- name: Run pytest and coverage
- name: Run pytest and coverage for differt
if: matrix.os == 'ubuntu-latest' && matrix.pyversion == '3.12'
run: pdm run pytest --cov-report xml --cov=differt tests/
run: rye run pytest --cov-report xml --cov=differt differt/tests/

- name: Upload to codecov.io
if: matrix.os == 'ubuntu-latest' && matrix.pyversion == '3.12'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

cargo-test:
strategy:
fail-fast: false
Expand All @@ -87,6 +107,7 @@ jobs:
- name: Run Cargo test
run: |
cargo test
python-benchmark:
runs-on: ubuntu-latest
permissions:
Expand All @@ -95,30 +116,30 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install PDM
uses: pdm-project/setup-pdm@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: true
cache: pip
cache-dependency-path: requirements-dev.lock

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools

- name: Install dependencies
run: |
pdm install -G test,github-action
run: pip install -r requirements-dev.lock

- name: Run Benchmarks on changes
run: pdm run pytest --benchmark-only --benchmark-save=changes tests/benchmarks
run: pytest --benchmark-only --benchmark-save=changes differt-core/tests/benchmarks

- name: Build wheel with profiling profile
uses: PyO3/maturin-action@v1
with:
args: >
--release
--out pgo-wheel
working-directory: differt-core
env:
RUSTFLAGS: -Cprofile-generate=${{ github.workspace }}/profdata

Expand All @@ -128,9 +149,9 @@ jobs:

- name: Generate profile data
run: |
pdm run python -m ensurepip
pdm run python -m pip install differt --no-index --no-deps --find-links pgo-wheel --force-reinstall
pdm run pytest --benchmark-only tests/benchmarks
python -m ensurepip
python -m pip install differt --no-index --no-deps --find-links pgo-wheel --force-reinstall
pytest --benchmark-only differt-core/tests/benchmarks
rustup run stable bash -c 'echo LLVM_PROFDATA=$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/${{ env.RUST_HOST }}/bin/llvm-profdata >> "$GITHUB_ENV"'
- name: Merge GO data
Expand All @@ -142,13 +163,14 @@ jobs:
args: >
--release
--out opt-wheel
working-directory: differt-core
env:
RUSTFLAGS: -Cprofile-use=${{ github.workspace }}/merged.profdata

- name: Run Benchmarks on changes with PGO-optimized wheel
run: |
pdm run python -m pip install differt --no-index --no-deps --find-links opt-wheel --force-reinstall
pdm run pytest --benchmark-only --benchmark-save=pgo tests/benchmarks
python -m pip install differt --no-index --no-deps --find-links opt-wheel --force-reinstall
pytest --benchmark-only --benchmark-save=pgo differt-core/tests/benchmarks
- name: Checkout base branch
uses: actions/checkout@v4
Expand All @@ -157,25 +179,25 @@ jobs:
clean: false

- name: Install dependencies (before changes)
run: |
pdm install -G test,github-action
run: pip install -r requirements-dev.lock

- name: Build wheel before changes
uses: PyO3/maturin-action@v1
with:
args: >
--release
--out dist
working-directory: differt-core

- name: Run Benchmarks before changes
run: |
pdm run python -m pip install differt --no-index --no-deps --find-links dist --force-reinstall
pdm run pytest --benchmark-only --benchmark-save=before tests/benchmarks
python -m pip install differt --no-index --no-deps --find-links dist --force-reinstall
pytest --benchmark-only --benchmark-save=before differt-core/tests/benchmarks
- name: Compare benchmarks
run: |
echo 'results<<EOF' >> $GITHUB_OUTPUT
pdm run pytest-benchmark compare --group-by=group --columns="mean,stddev,ops" >> $GITHUB_OUTPUT
pytest-benchmark compare --group-by=group --columns="mean,stddev,ops" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
id: compare

Expand All @@ -199,6 +221,7 @@ jobs:
echo '```' >> $GITHUB_STEP_SUMMARY
echo '${{ steps.compare.outputs.results }}' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
rust-benchmark:
runs-on: ubuntu-latest
permissions:
Expand Down Expand Up @@ -260,23 +283,23 @@ jobs:
echo '```' >> $GITHUB_STEP_SUMMARY
echo '${{ steps.compare.outputs.results }}' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
linkcheck-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install PDM
uses: pdm-project/setup-pdm@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: true
cache: pip
cache-dependency-path: requirements-dev.lock

- name: Install dependencies (before changes)
run: |
pdm install -G docs,github-action
- name: Install dependencies
run: pip install -r requirements-dev.lock

- name: Check links in documentation
run: |
cd docs
NB_OFF=1 pdm run make linkcheck
NB_OFF=1 make linkcheck
Loading

0 comments on commit 80c2529

Please sign in to comment.