Skip to content

Fix rustfst-python build in various ways to support Python 3.12 among other things #281

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions .ci/native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ echo $PYTHON_VERSION
$PYTHON_VERSION --version

($PYTHON_VERSION -m pip freeze | grep black 1>/dev/null 2>&1) || $PYTHON_VERSION -m pip install black==21.7b0
$PYTHON_VERSION -m pip install pylint==2.6.0 pytest==6.2.5
$PYTHON_VERSION -m pip install -r rustfst-python/requirements-setup.txt
$PYTHON_VERSION -m pip install -r rustfst-python/requirements-tests.txt
$PYTHON_VERSION -m pip install -e .

cd rustfst-python
$PYTHON_VERSION -m setup.py develop

# Check format
$PYTHON_VERSION -m black --check . || fail "Format your code by running black ." 1
Expand Down
58 changes: 42 additions & 16 deletions .github/workflows/native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ jobs:
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
- name: Build rustfst-python
run: |
pip install pylint==2.6.0 pytest==6.2.5
pip install -r rustfst-python/requirements-setup.txt
pip install -e rustfst-python
pip install -r rustfst-python/requirements-tests.txt
pip install -e .
- name: Test rustfst-python
run: python -m pytest -s --cache-clear --disable-warnings rustfst-python

Expand All @@ -258,7 +258,7 @@ jobs:
- name: Build rustfst-python
run: |
pip install -r rustfst-python/requirements-setup.txt
pip install -e rustfst-python
pip install -e .
- name: Install mkdocs
run: pip install -r rustfst-python/requirements-mkdocs.txt
- name: Test doc generation
Expand Down Expand Up @@ -291,7 +291,7 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
- run: pip install -r rustfst-python/requirements-setup.txt
- run: pip install -e rustfst-python
- run: pip install -e .
- run: pip install -r rustfst-python/requirements-mkdocs.txt
- run: git config user.name ${{ env.GIT_COMMITTER_NAME }}
- run: git config user.email ${{ env.GIT_COMMITTER_EMAIL }}
Expand Down Expand Up @@ -337,9 +337,28 @@ jobs:
cd ..


build-python-sdist:
name: Build source distribution
runs-on: ubuntu-latest
needs: [ rust-clippy, rust-doc, rust-tests, rustfst-python-bench, rustfst-python, python-doc ]
if: startsWith(github.ref, 'refs/tags/rustfst-v')
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build source distribution
run: pipx run build --sdist

- name: Upload source distribution as artifact
uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: dist/*.tar.gz


publish-python-wheels:
name: Publish Python Wheels to PyPI
needs: [ rust-clippy, rust-doc, rust-tests, rustfst-python-bench, rustfst-python, python-doc ]
needs: [ build-python-sdist ]
if: startsWith(github.ref, 'refs/tags/rustfst-v')

strategy:
Expand All @@ -352,12 +371,11 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }} # Version range or exact version of a Python version to use, using SemVer's version range syntax
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
- name: Build and publish
- name: Checkout
uses: actions/checkout@v4

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_SKIP: cp*-musllinux_i686
CIBW_ENVIRONMENT: PATH="$HOME/.cargo/bin:$PATH"
Expand All @@ -372,11 +390,19 @@ jobs:
CIBW_ARCHS_MACOS: "x86_64 arm64"
# On an Linux Intel runner with qemu installed, build Intel and ARM wheels
CIBW_ARCHS_LINUX: "auto"
run: |
python3.9 -m pip install twine cibuildwheel==2.13.1
mkdir -p wheels
python3.9 -m cibuildwheel --output-dir wheels rustfst-python
python3.9 -m twine upload -u "__token__" -p ${{ secrets.PYPI_PASSWORD }} -r pypi --verbose wheels/*

- name: Upload wheels as artifacts
uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl

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

- name: Upload sdist and wheels to PyPI
run: |
python -m pip install twine
python -m twine upload -u "__token__" -p ${{ secrets.PYPI_PASSWORD }} -r pypi --verbose wheelhouse/* dist/*.tar.gz
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ rustfst-python/mkdocs/site
rustfst-python/mkdocs/docs/reference
site

rustfst/proptest-regressions/
rustfst/proptest-regressions/
*~
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `TrivialWeight`
- Implement `WeaklyDivisibleSemiring` for `BooleanWeight`

## Changed
- Update to pyproject.toml configuration for Python build
- Use pyproject.toml to generate requirements files
- Support Python 3.12 and 3.13
- Correct documentation for various Python methods

## [0.8.0] - 2020-16-10

## Added
Expand Down
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include Cargo.toml
recursive-include rustfst *.toml *.rs
recursive-include rustfst-cli *.toml *.rs
recursive-include rustfst-ffi *.toml *.rs
71 changes: 71 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[build-system]
requires = ["setuptools", "setuptools-rust"]
build-backend = "setuptools.build_meta"

[project]
name = "rustfst-python"
version = "1.1.2"
authors = [
{ name = "Alexandre Caulier", email = "[email protected]" },
{ name = "Emrick Sinitambirivoutin", email = "[email protected]" },
]
description = "Library for constructing, combining, optimizing, and searching weighted finite-state transducers (FSTs). Re-implementation of OpenFst in Rust."
readme = "README.md"
requires-python = ">=3.8"
keywords = ["fst", "openfst", "graph", "transducer", "acceptor",
"shortest-path", "minimize", "determinize", "wfst"]
license = { text="Apache License, Version 2.0" }
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Rust",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Text Processing",
"License :: OSI Approved :: Apache Software License",
]

[project.optional-dependencies]
tests = [ "pytest", "pylint" ]
docs = [
"mike",
"mkdocstrings[python]",
"mkdocs-material",
"mkdocs-literate-nav",
"mkdocs-gen-files",
"mkdocs-section-index",
"mkdocs-macros-plugin",
]


# This was in setup.py but is no longer relevant (it's not for Mac OS X)
# options={"bdist_wheel": {"universal": True}},

[tool.setuptools]
package-dir = {"rustfst" = "rustfst-python/rustfst"}

[[tool.setuptools-rust.ext-modules]]
target = "rustfst.dylib.dylib"
path = "rustfst-ffi/Cargo.toml"
binding = "NoBinding"

[tool.pytest.ini_options]
markers = ["rustfst"]

[tool.pylint.main]
ignore = ["scripts"]
persistent = true
py-version = "3.8"

[tool.pylint."messages control"]
enable = ["indexing-exception", "old-raise-syntax"]
disable = ["design","similarities","no-self-use","attribute-defined-outside-init","locally-disabled","star-args","pointless-except","bad-option-value","global-statement","fixme","suppressed-message","useless-suppression","locally-enabled","no-member","no-name-in-module","import-error","unsubscriptable-object","unbalanced-tuple-unpacking","undefined-variable","not-context-manager","missing-docstring","cyclic-import","redefined-builtin","ungrouped-imports","wrong-import-order","bad-continuation","import-outside-toplevel","line-too-long"]

[tool.pylint.reports]
output-format = "text"
reports = "no"
6 changes: 2 additions & 4 deletions rustfst-python/linting/linting_test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import os
from pathlib import Path

import pytest
from pylint.lint import Run

ROOT_PATH = Path(__file__).parents[1]
ROOT_PATH = Path(__file__).parent.parent
RCFILEPATH = ROOT_PATH / "linting" / "pylintrc"


def run_linting_test(package):
args = ["--rcfile", str(RCFILEPATH)]
args += all_python_files(package)
args = all_python_files(package)

run = Run(args, exit=False)
assert run.linter.msg_status == 0
Expand Down
Loading