Skip to content
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

Rust extension module #101

Merged
merged 26 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
94f31ed
Rust extension module with maturin
ariebovenberg Mar 29, 2024
18a83b4
Make rust extension optional
ariebovenberg Apr 1, 2024
7b81dd6
First classes in rust extension
ariebovenberg Apr 2, 2024
2fc7ccf
Add other datetime types, redesign DateDelta
ariebovenberg Apr 29, 2024
fc2f77f
Improve error handling
ariebovenberg May 20, 2024
a060e69
Add missing methods, improve error handling
ariebovenberg May 28, 2024
7b1d82c
patch up GC/ref handling, 3.13 support
ariebovenberg Jun 10, 2024
5d7ce10
Improve docs, get pure-Python version working again
ariebovenberg Jun 10, 2024
0c39c8c
rationalize method names
ariebovenberg Jun 13, 2024
2e6e53a
fix leftover todos and coverage
ariebovenberg Jun 13, 2024
6cc336c
Fixes for wheels across platforms
ariebovenberg Jun 16, 2024
def6619
fix image link in README
ariebovenberg Jun 19, 2024
3b43929
Additional wheels for other archs
ariebovenberg Jun 19, 2024
a4c0e8f
add flag to see whether rust extension is loaded
ariebovenberg Jun 20, 2024
e5bfa10
additional testing for internal function
ariebovenberg Jun 20, 2024
857caab
add benchmark readme
ariebovenberg Jun 20, 2024
1ef0ab7
docs improvements
ariebovenberg Jun 20, 2024
d517867
small refactorings across extension module
ariebovenberg Jun 20, 2024
9475917
improve robustness of conversions near bounds
ariebovenberg Jun 23, 2024
14876cf
Drop "local" terminolgy from system timezone
ariebovenberg Jun 23, 2024
38cfb27
fix failing tests
ariebovenberg Jun 24, 2024
d93a57f
Replace UTCDateTime with Instant
ariebovenberg Jun 25, 2024
f18b5ba
Rename naive to local, cleanup docs
ariebovenberg Jun 28, 2024
1d4b722
make disambiguate argument required for relevant methods
ariebovenberg Jun 28, 2024
7c35f86
Add ignore_dst and disambiguate arg to relevant methods
ariebovenberg Jun 29, 2024
ce7885a
prepare next release
ariebovenberg Jul 4, 2024
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
15 changes: 15 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[build]
rustflags = []

# see https://pyo3.rs/v0.21.2/building-and-distribution.html?highlight=macos#manual-builds
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]

