Skip to content

Commit

Permalink
Merge pull request #18 from rchildre3/update-pyo3_016-stable-rust
Browse files Browse the repository at this point in the history
Update PyO3 to 0.16 and to Rust stable channel
  • Loading branch information
thedrow committed Mar 23, 2022
2 parents d613378 + 5199227 commit a017457
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: python
dist: bionic
python:
- '3.6'
- '3.7'
- '3.8'
- '3.9'
- '3.10'
stages:
- test
- lint
Expand Down Expand Up @@ -52,7 +52,7 @@ before_cache:
- sudo rm -R $TRAVIS_BUILD_DIR/target/wheels

before_install:
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly --component clippy rustfmt
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --component clippy rustfmt

install: pip install -U tox maturin tox-pyo3 tox-travis

Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fastuuid"
version = "0.7.0"
version = "0.8.0"
authors = ["Omer Katz <[email protected]>"]
license = "BSD3"
description = "Python bindings to Rust's UUID library."
Expand All @@ -10,7 +10,7 @@ name = "fastuuid"
crate-type = ["cdylib"]

[dependencies.pyo3]
version = "0.14.5"
version = "0.16"
features = ["extension-module"]

[dependencies.uuid]
Expand All @@ -25,17 +25,17 @@ classifier = [
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"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",
"Topic :: Software Development :: Libraries :: Python Modules"
]
maintainer = "Omer Katz"
maintainer-email = "[email protected]"
requires-python = ">=3.6"
requires-python = ">=3.7"
project-url = { homepage = "https://github.com/thedrow/fastuuid/" }

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FastUUID is a library which provides CPython bindings to Rust's UUID library.

The provided API is exactly as Python's builtin UUID class.

It is supported on Python 3.5, 3.6, 3.7, 3.8 & 3.9.
It is supported on Python 3.7, 3.8, 3.9 & 3.10.

Why?
----
Expand Down
4 changes: 2 additions & 2 deletions build_or_release.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh

if [[ -z "${TRAVIS_TAG}" ]]; then
/opt/python/cp39-cp39/bin/maturin build --manylinux $MANYLINUX_VERSION --release -i /opt/python/cp39-cp39/bin/python -i /opt/python/cp38-cp38/bin/python -i /opt/python/cp37-cp37m/bin/python -i /opt/python/cp36-cp36m/bin/python
/opt/python/cp39-cp39/bin/maturin build --compatibility $MANYLINUX_VERSION --release -i /opt/python/cp310-cp310/bin/python -i /opt/python/cp39-cp39/bin/python -i /opt/python/cp38-cp38/bin/python -i /opt/python/cp37-cp37m/bin/python
ls -1 target/wheels/*.whl | xargs -I% auditwheel show %
else
/opt/python/cp39-cp39/bin/maturin publish ${NO_SDIST:+--no-sdist} --username $PYPI_USERNAME --manylinux $MANYLINUX_VERSION -i /opt/python/cp39-cp39/bin/python -i /opt/python/cp38-cp38/bin/python -i /opt/python/cp37-cp37m/bin/python -i /opt/python/cp36-cp36m/bin/python
/opt/python/cp39-cp39/bin/maturin publish ${NO_SDIST:+--no-sdist} --username $PYPI_USERNAME --compatibility $MANYLINUX_VERSION -i /opt/python/cp310-cp310/bin/python -i /opt/python/cp39-cp39/bin/python -i /opt/python/cp38-cp38/bin/python -i /opt/python/cp37-cp37m/bin/python
fi
2 changes: 1 addition & 1 deletion manylinux2014.dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM quay.io/pypa/manylinux2014_x86_64:latest

RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH /root/.cargo/bin:$PATH
RUN /opt/python/cp39-cp39/bin/pip install maturin

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["maturin"]
requires = ["maturin>=0.12,<0.13"]
build-backend = "maturin"
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

42 changes: 18 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ extern crate pyo3;
extern crate uuid;

use pyo3::class::basic::CompareOp;
use pyo3::class::{PyNumberProtocol, PyObjectProtocol};
use pyo3::exceptions::{PyTypeError, PyValueError};
use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyInt, PyTuple};
Expand All @@ -16,6 +15,7 @@ use uuid::{Builder, Uuid, Variant, Version};
fn fastuuid(_py: Python, m: &PyModule) -> PyResult<()> {
#[pyclass(freelist = 1000)]
#[derive(Clone)]
#[allow(clippy::upper_case_acronyms)]
struct UUID {
handle: Uuid,
}
Expand Down Expand Up @@ -94,7 +94,7 @@ fn fastuuid(_py: Python, m: &PyModule) -> PyResult<()> {
if f.len() != 6 {
Err(PyErr::new::<PyValueError, &str>("fields is not a 6-tuple"))
} else {
let time_low = match f.get_item(0).downcast::<PyInt>()?.extract::<u32>() {
let time_low = match f.get_item(0)?.downcast::<PyInt>()?.extract::<u32>() {
Ok(time_low) => Ok(u128::from(time_low)),
Err(_) => Err(PyErr::new::<PyValueError, &str>(
"field 1 out of range (need a 32-bit value)",
Expand All @@ -106,7 +106,7 @@ fn fastuuid(_py: Python, m: &PyModule) -> PyResult<()> {
}
let time_low = time_low.unwrap();

let time_mid = match f.get_item(1).downcast::<PyInt>()?.extract::<u16>() {
let time_mid = match f.get_item(1)?.downcast::<PyInt>()?.extract::<u16>() {
Ok(time_mid) => Ok(u128::from(time_mid)),
Err(_) => Err(PyErr::new::<PyValueError, &str>(
"field 2 out of range (need a 16-bit value)",
Expand All @@ -119,7 +119,7 @@ fn fastuuid(_py: Python, m: &PyModule) -> PyResult<()> {
let time_mid = time_mid.unwrap();

let time_high_version =
match f.get_item(2).downcast::<PyInt>()?.extract::<u16>() {
match f.get_item(2)?.downcast::<PyInt>()?.extract::<u16>() {
Ok(time_high_version) => Ok(u128::from(time_high_version)),
Err(_) => Err(PyErr::new::<PyValueError, &str>(
"field 3 out of range (need a 16-bit value)",
Expand All @@ -132,7 +132,7 @@ fn fastuuid(_py: Python, m: &PyModule) -> PyResult<()> {
let time_high_version = time_high_version.unwrap();

let clock_seq_hi_variant =
match f.get_item(3).downcast::<PyInt>()?.extract::<u8>() {
match f.get_item(3)?.downcast::<PyInt>()?.extract::<u8>() {
Ok(clock_seq_hi_variant) => Ok(u128::from(clock_seq_hi_variant)),
Err(_) => Err(PyErr::new::<PyValueError, &str>(
"field 4 out of range (need a 8-bit value)",
Expand All @@ -144,20 +144,20 @@ fn fastuuid(_py: Python, m: &PyModule) -> PyResult<()> {
};
let clock_seq_hi_variant = clock_seq_hi_variant.unwrap();

let clock_seq_low = match f.get_item(4).downcast::<PyInt>()?.extract::<u8>()
{
Ok(clock_seq_low) => Ok(u128::from(clock_seq_low)),
Err(_) => Err(PyErr::new::<PyValueError, &str>(
"field 5 out of range (need a 8-bit value)",
)),
};
let clock_seq_low =
match f.get_item(4)?.downcast::<PyInt>()?.extract::<u8>() {
Ok(clock_seq_low) => Ok(u128::from(clock_seq_low)),
Err(_) => Err(PyErr::new::<PyValueError, &str>(
"field 5 out of range (need a 8-bit value)",
)),
};

if let Err(e) = clock_seq_low {
return Err(e);
};
let clock_seq_low = clock_seq_low.unwrap();

let node = f.get_item(5).downcast::<PyInt>()?.extract::<u128>()?;
let node = f.get_item(5)?.downcast::<PyInt>()?.extract::<u128>()?;
if node >= (1 << 48) {
return Err(PyErr::new::<PyValueError, &str>(
"field 6 out of range (need a 48-bit value)",
Expand Down Expand Up @@ -299,10 +299,7 @@ fn fastuuid(_py: Python, m: &PyModule) -> PyResult<()> {
fn node(&self) -> u64 {
(self.int() & 0xffffffffffff) as u64
}
}

#[pyproto]
impl<'p> PyObjectProtocol<'p> for UUID {
fn __str__(&self) -> PyResult<String> {
Ok(self
.handle
Expand Down Expand Up @@ -334,30 +331,27 @@ fn fastuuid(_py: Python, m: &PyModule) -> PyResult<()> {

Ok(result)
}
}

#[pyproto]
impl<'p> PyNumberProtocol<'p> for UUID {
fn __int__(&self) -> PyResult<u128> {
Ok(self.int())
}
}

#[pyfn(m, name="uuid3")]
#[pyfn(m, name = "uuid3")]
fn uuid3(namespace: &UUID, name: &PyBytes) -> UUID {
UUID {
handle: Uuid::new_v3(&namespace.handle, name.as_bytes()),
}
}

#[pyfn(m, name="uuid5")]
#[pyfn(m, name = "uuid5")]
fn uuid5(namespace: &UUID, name: &PyBytes) -> UUID {
UUID {
handle: Uuid::new_v5(&namespace.handle, name.as_bytes()),
}
}

#[pyfn(m, name="uuid4_bulk")]
#[pyfn(m, name = "uuid4_bulk")]
fn uuid4_bulk(py: Python, n: usize) -> Vec<UUID> {
py.allow_threads(|| {
iter::repeat_with(|| UUID {
Expand All @@ -368,7 +362,7 @@ fn fastuuid(_py: Python, m: &PyModule) -> PyResult<()> {
})
}

#[pyfn(m, name="uuid4_as_strings_bulk")]
#[pyfn(m, name = "uuid4_as_strings_bulk")]
fn uuid4_as_strings_bulk(py: Python, n: usize) -> Vec<String> {
py.allow_threads(|| {
iter::repeat_with(|| {
Expand All @@ -382,7 +376,7 @@ fn fastuuid(_py: Python, m: &PyModule) -> PyResult<()> {
})
}

#[pyfn(m, name="uuid4")]
#[pyfn(m, name = "uuid4")]
fn uuid4() -> UUID {
UUID {
handle: Uuid::new_v4(),
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = py35, py36, py37, py38, py39, pypy3
envlist = py37, py38, py39, py310, pypy3
requires = tox-pyo3

[testenv]
Expand Down

0 comments on commit a017457

Please sign in to comment.