Skip to content

Commit

Permalink
feat: adopt maturin (#616)
Browse files Browse the repository at this point in the history
* feat: adopt maturin

Signed-off-by: Keming <[email protected]>

* fix ci install dependencies

Signed-off-by: Keming <[email protected]>

* fix ci install editable

Signed-off-by: Keming <[email protected]>

* rm all setuptools related code

Signed-off-by: Keming <[email protected]>

---------

Signed-off-by: Keming <[email protected]>
  • Loading branch information
kemingy authored Jan 9, 2025
1 parent 31acd81 commit 5968646
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 213 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ jobs:
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: 3.9
Expand Down Expand Up @@ -69,8 +67,6 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand All @@ -82,8 +78,7 @@ jobs:
toolchain: nightly
- name: Install components
run: |
python -m pip install --upgrade pip
rustup component add clippy
make install
- name: Test unit
run: |
make test_unit
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev,mixin]
make install
make dev
- name: Test
run: |
Expand Down
152 changes: 110 additions & 42 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -1,75 +1,143 @@
# This file added mautrin autogenerated ci file by maturin v1.8.1
# DO NOT OVERWRITE THIS FILE by `maturin generate-ci github` directly

name: PyPI Publish

on:
release:
types: [created]
workflow_dispatch:

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

permissions:
contents: read

jobs:
build:
name: "Build PyPI Package"
runs-on: ${{ matrix.os }}
timeout-minutes: 60
linux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
os: [ubuntu-latest, macos-13, macos-14]
platform:
- runner: ubuntu-22.04
target: x86_64
- runner: ubuntu-22.04
target: x86
- runner: ubuntu-22.04
target: aarch64
- runner: ubuntu-22.04
target: armv7
- runner: ubuntu-22.04
target: s390x
- runner: ubuntu-22.04
target: ppc64le
steps:
- uses: actions/checkout@v4
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist

musllinux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-22.04
target: x86_64
- runner: ubuntu-22.04
target: x86
- runner: ubuntu-22.04
target: aarch64
- runner: ubuntu-22.04
target: armv7
steps:
- uses: actions/checkout@v4
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
target: ${{ matrix.platform.target }}
args: --release --out dist
sccache: 'true'
manylinux: musllinux_1_2
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
python-version: 3.11
- name: Build
run: |
python -m pip install pipx
pipx run cibuildwheel
name: wheels-musllinux-${{ matrix.platform.target }}
path: dist

macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-13
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels_${{ github.event.release.tag_name }}_${{ matrix.os }}
retention-days: 1
path: ./wheelhouse/*.whl
name: wheels-macos-${{ matrix.platform.target }}
path: dist

publish:
name: "Publish PyPI Package"
sdist:
runs-on: ubuntu-latest
permissions:
id-token: write
needs: [build]
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
fetch-depth: 0
- uses: actions/setup-python@v5
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
python-version: 3.9
name: wheels-sdist
path: dist

release:
name: Release
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
needs: [linux, musllinux, macos, sdist]
permissions:
# Use to sign the release artifacts
id-token: write
# Used to upload release artifacts
contents: write
# Used to generate artifact attestation
attestations: write
steps:
- uses: actions/download-artifact@v4
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
pattern: wheels_${{ github.event.release.tag_name }}_*
merge-multiple: true
path: dist/
- name: Prepare PyPI package
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
python setup.py sdist
ls dist/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
subject-path: 'wheels-*/*'
- name: Publish to PyPI
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: PyO3/maturin-action@v1
with:
skip-existing: true
- name: Publish Crates
env:
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
run: |
cargo login $CRATES_TOKEN
cargo publish
command: upload
args: --non-interactive --skip-existing wheels-*/*

image:
name: "Build Docker Image"
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Set up Python
Expand All @@ -40,8 +38,7 @@ jobs:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev,doc,mixin]
make install
- name: Generate docs
run: |
cd docs && make html
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mosec"
version = "0.9.0"
version = "0.9.1"
authors = ["Keming <[email protected]>", "Zichen <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
11 changes: 0 additions & 11 deletions MANIFEST.in

This file was deleted.

19 changes: 6 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
.DEFAULT_GOAL:=dev

PY_SOURCE_FILES=mosec tests examples setup.py
PY_SOURCE_FILES=mosec tests examples
RUST_SOURCE_FILES=src/*

install:
pip install -e .[dev,doc,mixin]
pip install -r requirements/dev.txt -r requirements/mixin.txt -r requirements/doc.txt
pre-commit install
rustup toolchain install nightly
rustup component add rustfmt --toolchain nightly
rustup component add rustfmt clippy --toolchain nightly

dev:
cargo build
@mkdir -p mosec/bin
@cp ./target/debug/mosec mosec/bin/mosec
pip install -e .[dev]
pip install -e .

test: dev
@pip install -q -r requirements/mixin.txt
Expand Down Expand Up @@ -48,15 +45,11 @@ doc:
clean:
@cargo clean
@-rm -rf build/ dist/ .eggs/ site/ *.egg-info .pytest_cache .mypy_cache .ruff_cache
@-rm -rf mosec/bin/
@-find . -name '*.pyc' -type f -exec rm -rf {} +
@-find . -name '__pycache__' -exec rm -rf {} +

package: clean
PRODUCTION_MODE=yes python setup.py bdist_wheel

cross_compile: clean
cibuildwheel --platform linux
maturin build --release --out dist

publish: package
twine upload dist/*
Expand All @@ -78,7 +71,7 @@ semantic_lint:
@cargo clippy -- -D warnings

version:
@python -m setuptools_scm
@cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "mosec") | .version'

add_license:
@addlicense -c "MOSEC Authors" **/*.py **/*.rs **/**/*.py
Expand Down
7 changes: 0 additions & 7 deletions mosec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
from mosec.server import Server
from mosec.worker import SSEWorker, Worker

try:
from mosec._version import __version__ # type: ignore
except ImportError:
from setuptools_scm import get_version # type: ignore

__version__ = get_version(root="..", relative_to=__file__)

__all__ = [
"ClientError",
"DecodingError",
Expand Down
Loading

0 comments on commit 5968646

Please sign in to comment.