build: Update Python builds

This commit is contained in:
stranger6667 2022-12-24 14:09:41 +01:00
parent f44f195dc1
commit 2f0c815244
15 changed files with 505 additions and 411 deletions

View File

@ -102,8 +102,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, macos-11, windows-2019]
python-version: ['3.7', '3.8', '3.9', '3.10']
os: [ ubuntu-20.04, macos-11, windows-2019 ]
python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11' ]
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}

View File

@ -5,133 +5,320 @@ on:
tags:
- python-v*
defaults:
run:
shell: bash
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
PACKAGE_NAME: jsonschema_rs
PYTHON_VERSION: "3.7" # to build abi3 wheels
jobs:
create_macos_and_windows_wheels:
name: Wheels for Python ${{ matrix.python-version }} / ${{ matrix.os }}
strategy:
matrix:
os: [macos-11, windows-2019]
python-version: ['3.7', '3.8', '3.9', '3.10']
architecture: [x86, x64]
exclude:
- os: macos-11
architecture: x86
- os: windows-2019
# TODO: Re-enable windows 32bits
architecture: x86
runs-on: ${{ matrix.os }}
sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}
- uses: actions-rs/toolchain@v1
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install Tox
run: pip install tox
- name: Build wheel
working-directory: ./bindings/python
run: tox -e build-wheel
- uses: actions/upload-artifact@v2
with:
name: Distribution Artifacts
path: bindings/python/dist/
create_wheels_manylinux:
name: Wheels for Python ${{ matrix.PYTHON_IMPLEMENTATION_ABI }} / Linux
strategy:
fail-fast: false
matrix:
# List of the language-implementation API pairs to publish wheels for
# The list of supported is obtainable by running `docker run quay.io/pypa/manylinux2014_x86_64 ls /opt/python`
PYTHON_IMPLEMENTATION_ABI: [cp37-cp37m, cp38-cp38, cp39-cp39, cp310-cp310]
runs-on: ubuntu-20.04
container: quay.io/pypa/manylinux2014_x86_64 # Builds wheels on CentOS 7 (supported until 2024)
env:
# Variable needed for PyO3 to properly identify the python interpreter
PYTHON_SYS_EXECUTABLE: /opt/python/${{ matrix.PYTHON_IMPLEMENTATION_ABI }}/bin/python
steps:
- uses: actions/checkout@v2
- name: Install/Update OpenSSL
run: |
retryCount=0
# yum install seems to be flakey (due to network timeouts)
# retry up to 5 times with a 10s sleep in case of failure
until yum install openssl-devel --assumeyes --noplugins; do
# For some reason the install has failed
if [ ${retryCount} -eq 5 ]; then
false
else
retryCount=$((${retryCount}+1))
fi
sleep 10
done
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install Tox
run: ${{ env.PYTHON_SYS_EXECUTABLE }} -m pip install tox
- name: Build wheel
working-directory: ./bindings/python
run: |
${{ env.PYTHON_SYS_EXECUTABLE }} -m tox -e build-wheel
# Ensure that the wheel is tagged as manylinux2014 platform
auditwheel repair \
--wheel-dir=./dist \
--plat manylinux2014_x86_64 \
./dist/jsonschema_rs-*-${{ matrix.PYTHON_IMPLEMENTATION_ABI }}-linux_x86_64.whl
# Remove `linux_x86_64` tagged wheels as they are not supported by https://pypi.org
# Example https://github.com/Stranger6667/jsonschema-rs/runs/766075274
rm ./dist/jsonschema_rs-*-${{ matrix.PYTHON_IMPLEMENTATION_ABI }}-linux_x86_64.whl
- uses: actions/upload-artifact@v2
with:
name: Distribution Artifacts
path: bindings/python/dist/
create_source_dist:
name: Create sdist package
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install Tox
run: pip install tox
default: true
- name: Build sdist
working-directory: ./bindings/python
run: tox -e build-sdist
- uses: actions/upload-artifact@v2
uses: messense/maturin-action@v1
with:
name: Distribution Artifacts
path: bindings/python/dist/
command: sdist
args: -m bindings/python/Cargo.toml --out dist
- name: Install sdist
run: |
pip install dist/${{ env.PACKAGE_NAME }}-*.tar.gz --force-reinstall
- name: Upload sdist
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
upload_to_pypi:
needs:
- create_macos_and_windows_wheels
- create_wheels_manylinux
- create_source_dist
name: Upload Artifacts to PyPi
runs-on: ubuntu-20.04
macos-x86_64:
runs-on: macos-latest
steps:
- uses: actions/download-artifact@v2
with:
name: Distribution Artifacts
path: bindings/python/dist/
- name: Publish distribution package to PyPI
uses: pypa/gh-action-pypi-publish@v1.2.2
with:
user: ${{ secrets.PYPI_USERNAME }}
password: ${{ secrets.PYPI_PASSWORD }}
packages_dir: bindings/python/dist/
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
default: true
- name: Build wheels - x86_64
uses: messense/maturin-action@v1
with:
target: x86_64
args: --release -m bindings/python/Cargo.toml --out dist
- name: Install built wheel - x86_64
run: |
pip install dist/${{ env.PACKAGE_NAME }}-*.whl --force-reinstall
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
macos-universal:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
default: true
- name: Build wheels - universal2
uses: messense/maturin-action@v1
with:
args: --release -m bindings/python/Cargo.toml --universal2 --out dist
- name: Install built wheel - universal2
run: |
pip install dist/${{ env.PACKAGE_NAME }}-*universal2.whl --force-reinstall
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
windows:
runs-on: windows-latest
strategy:
matrix:
target: [ x64, x86 ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: ${{ matrix.target }}
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
default: true
- name: Build wheels
uses: messense/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release -m bindings/python/Cargo.toml --out dist
- name: Install built wheel
shell: bash
run: |
python -m pip install dist/${{ env.PACKAGE_NAME }}-*.whl --force-reinstall
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
linux:
runs-on: ubuntu-latest
strategy:
matrix:
target: [ x86_64, i686 ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- name: Build wheels
uses: messense/maturin-action@v1
with:
target: ${{ matrix.target }}
manylinux: auto
args: --release -m bindings/python/Cargo.toml --out dist
- name: Install built wheel
if: matrix.target == 'x86_64'
run: |
pip install dist/${{ env.PACKAGE_NAME }}-*.whl --force-reinstall
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
linux-cross:
runs-on: ubuntu-latest
strategy:
matrix:
target: [ aarch64, armv7 ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Build wheels
uses: messense/maturin-action@v1
with:
target: ${{ matrix.target }}
manylinux: auto
args: --release -m bindings/python/Cargo.toml --no-default-features --out dist
- uses: uraimo/run-on-arch-action@v2.0.5
name: Install built wheel
with:
arch: ${{ matrix.target }}
distro: ubuntu20.04
githubToken: ${{ github.token }}
install: |
apt-get update
apt-get install -y --no-install-recommends python3 python3-pip
pip3 install -U pip
run: |
pip3 install ${{ env.PACKAGE_NAME }} --no-index --find-links dist/ --force-reinstall
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
musllinux:
runs-on: ubuntu-latest
strategy:
matrix:
target:
- x86_64-unknown-linux-musl
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- name: Build wheels
uses: messense/maturin-action@v1
with:
target: ${{ matrix.target }}
manylinux: musllinux_1_2
args: --release -m bindings/python/Cargo.toml --out dist
- name: Install built wheel
uses: addnab/docker-run-action@v3
with:
image: alpine:latest
options: -v ${{ github.workspace }}:/io -w /io
run: |
apk add py3-pip
pip3 install ${{ env.PACKAGE_NAME }} --no-index --find-links /io/dist/ --force-reinstall
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
musllinux-cross:
runs-on: ubuntu-latest
strategy:
matrix:
platform:
- target: aarch64-unknown-linux-musl
arch: aarch64
- target: armv7-unknown-linux-musleabihf
arch: armv7
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Build wheels
uses: messense/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
manylinux: musllinux_1_2
args: --release -m bindings/python/Cargo.toml --out dist
- uses: uraimo/run-on-arch-action@master
name: Install built wheel
with:
arch: ${{ matrix.platform.arch }}
distro: alpine_latest
githubToken: ${{ github.token }}
install: |
apk add py3-pip
run: |
pip3 install ${{ env.PACKAGE_NAME }} --no-index --find-links dist/ --force-reinstall
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
pypy:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macos-latest ]
target: [ x86_64, aarch64 ]
python-version:
- "3.7"
- "3.8"
- "3.9"
exclude:
- os: macos-latest
target: aarch64
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: pypy${{ matrix.python-version }}
- name: Build wheels
uses: messense/maturin-action@v1
with:
target: ${{ matrix.target }}
manylinux: auto
args: --release -m bindings/python/Cargo.toml --out dist -i pypy${{ matrix.python-version }}
- name: Install built wheel
if: matrix.target == 'x86_64'
run: |
pip install dist/${{ env.PACKAGE_NAME }}-*.whl --force-reinstall
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
release:
name: Release
runs-on: ubuntu-latest
needs:
- sdist
- macos-x86_64
- macos-universal
- windows
- linux
- linux-cross
- musllinux
- musllinux-cross
- pypy
if: "startsWith(github.ref, 'refs/tags/')"
steps:
- uses: actions/download-artifact@v2
with:
name: dist
- uses: actions/setup-python@v4
- name: Publish to PyPi
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
pip install --upgrade twine
twine upload --skip-existing *

View File

@ -4,9 +4,9 @@ version = 3
[[package]]
name = "ahash"
version = "0.8.0"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57e6e951cfbb2db8de1828d49073a113a29fd7117b1596caa781a258c7e38d72"
checksum = "bf6ccdb167abbf410dcb915cabd428929d7f6a04980b54a11f26a39f1c7f7107"
dependencies = [
"cfg-if",
"getrandom",
@ -17,9 +17,9 @@ dependencies = [
[[package]]
name = "aho-corasick"
version = "0.7.19"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e"
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
dependencies = [
"memchr",
]
@ -35,9 +35,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.66"
version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61"
[[package]]
name = "autocfg"
@ -74,9 +74,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "built"
version = "0.5.1"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f346b6890a0dfa7266974910e7df2d5088120dd54721b9b0e5aae1ae5e05715"
checksum = "5b9c056b9ed43aee5e064b683aa1ec783e19c6acec7559e3ae931b7490472fbe"
dependencies = [
"cargo-lock",
"chrono",
@ -96,15 +96,15 @@ checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c"
[[package]]
name = "bytes"
version = "1.2.1"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db"
checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c"
[[package]]
name = "cargo-lock"
version = "7.1.0"
version = "8.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c408da54db4c50d4693f7e649c299bc9de9c23ead86249e5368830bb32a734b"
checksum = "031718ddb8f78aa5def78a09e90defe30151d1f6c672f937af4dd916429ed996"
dependencies = [
"semver",
"serde",
@ -114,9 +114,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.0.73"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d"
[[package]]
name = "cfg-if"
@ -126,16 +126,13 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.22"
version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1"
checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f"
dependencies = [
"iana-time-zone",
"js-sys",
"num-integer",
"num-traits",
"time 0.1.44",
"wasm-bindgen",
"winapi",
]
@ -157,9 +154,9 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]]
name = "cxx"
version = "1.0.80"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a"
checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd"
dependencies = [
"cc",
"cxxbridge-flags",
@ -169,9 +166,9 @@ dependencies = [
[[package]]
name = "cxx-build"
version = "1.0.80"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827"
checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0"
dependencies = [
"cc",
"codespan-reporting",
@ -184,15 +181,15 @@ dependencies = [
[[package]]
name = "cxxbridge-flags"
version = "1.0.80"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a"
checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59"
[[package]]
name = "cxxbridge-macro"
version = "1.0.80"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7"
checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6"
dependencies = [
"proc-macro2",
"quote",
@ -235,9 +232,9 @@ dependencies = [
[[package]]
name = "fraction"
version = "0.12.1"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99df8100674344d1cee346c764684f7ad688a4dcaa1a3efb2fdb45daf9acf4f9"
checksum = "7aa5de57a62c2440ece64342ea59efb7171aa7d016faf8dfcb8795066a17146b"
dependencies = [
"lazy_static",
"num",
@ -299,7 +296,7 @@ checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
dependencies = [
"cfg-if",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
"wasi",
]
[[package]]
@ -329,9 +326,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hermit-abi"
version = "0.1.19"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
dependencies = [
"libc",
]
@ -372,9 +369,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "hyper"
version = "0.14.20"
version = "0.14.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac"
checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c"
dependencies = [
"bytes",
"futures-channel",
@ -396,9 +393,9 @@ dependencies = [
[[package]]
name = "iana-time-zone"
version = "0.1.51"
version = "0.1.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5a6ef98976b22b3b7f2f3a806f858cb862044cfa66805aa3ad84cb3d3b785ed"
checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765"
dependencies = [
"android_system_properties",
"core-foundation-sys",
@ -430,9 +427,9 @@ dependencies = [
[[package]]
name = "indexmap"
version = "1.9.1"
version = "1.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
dependencies = [
"autocfg",
"hashbrown",
@ -440,30 +437,30 @@ dependencies = [
[[package]]
name = "indoc"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adab1eaa3408fb7f0c777a73e7465fd5656136fc93b670eb6df3c88c2c1344e3"
checksum = "da2d6f23ffea9d7e76c53eee25dfb67bcd8fde7f1198b0855350698c9f07c780"
[[package]]
name = "ipnet"
version = "2.5.0"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b"
checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e"
[[package]]
name = "iso8601"
version = "0.5.0"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f21abb3d09069861499d93d41a970243a90e215df0cf763ac9a31b9b27178d0"
checksum = "296af15e112ec6dc38c9fd3ae027b5337a75466e8eed757bd7d5cf742ea85eb6"
dependencies = [
"nom",
]
[[package]]
name = "itoa"
version = "1.0.4"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
[[package]]
name = "js-sys"
@ -495,7 +492,7 @@ dependencies = [
"reqwest",
"serde",
"serde_json",
"time 0.3.16",
"time",
"url",
"uuid",
]
@ -520,15 +517,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.137"
version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
name = "link-cplusplus"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369"
checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
dependencies = [
"cc",
]
@ -587,7 +584,7 @@ checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de"
dependencies = [
"libc",
"log",
"wasi 0.11.0+wasi-snapshot-preview1",
"wasi",
"windows-sys",
]
@ -685,28 +682,19 @@ dependencies = [
[[package]]
name = "num_cpus"
version = "1.13.1"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "num_threads"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
dependencies = [
"libc",
]
[[package]]
name = "once_cell"
version = "1.15.0"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
[[package]]
name = "parking_lot"
@ -720,9 +708,9 @@ dependencies = [
[[package]]
name = "parking_lot_core"
version = "0.9.4"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0"
checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba"
dependencies = [
"cfg-if",
"libc",
@ -751,18 +739,18 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "proc-macro2"
version = "1.0.47"
version = "1.0.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
dependencies = [
"unicode-ident",
]
[[package]]
name = "pyo3"
version = "0.17.2"
version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201b6887e5576bf2f945fe65172c1fcbf3fcf285b23e4d71eb171d9736e38d32"
checksum = "268be0c73583c183f2b14052337465768c07726936a260f480f0857cb95ba543"
dependencies = [
"cfg-if",
"indoc",
@ -777,9 +765,9 @@ dependencies = [
[[package]]
name = "pyo3-build-config"
version = "0.17.2"
version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf0708c9ed01692635cbf056e286008e5a2927ab1a5e48cdd3aeb1ba5a6fef47"
checksum = "28fcd1e73f06ec85bf3280c48c67e731d8290ad3d730f8be9dc07946923005c8"
dependencies = [
"once_cell",
"target-lexicon",
@ -793,9 +781,9 @@ checksum = "be6d574e0f8cab2cdd1eeeb640cbf845c974519fa9e9b62fa9c08ecece0ca5de"
[[package]]
name = "pyo3-ffi"
version = "0.17.2"
version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90352dea4f486932b72ddf776264d293f85b79a1d214de1d023927b41461132d"
checksum = "0f6cb136e222e49115b3c51c32792886defbfb0adead26a688142b346a0b9ffc"
dependencies = [
"libc",
"pyo3-build-config",
@ -803,9 +791,9 @@ dependencies = [
[[package]]
name = "pyo3-macros"
version = "0.17.2"
version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eb24b804a2d9e88bfcc480a5a6dd76f006c1e3edaf064e8250423336e2cd79d"
checksum = "94144a1266e236b1c932682136dc35a9dee8d3589728f68130c7c3861ef96b28"
dependencies = [
"proc-macro2",
"pyo3-macros-backend",
@ -815,9 +803,9 @@ dependencies = [
[[package]]
name = "pyo3-macros-backend"
version = "0.17.2"
version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f22bb49f6a7348c253d7ac67a6875f2dc65f36c2ae64a82c381d528972bea6d6"
checksum = "c8df9be978a2d2f0cdebabb03206ed73b11314701a5bfe71b0d753b81997777f"
dependencies = [
"proc-macro2",
"quote",
@ -826,9 +814,9 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.21"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
dependencies = [
"proc-macro2",
]
@ -844,9 +832,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.6.0"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
dependencies = [
"aho-corasick",
"memchr",
@ -855,15 +843,15 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.6.27"
version = "0.6.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
[[package]]
name = "reqwest"
version = "0.11.12"
version = "0.11.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc"
checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c"
dependencies = [
"base64",
"bytes",
@ -895,9 +883,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.11"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
[[package]]
name = "scopeguard"
@ -907,33 +895,33 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "scratch"
version = "1.0.2"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898"
checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
[[package]]
name = "semver"
version = "1.0.14"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4"
checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a"
dependencies = [
"serde",
]
[[package]]
name = "serde"
version = "1.0.147"
version = "1.0.151"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965"
checksum = "97fed41fc1a24994d044e6db6935e69511a1153b52c15eb42493b26fa87feba0"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.147"
version = "1.0.151"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852"
checksum = "255abe9a125a985c05190d687b320c12f9b1f0b99445e608c21ba0782c719ad8"
dependencies = [
"proc-macro2",
"quote",
@ -942,9 +930,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.87"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45"
checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
dependencies = [
"itoa",
"ryu",
@ -990,9 +978,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.103"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d"
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
dependencies = [
"proc-macro2",
"quote",
@ -1001,9 +989,9 @@ dependencies = [
[[package]]
name = "target-lexicon"
version = "0.12.4"
version = "0.12.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c02424087780c9b71cc96799eaeddff35af2bc513278cda5c99fc1f5d026d3c1"
checksum = "9410d0f6853b1d94f0e519fb95df60f29d2c1eff2d921ffdf01a4c8a3b54f12d"
[[package]]
name = "termcolor"
@ -1016,23 +1004,10 @@ dependencies = [
[[package]]
name = "time"
version = "0.1.44"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
[[package]]
name = "time"
version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fab5c8b9980850e06d92ddbe3ab839c062c801f3927c0fb8abd6fc8e918fbca"
dependencies = [
"libc",
"num_threads",
"serde",
"time-core",
"time-macros",
@ -1046,9 +1021,9 @@ checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
[[package]]
name = "time-macros"
version = "0.2.5"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65bb801831d812c562ae7d2bfb531f26e66e4e1f6b17307ba4149c5064710e5b"
checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2"
dependencies = [
"time-core",
]
@ -1070,9 +1045,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.21.2"
version = "1.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099"
checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46"
dependencies = [
"autocfg",
"bytes",
@ -1082,7 +1057,7 @@ dependencies = [
"num_cpus",
"pin-project-lite",
"socket2",
"winapi",
"windows-sys",
]
[[package]]
@ -1101,9 +1076,9 @@ dependencies = [
[[package]]
name = "toml"
version = "0.5.9"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f"
dependencies = [
"serde",
]
@ -1148,9 +1123,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992"
[[package]]
name = "unicode-ident"
version = "1.0.5"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
[[package]]
name = "unicode-normalization"
@ -1169,9 +1144,9 @@ checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "unindent"
version = "0.1.10"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58ee9362deb4a96cef4d437d1ad49cffc9b9e92d202b6995674e928ce684f112"
checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c"
[[package]]
name = "url"
@ -1186,9 +1161,9 @@ dependencies = [
[[package]]
name = "uuid"
version = "1.2.1"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83"
checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c"
[[package]]
name = "version_check"
@ -1206,12 +1181,6 @@ dependencies = [
"try-lock",
]
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"

View File

@ -25,31 +25,11 @@ default-features = false
features = ["resolve-http", "resolve-file"]
[dependencies]
serde_json = "1.0.81"
serde = "1.0.137"
pyo3 = { version = "0.17.2", features = ["extension-module"] }
serde_json = "1.0.91"
serde = "1.0.151"
pyo3 = { version = "0.17.2", features = ["extension-module", "abi3-py37"] }
pyo3-built = "0.4.7"
[package.metadata.maturin]
requires-python = ">=3.7"
project-url = { repository = "https://github.com/Stranger6667/jsonschema-rs" }
maintainer = "Dmitry Dygalo"
maintainer-email = "Dmitry Dygalo <dadygalo@gmail.com>"
classifier = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"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",
]
[profile.release]
codegen-units = 1
lto = "on"

View File

@ -1,12 +0,0 @@
include Cargo.toml
include build.rs
include pyproject.toml
include rust-toolchain
recursive-include src *
include jsonschema_rs/py.typed
recursive-include jsonschema_rs *.pyi
recursive-include jsonschema-lib *
recursive-exclude jsonschema-lib Cargo.lock
recursive-exclude jsonschema-lib/target *
recursive-exclude jsonschema-lib/benches *.json
recursive-exclude jsonschema-lib/tests *

View File

@ -1,12 +0,0 @@
#!/bin/bash
set -ex
# Create a symlink for jsonschema
ln -sf ../../jsonschema jsonschema-lib
# Modify Cargo.toml to include this symlink
cp Cargo.toml Cargo.toml.orig
sed -i 's/\.\.\/\.\.\/jsonschema/\.\/jsonschema-lib/' Cargo.toml
# Build the source distribution
python setup.py sdist
rm jsonschema-lib
mv Cargo.toml.orig Cargo.toml

View File

@ -1 +1 @@
from ._jsonschema_rs import *
from .jsonschema_rs import *

View File

@ -1,6 +1,3 @@
[build-system]
requires = ["setuptools", "setuptools-rust", "toml", "wheel"]
[tool.black]
line-length = 120
target_version = ["py37"]
@ -13,3 +10,42 @@ default_section = "THIRDPARTY"
include_trailing_comma = true
known_first_party = "jsonschema_rs"
known_third_party = []
[project]
name = "jsonschema_rs"
description = "Fast JSON Schema validation for Python implemented in Rust"
authors = [
{name = "Dmitry Dygalo", email = "dadygalo@gmail.com"}
]
requires-python = ">=3.7"
project-url = { repository = "https://github.com/Stranger6667/jsonschema-rs" }
maintainer = "Dmitry Dygalo"
maintainer-email = "Dmitry Dygalo <dadygalo@gmail.com>"
license = { text = "MIT" }
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"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 :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
]
dependencies = []
[project.urls]
homepage = "https://github.com/Stranger6667/jsonschema-rs/tree/master/python"
repository = "https://github.com/Stranger6667/jsonschema-rs/"
[build-system]
requires = ["maturin>=0.14.0<15"]
build-backend = "maturin"
[tool.maturin]
strip = true

View File

@ -1 +0,0 @@
stable

View File

@ -1,56 +0,0 @@
from setuptools import setup
try:
from setuptools_rust import Binding, RustExtension
except ImportError:
from textwrap import dedent
raise ImportError(
dedent(
"""
`setuptools-rust` is a required dependency to run `setup.py`.
This should not happen if you're using `pip>=10` as it honors `pyproject.toml`.
This usually (at least on our workflows) might happen while
building source-distribution.
"""
)
)
def call_setup():
setup(
name="jsonschema_rs",
version="0.16.1",
packages=["jsonschema_rs"],
description="Fast JSON Schema validation for Python implemented in Rust",
long_description=open("README.rst", encoding="utf-8").read(),
long_description_content_type="text/x-rst",
keywords="jsonschema validation rust",
author="Dmitry Dygalo",
author_email="dadygalo@gmail.com",
maintainer="Dmitry Dygalo",
maintainer_email="dadygalo@gmail.com",
python_requires=">=3.7",
url="https://github.com/Stranger6667/jsonschema-rs/tree/master/python",
license="MIT",
rust_extensions=[RustExtension("jsonschema_rs._jsonschema_rs", binding=Binding.PyO3)],
include_package_data=True,
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"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",
"Programming Language :: Rust",
],
zip_safe=False,
)
if __name__ == "__main__":
call_setup()

View File

@ -373,8 +373,7 @@ impl JSONSchema {
let obj_ptr = pyschema.as_ptr();
let object_type = unsafe { pyo3::ffi::Py_TYPE(obj_ptr) };
if unsafe { object_type != types::STR_TYPE } {
let type_name =
unsafe { std::ffi::CStr::from_ptr((*object_type).tp_name).to_string_lossy() };
let type_name = unsafe { types::get_type_name(object_type) };
Err(PyValueError::new_err(format!(
"Expected string, got {}",
type_name
@ -450,7 +449,7 @@ mod build {
/// JSON Schema validation for Python written in Rust.
#[pymodule]
fn _jsonschema_rs(py: Python<'_>, module: &PyModule) -> PyResult<()> {
fn jsonschema_rs(py: Python<'_>, module: &PyModule) -> PyResult<()> {
// To provide proper signatures for PyCharm, all the functions have their signatures as the
// first line in docstrings. The idea is taken from NumPy.
types::init();

View File

@ -1,8 +1,8 @@
use pyo3::{
exceptions,
ffi::{
PyDictObject, PyFloat_AS_DOUBLE, PyList_GET_ITEM, PyList_GET_SIZE, PyLong_AsLongLong,
PyObject_GetAttr, PyTuple_GET_ITEM, PyTuple_GET_SIZE, Py_TYPE,
PyDict_Size, PyFloat_AsDouble, PyList_GetItem, PyList_Size, PyLong_AsLongLong,
PyObject_GetAttr, PyTuple_GetItem, PyTuple_Size, Py_TYPE,
},
prelude::*,
types::PyAny,
@ -14,7 +14,6 @@ use serde::{
};
use crate::{ffi, string, types};
use std::ffi::CStr;
pub const RECURSION_LIMIT: u8 = 255;
@ -74,18 +73,16 @@ fn get_object_type_from_object(object: *mut pyo3::ffi::PyObject) -> ObjectType {
}
}
fn get_type_name(object_type: *mut pyo3::ffi::PyTypeObject) -> std::borrow::Cow<'static, str> {
unsafe { CStr::from_ptr((*object_type).tp_name).to_string_lossy() }
}
#[inline]
fn check_type_is_str<E: ser::Error>(object: *mut pyo3::ffi::PyObject) -> Result<(), E> {
let object_type = unsafe { Py_TYPE(object) };
if object_type != unsafe { types::STR_TYPE } {
return Err(ser::Error::custom(format!(
"Dict key must be str. Got '{}'",
get_type_name(object_type)
)));
unsafe {
return Err(ser::Error::custom(format!(
"Dict key must be str. Got '{}'",
types::get_type_name(object_type)
)));
}
}
Ok(())
}
@ -111,7 +108,7 @@ pub fn get_object_type(object_type: *mut pyo3::ffi::PyTypeObject) -> ObjectType
} else if is_enum_subclass(object_type) {
ObjectType::Enum
} else {
ObjectType::Unknown(get_type_name(object_type).to_string())
unsafe { ObjectType::Unknown(types::get_type_name(object_type).to_string()) }
}
}
@ -134,16 +131,14 @@ impl Serialize for SerializePyObject {
serializer.serialize_str(slice)
}
ObjectType::Int => serializer.serialize_i64(unsafe { PyLong_AsLongLong(self.object) }),
ObjectType::Float => {
serializer.serialize_f64(unsafe { PyFloat_AS_DOUBLE(self.object) })
}
ObjectType::Float => serializer.serialize_f64(unsafe { PyFloat_AsDouble(self.object) }),
ObjectType::Bool => serializer.serialize_bool(self.object == unsafe { types::TRUE }),
ObjectType::None => serializer.serialize_unit(),
ObjectType::Dict => {
if self.recursion_depth == RECURSION_LIMIT {
return Err(ser::Error::custom("Recursion limit reached"));
}
let length = unsafe { (*self.object.cast::<PyDictObject>()).ma_used } as usize;
let length = unsafe { PyDict_Size(self.object) } as usize;
if length == 0 {
serializer.serialize_map(Some(0))?.end()
} else {
@ -177,7 +172,7 @@ impl Serialize for SerializePyObject {
if self.recursion_depth == RECURSION_LIMIT {
return Err(ser::Error::custom("Recursion limit reached"));
}
let length = unsafe { PyList_GET_SIZE(self.object) as usize };
let length = unsafe { PyList_Size(self.object) as usize };
if length == 0 {
serializer.serialize_seq(Some(0))?.end()
} else {
@ -185,7 +180,7 @@ impl Serialize for SerializePyObject {
let mut ob_type = ObjectType::Str;
let mut sequence = serializer.serialize_seq(Some(length))?;
for i in 0..length {
let elem = unsafe { PyList_GET_ITEM(self.object, i as isize) };
let elem = unsafe { PyList_GetItem(self.object, i as isize) };
let current_ob_type = unsafe { Py_TYPE(elem) };
if current_ob_type != type_ptr {
type_ptr = current_ob_type;
@ -205,7 +200,7 @@ impl Serialize for SerializePyObject {
if self.recursion_depth == RECURSION_LIMIT {
return Err(ser::Error::custom("Recursion limit reached"));
}
let length = unsafe { PyTuple_GET_SIZE(self.object) as usize };
let length = unsafe { PyTuple_Size(self.object) as usize };
if length == 0 {
serializer.serialize_seq(Some(0))?.end()
} else {
@ -213,7 +208,7 @@ impl Serialize for SerializePyObject {
let mut ob_type = ObjectType::Str;
let mut sequence = serializer.serialize_seq(Some(length))?;
for i in 0..length {
let elem = unsafe { PyTuple_GET_ITEM(self.object, i as isize) };
let elem = unsafe { PyTuple_GetItem(self.object, i as isize) };
let current_ob_type = unsafe { Py_TYPE(elem) };
if current_ob_type != type_ptr {
type_ptr = current_ob_type;

View File

@ -1,8 +1,11 @@
use pyo3::ffi::{PyTypeObject, PyUnicode_AsUTF8AndSize, Py_UNICODE, Py_hash_t, Py_ssize_t};
use pyo3::ffi::{
PyBytes_AsString, PyTypeObject, PyUnicode_AsUTF8String, PyUnicode_GetLength, Py_hash_t,
Py_ssize_t,
};
use std::os::raw::c_char;
#[repr(C)]
struct PyAsciiObject {
pub struct PyAsciiObject {
pub ob_refcnt: Py_ssize_t,
pub ob_type: *mut PyTypeObject,
pub length: Py_ssize_t,
@ -12,13 +15,8 @@ struct PyAsciiObject {
}
#[repr(C)]
struct PyCompactUnicodeObject {
pub ob_refcnt: Py_ssize_t,
pub ob_type: *mut PyTypeObject,
pub length: Py_ssize_t,
pub hash: Py_hash_t,
pub state: u32,
pub wstr: *mut Py_UNICODE,
pub struct PyCompactUnicodeObject {
pub ob_base: PyAsciiObject,
pub utf8_length: Py_ssize_t,
pub utf8: *mut c_char,
pub wstr_length: Py_ssize_t,
@ -27,7 +25,7 @@ struct PyCompactUnicodeObject {
const STATE_ASCII: u32 = 0b0000_0000_0000_0000_0000_0000_0100_0000;
const STATE_COMPACT: u32 = 0b0000_0000_0000_0000_0000_0000_0010_0000;
/// Read a UTF-8 string from a pointer and change the given size if needed.
/// Read a UTF-8 string from a pointer and change the given size.
pub unsafe fn read_utf8_from_str(
object_pointer: *mut pyo3::ffi::PyObject,
size: &mut Py_ssize_t,
@ -43,6 +41,8 @@ pub unsafe fn read_utf8_from_str(
*size = (*object_pointer.cast::<PyCompactUnicodeObject>()).utf8_length;
(*object_pointer.cast::<PyCompactUnicodeObject>()).utf8 as *const u8
} else {
PyUnicode_AsUTF8AndSize(object_pointer, size).cast::<u8>()
*size = PyUnicode_GetLength(object_pointer);
let bytes = PyUnicode_AsUTF8String(object_pointer);
PyBytes_AsString(bytes) as *const u8
}
}

View File

@ -1,7 +1,8 @@
use crate::string;
use pyo3::ffi::{
PyDict_New, PyFloat_FromDouble, PyImport_ImportModule, PyList_New, PyLong_FromLongLong,
PyMapping_GetItemString, PyObject, PyObject_GenericGetDict, PyTuple_New, PyTypeObject,
PyUnicode_New, Py_DECREF, Py_None, Py_TYPE, Py_True,
PyMapping_GetItemString, PyObject, PyObject_GetAttrString, PyTuple_New, PyTypeObject,
PyUnicode_FromString, Py_DECREF, Py_None, Py_TYPE, Py_True,
};
use std::{os::raw::c_char, sync::Once};
@ -24,7 +25,7 @@ static INIT: Once = Once::new();
#[cold]
unsafe fn look_up_enum_type() -> *mut PyTypeObject {
let module = PyImport_ImportModule("enum\0".as_ptr().cast::<c_char>());
let module_dict = PyObject_GenericGetDict(module, std::ptr::null_mut());
let module_dict = PyObject_GetAttrString(module, "__dict__\0".as_ptr().cast::<c_char>());
let ptr = PyMapping_GetItemString(module_dict, "EnumMeta\0".as_ptr().cast::<c_char>())
.cast::<PyTypeObject>();
Py_DECREF(module_dict);
@ -32,13 +33,22 @@ unsafe fn look_up_enum_type() -> *mut PyTypeObject {
ptr
}
pub(crate) unsafe fn get_type_name(object_type: *mut pyo3::ffi::PyTypeObject) -> String {
let type_name =
PyObject_GetAttrString(object_type as _, "__name__\0".as_ptr().cast::<c_char>());
let mut str_size: pyo3::ffi::Py_ssize_t = 0;
let uni = string::read_utf8_from_str(type_name, &mut str_size);
let bytes = std::slice::from_raw_parts(uni, str_size as usize).to_vec();
String::from_utf8_unchecked(bytes)
}
/// Set empty type object pointers with their actual values.
/// We need these Python-side type objects for direct comparison during conversion to serde types
/// NOTE. This function should be called before any serialization logic
pub fn init() {
INIT.call_once(|| unsafe {
TRUE = Py_True();
STR_TYPE = Py_TYPE(PyUnicode_New(0, 255));
STR_TYPE = Py_TYPE(PyUnicode_FromString("".as_ptr().cast::<c_char>()));
DICT_TYPE = Py_TYPE(PyDict_New());
TUPLE_TYPE = Py_TYPE(PyTuple_New(0_isize));
LIST_TYPE = Py_TYPE(PyList_New(0_isize));

View File

@ -3,7 +3,7 @@
# (workaround the fact that setup.py does not honor pyproject.toml)
skipsdist = True
envlist = py{36,37,38,39,310}
envlist = py{36,37,38,39,310,311}
[testenv]
deps =
@ -17,15 +17,14 @@ commands =
[testenv:build-sdist]
deps =
setuptools-rust
maturin
commands =
./build-sdist.sh
maturin build --sdist
[testenv:build-wheel]
passenv =
PYTHON_SYS_EXECUTABLE
deps =
setuptools-rust
wheel
maturin
commands =
python setup.py bdist_wheel
maturin build