Skip to content

Commit

Permalink
Move from maturin to setuptools-rust
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonxslays committed Dec 9, 2021
1 parent bb9f594 commit 7b1e2a4
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 110 deletions.
175 changes: 84 additions & 91 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
name: Pypi-release
name: PyPI-release

on:
push:
tags:
- v0.1.0
# release:
# types: [published]
release:
types: [published]

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Check version
- name: check project version
run: |
latest=$(git tag -l | tail -1)
cargo_v=$(grep -m 1 -oP 'version = "(.*)"' Cargo.toml | sed -rn 's/.*"(.*)"/v\1/p')
Expand All @@ -24,101 +21,97 @@ jobs:
fi
exit 0
linux:
runs-on: ubuntu-latest

build:
name: build python 3.${{ matrix.python-version }} on ${{ matrix.platform || matrix.os }}
needs:
- setup
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
os:
- ubuntu
- macos
- windows
python-version:
- '7'
- '9'
- '8'
- '10'
include:
- os: ubuntu
platform: linux
- os: windows
ls: dir

runs-on: ${{ format('{0}-latest', matrix.os) }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/checkout@v2

- name: Install rust stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: set up python
uses: actions/setup-python@v2
with:
python-version: "3.8"

- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: set up rust
if: matrix.os != 'ubuntu'
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Install maturin
run: pip install maturin
- name: install python dependencies
run: pip install -U setuptools wheel twine cibuildwheel

- name: Build wheel
run: maturin build --release -o dist --target x86_64-unknown-linux-gnu
- name: build sdist
if: matrix.os == 'ubuntu' && matrix.python-version == '8'
run: |
pip install -U setuptools-rust
python setup.py sdist
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: wheels
path: dist
- name: build ${{ matrix.platform || matrix.os }} binaries
run: cibuildwheel --output-dir dist
env:
CIBW_BUILD: 'cp3${{ matrix.python-version }}-*'
CIBW_SKIP: '*-win32 *-musllinux*i686'
CIBW_PLATFORM: ${{ matrix.platform || matrix.os }}
CIBW_ENVIRONMENT: 'PATH="$HOME/.cargo/bin:$PATH"'
CIBW_ENVIRONMENT_WINDOWS: 'PATH="$UserProfile\.cargo\bin;$PATH"'
CIBW_MANYLINUX_X86_64_IMAGE: 'manylinux2014'
CIBW_MANYLINUX_I686_IMAGE: 'manylinux2014'
CIBW_BEFORE_BUILD: >
pip install -U setuptools-rust &&
rustup default stable &&
rustup show
CIBW_BEFORE_BUILD_LINUX: >
yum install -y openssl-devel || apk add openssl-dev musl-dev &&
pip install -U setuptools-rust &&
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=minimal -y &&
rustup show
# linux:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - name: openssl?
# run: export OPENSSL_DIR=$(which openssl)
# - uses: messense/maturin-action@v1
# with:
# manylinux: 2014
# command: build
# args: --release -o dist
# - name: Upload wheels
# uses: actions/upload-artifact@v2
# with:
# name: wheels
# path: dist
- name: build windows 32bit binaries
if: matrix.os == 'windows'
run: cibuildwheel --output-dir dist
env:
CIBW_BUILD: 'cp3${{ matrix.python-version }}-win32'
CIBW_PLATFORM: windows
CIBW_ENVIRONMENT: 'PATH="$UserProfile\.cargo\bin;$PATH"'
CIBW_BEFORE_BUILD: >
pip install -U setuptools-rust &&
rustup toolchain install stable-i686-pc-windows-msvc &&
rustup default stable-i686-pc-windows-msvc &&
rustup override set stable-i686-pc-windows-msvc &&
rustup show
# windows:
# runs-on: windows-latest
# steps:
# - uses: actions/checkout@v2
# - uses: messense/maturin-action@v1
# with:
# command: build
# args: --release --no-sdist -o dist
# - name: Upload wheels
# uses: actions/upload-artifact@v2
# with:
# name: wheels
# path: dist
- name: list dist files
run: ${{ matrix.ls || 'ls -lh' }} dist/

# macos:
# runs-on: macos-latest
# steps:
# - uses: actions/checkout@v2
# - uses: messense/maturin-action@v1
# with:
# command: build
# args: --release --no-sdist -o dist --universal2
# - name: Upload wheels
# uses: actions/upload-artifact@v2
# with:
# name: wheels
# path: dist
- name: twine check
run: twine check dist/*

# release:
# name: Release
# runs-on: ubuntu-latest
# if: "startsWith(github.ref, 'refs/tags/')"
# needs: [ macos, windows, linux, setup ]
# steps:
# - uses: actions/download-artifact@v2
# with:
# name: wheels
# - uses: actions/setup-python@v2
# with:
# python-version: "3.9"
# - name: Publish to PyPI
# env:
# TWINE_USERNAME: __token__
# TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
# run: |
# pip install --upgrade twine
# twine upload --skip-existing *
- name: upload to pypi
if: startsWith(github.ref, 'refs/tags/')
run: twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.pypi_token }}
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include Cargo.toml
recursive-include src *
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ async def main() -> None:

print(f"Output:\n{response.run.output}")


if __name__ == "__main__":
asyncio.run(main())
```
Expand All @@ -95,7 +96,7 @@ async def main() -> None:
piston_rspy.File(
name="main.py",
content="for i in range(10): print(i)",
)
),
)
)

Expand All @@ -106,6 +107,7 @@ async def main() -> None:

print(f"Output:\n{response.run.output}")


if __name__ == "__main__":
asyncio.run(main())
```
Expand Down
24 changes: 6 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,18 @@ version = "0.1.0"
description = "Python bindings for piston_rs."
readme = "README.md"
documentation = "https://jonxslays.github.io/piston_rspy/piston_rspy/"
repository = "https://github.com/Jonxslays/piston_rspy"
url = "https://github.com/Jonxslays/piston_rspy"
requires-python = ">=3.7,<3.11"
classifiers = [
"Development Status :: 3 - Alpha",
"Framework :: AsyncIO",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Rust",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Software Development :: Libraries :: Python Modules",
"Typing :: Typed",
]

[tool.pyright]
typeCheckingMode = "strict"
include = ["piston_rspy.pyi"]
include = ["piston_rspy"]

[tool.black]
line-length = 99

[build-system]
requires = ["maturin>=0.12,<0.13"]
build-backend = "maturin"
# requires = ["maturin>=0.12,<0.13"]
# build-backend = "maturin"
requires = ["setuptools", "wheel", "setuptools-rust"]
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ black==21.11b1
maturin==0.12.2
pdoc3==0.10.0
pyright==0.0.13
setuptool_rust==1.1.2
44 changes: 44 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from setuptools import setup
from setuptools_rust import Binding, RustExtension # type: ignore


setup_requires = ["setuptools-rust>=0.9.2"]

with open("README.md") as r:
long_description = r.read()

setup(
name="piston_rspy",
version="0.1.0",
description="Python bindings for piston_rs.",
author="Jonxslays",
long_description=long_description,
long_description_content_type="text/markdown",
license="MIT",
url="https://github.com/Jonxslays/piston_rspy",
classifiers=[
"Development Status :: 3 - Alpha",
"Framework :: AsyncIO",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Rust",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Software Development :: Libraries :: Python Modules",
"Typing :: Typed",
],
rust_extensions=[
RustExtension(
"piston_rspy.piston_rspy", "Cargo.toml", binding=Binding.PyO3, # type: ignore
)
],
setup_requires=setup_requires,
include_package_data=True,
packages=["piston_rspy"],
zip_safe=False,
python_requires=">=3.7,<3.11",
)

0 comments on commit 7b1e2a4

Please sign in to comment.