[target.aarch64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
11 changes: 11 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[coverage:run]
branch=True
[coverage:report]
fail_under=100
exclude_lines=
pragma: no cover
raise NotImplementedError
def __repr__
@overload
^\s+\.\.\.
if TYPE_CHECKING.*:
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,.tox
extend-ignore =
# let black handle line length
E501
per-file-ignores =
__init__.py: F401,F403

1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Checklist

- [ ] Build runs successfully
- [ ] Type stubs updated
- [ ] Docs updated

# Release checklist (maintainers only)
Expand Down
139 changes: 139 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: Checks

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
test-python-versions:
name: Test Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [
"3.9",
"3.10",
"3.11",
"3.12",
"3.13-dev",
]
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: "Test Rust"
if: ${{ (matrix.os == 'ubuntu-latest') && (matrix.python-version == '3.12') }}
run: |
cargo test

- name: Install and test
shell: bash
run: |
pip install .
pip install -r requirements/test.txt
pytest tests/

Test-os:
name: Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1

- uses: actions/setup-python@v5
if: ${{ !(matrix.os == 'windows-latest') }}
with:
python-version: '3.12'

# ensure 32-bit target is tested
# FUTURE: Add a linux 32-bit target
- uses: actions/setup-python@v5
if: ${{ matrix.os == 'windows-latest' }}
with:
python-version: '3.12'
architecture: x86


- name: Install and test
shell: bash
run: |
pip install -e .
pip install -r requirements/test.txt
pytest tests/

test-pure-python:
name: Test pure Python version
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [
"3.9",
"3.10",
"3.11",
"3.12",
"3.13-dev",
# # NOTE: pypy/pytest fails sometimes (https://github.com/pypy/pypy/issues/3959)
"pypy3.9",
"pypy3.10"
]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# only run coverage once
- if: ${{ matrix.python-version == '3.12' }}
run: |
pip install .
pip install -r requirements/test.txt
pytest tests/ --cov=whenever --cov-report=xml
env:
WHENEVER_NO_BUILD_RUST_EXT: "1"
- run: |
pip install .
pip install -r requirements/test.txt
pytest tests/
env:
WHENEVER_NO_BUILD_RUST_EXT: "1"

Linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: |
pip install .
pip install -U pip
pip install -r requirements/lint.txt
make ci-lint
env:
WHENEVER_NO_BUILD_RUST_EXT: "1"

Typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: |
pip install .
pip install -r requirements/typecheck.txt
pip install -r requirements/test.txt
make typecheck
env:
WHENEVER_NO_BUILD_RUST_EXT: "1"
52 changes: 0 additions & 52 deletions .github/workflows/tests.yml

This file was deleted.

108 changes: 108 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Build and publish wheels

on:
push:
tags:
- '*'
workflow_dispatch:

permissions:
contents: read

jobs:
binary:
name: build on ${{ matrix.os }} (${{ matrix.target }}) (${{ matrix.manylinux || 'auto' }})
strategy:
fail-fast: false
matrix:
os: [windows, macos, linux]
target: [x86_64, aarch64]
include:
# additional linux targets
- os: linux
target: x86
- os: linux
target: armv7
- os: linux
target: ppc64le
- os: linux
target: s390x

# musl targets
- os: linux
target: x86_64
manylinux: musllinux_1_2
- os: linux
target: x86
manylinux: musllinux_1_2
- os: linux
target: aarch64
manylinux: musllinux_1_2
- os: linux
target: armv7
manylinux: musllinux_1_2

- os: windows
python-architecture: x86
target: x86

exclude:
- os: windows
target: aarch64

runs-on: ${{ (matrix.os == 'linux' && 'ubuntu') || matrix.os }}-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
architecture: ${{ matrix.python-architecture || 'x64' }}
- run: |
pip install -U twine
sed -i ${{ (matrix.os == 'macos' && '""') || '' }} 's/build-backend = "setuptools.build_meta"/build-backend = "maturin"/' pyproject.toml
sed -i ${{ (matrix.os == 'macos' && '""') || '' }} 's/^requires = \["setuptools", .*]/requires = \["maturin>=1.0,<2.0"\]/' pyproject.toml
tail pyproject.toml
- name: build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --interpreter '3.9 3.10 3.11 3.12'
manylinux: ${{ matrix.manylinux || 'auto' }}
sccache: 'true'
rust-toolchain: stable
- run: twine check --strict dist/*
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-binary-${{ matrix.os }}-${{ matrix.target }}-${{ matrix.manylinux || 'auto' }}
path: dist/*

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
run: |
pip install build twine
python -m build --sdist --outdir dist
- run: twine check --strict dist/*
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist/*

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [binary, sdist]
steps:
- uses: actions/download-artifact@v4
- name: Publish to PyPI
run: |
pip install twine
twine upload --non-interactive --disable-progress-bar --skip-existing wheels-*/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ docs/_build/
.python-version

.hypothesis
.benchmarks

benchmarks/comparison/result_*.json
5 changes: 3 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ build:
os: ubuntu-22.04
tools:
python: "3.11"
rust: "1.70"
# rust shouldn't be needed as we disable building the extension
# in the readthedocs configuration

python:
install:
- requirements: docs/requirements.txt
- requirements: requirements/docs.txt
- method: pip
path: .
Loading