From 1d3f2d16ee3145ae3bb082bda0bdeb80f2892532 Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Fri, 3 May 2024 11:01:02 +0200 Subject: [PATCH 1/2] Upgrade and drop Python 3.7 --- .github/workflows/ci.yml | 14 +++--- Cargo.lock | 96 ++++++++++++++++++++++++---------------- Cargo.toml | 6 +-- README.md | 15 +++++++ pyproject.toml | 3 +- requirements.txt | 10 ++--- src/lib.rs | 18 ++++---- 7 files changed, 97 insertions(+), 65 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 323bec2..204088e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,7 +47,7 @@ jobs: uses: PyO3/maturin-action@v1 with: target: ${{ matrix.target }} - args: --release --out dist -i 3.7 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 + args: --release --out dist -i 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 sccache: "true" manylinux: auto - name: Install and test @@ -79,7 +79,7 @@ jobs: rust-toolchain: stable target: ${{ matrix.target }} manylinux: auto - args: --release --out dist -i 3.7 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 + args: --release --out dist -i 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 - uses: uraimo/run-on-arch-action@v2.7.2 if: matrix.target != 'ppc64' name: Install built wheel @@ -120,7 +120,7 @@ jobs: rust-toolchain: stable target: ${{ matrix.target }} manylinux: musllinux_1_2 - args: --release --out dist -i 3.7 3.8 3.9 3.10 3.11 3.12 + args: --release --out dist -i 3.8 3.9 3.10 3.11 3.12 - name: Install built wheel if: matrix.target == 'x86_64-unknown-linux-musl' uses: addnab/docker-run-action@v3 @@ -157,7 +157,7 @@ jobs: rust-toolchain: stable target: ${{ matrix.platform.target }} manylinux: musllinux_1_2 - args: --release --out dist -i 3.7 3.8 3.9 3.10 3.11 3.12 + args: --release --out dist -i 3.8 3.9 3.10 3.11 3.12 - name: Upload wheels uses: actions/upload-artifact@v3 with: @@ -171,9 +171,9 @@ jobs: matrix: platform: - target: x64 - interpreter: 3.7 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 + interpreter: 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 - target: x86 - interpreter: 3.7 3.8 3.9 3.10 3.11 + interpreter: 3.8 3.9 3.10 3.11 steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 @@ -211,7 +211,7 @@ jobs: uses: PyO3/maturin-action@v1 with: target: x86_64 - args: --release --out dist -i 3.7 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 + args: --release --out dist -i 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 sccache: "true" - name: Build wheels - universal2 uses: PyO3/maturin-action@v1 diff --git a/Cargo.lock b/Cargo.lock index dd22de4..a3fb712 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + [[package]] name = "block-buffer" version = "0.10.4" @@ -44,6 +50,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "crypto-common" version = "0.1.6" @@ -85,17 +97,23 @@ dependencies = [ "wasi", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "indoc" -version = "1.0.9" +version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" +checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" [[package]] name = "libc" -version = "0.2.148" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "lock_api" @@ -109,9 +127,9 @@ dependencies = [ [[package]] name = "mac_address" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4863ee94f19ed315bf3bc00299338d857d4b5bc856af375cc97d237382ad3856" +checksum = "5aa12182b93606fff55b70a5cfe6130eaf7407c2ea4f2c2bcc8b113b67c9928f" dependencies = [ "nix", "winapi", @@ -127,15 +145,6 @@ dependencies = [ "digest", ] -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] - [[package]] name = "memoffset" version = "0.9.0" @@ -147,15 +156,15 @@ dependencies = [ [[package]] name = "nix" -version = "0.23.2" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" +checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ - "bitflags", - "cc", + "bitflags 2.5.0", "cfg-if", + "cfg_aliases", "libc", - "memoffset 0.6.5", + "memoffset", ] [[package]] @@ -187,6 +196,12 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "portable-atomic" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -204,15 +219,16 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.19.2" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e681a6cfdc4adcc93b4d3cf993749a4552018ee0a9b65fc0ccfad74352c72a38" +checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" dependencies = [ "cfg-if", "indoc", "libc", - "memoffset 0.9.0", + "memoffset", "parking_lot", + "portable-atomic", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", @@ -221,9 +237,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.19.2" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076c73d0bc438f7a4ef6fdd0c3bb4732149136abd952b110ac93e4edb13a6ba5" +checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" dependencies = [ "once_cell", "python3-dll-a", @@ -232,9 +248,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.19.2" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53cee42e77ebe256066ba8aa77eff722b3bb91f3419177cf4cd0f304d3284d9" +checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" dependencies = [ "libc", "pyo3-build-config", @@ -242,9 +258,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.19.2" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfeb4c99597e136528c6dd7d5e3de5434d1ceaf487436a3f03b2d56b6fc9efd1" +checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -254,11 +270,13 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.19.2" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "947dc12175c254889edc0c02e399476c2f652b4b9ebd123aa655c224de259536" +checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" dependencies = [ + "heck", "proc-macro2", + "pyo3-build-config", "quote", "syn", ] @@ -317,7 +335,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -340,9 +358,9 @@ checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "syn" -version = "1.0.109" +version = "2.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" dependencies = [ "proc-macro2", "quote", @@ -369,15 +387,15 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unindent" -version = "0.1.11" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c" +checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" [[package]] name = "uuid" -version = "1.4.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" +checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" dependencies = [ "atomic", "getrandom", @@ -388,7 +406,7 @@ dependencies = [ [[package]] name = "uuid-utils" -version = "0.5.0" +version = "0.6.1" dependencies = [ "mac_address", "pyo3", diff --git a/Cargo.toml b/Cargo.toml index 60008ef..1b83336 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ name = "uuid_utils" crate-type = ["cdylib"] [dependencies] -mac_address = "1.1.5" -pyo3 = { version = "0.19.2", features = ["extension-module", "generate-import-lib"] } +mac_address = "1.1.6" +pyo3 = { version = "0.21.2", features = ["extension-module", "generate-import-lib"] } rand = "0.8.5" -uuid = { version = "1.4.1", features = ["v1", "v3", "v4", "v5", "v6", "v7", "v8", "fast-rng"]} +uuid = { version = "1.8.0", features = ["v1", "v3", "v4", "v5", "v6", "v7", "v8", "fast-rng"]} diff --git a/README.md b/README.md index ca9ece4..06fa90a 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,21 @@ UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d') UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e') ``` +## Compat module + +In some cases you might need `UUID` instances to be returned +from the standrad-library `uuid`, not a custom `UUID` class. +In that case you can use the `uuid_utils.compat` which comes with a performance penalty +in comparison with the `uuid_utils` default behaviour, but still faster than the standard-library. + +```py +>>> import uuid_utils.compat as uuid + +>>> # make a random UUID +>>> uuid.uuid4() +UUID('ffe95fcc-b818-4aca-a350-e0a35b9de6ec') +``` + ## Benchmarks | Benchmark | Min | Max | Mean | Min (+) | Max (+) | Mean (+) | diff --git a/pyproject.toml b/pyproject.toml index 27f251f..1847f32 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,13 +7,12 @@ name = "uuid_utils" description = "Drop-in replacement for Python UUID in Rust" authors = [{ name = "Amin Alaee", email = "me@aminalaee.dev" }] keywords = ["rust", "uuid"] -requires-python = ">=3.7" +requires-python = ">=3.8" classifiers = [ "Development Status :: 3 - Alpha", "Programming Language :: Python", "Programming Language :: Python :: 3", "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", diff --git a/requirements.txt b/requirements.txt index cc5eb75..4c33526 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -black==23.1.0 -isort==5.11.5 -mypy==1.1.1 -pytest==7.2.2 -ruff==0.0.259 +black==24.4.2 +isort==5.13.2 +mypy==1.10.0 +pytest==8.2.0 +ruff==0.4.2 diff --git a/src/lib.rs b/src/lib.rs index 041f39f..aa32675 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,8 +42,8 @@ impl UUID { #[new] fn new( hex: Option<&str>, - bytes: Option<&PyBytes>, - bytes_le: Option<&PyBytes>, + bytes: Option<&Bound<'_, PyBytes>>, + bytes_le: Option<&Bound<'_, PyBytes>>, fields: Option<(u32, u16, u16, u8, u8, u64)>, int: Option, version: Option, @@ -124,7 +124,7 @@ impl UUID { (self.__str__(),) } - pub fn __deepcopy__(&self, py: Python, _memo: &PyDict) -> Py { + pub fn __deepcopy__(&self, py: Python, _memo: &Bound<'_, PyDict>) -> Py { self.clone().into_py(py) } @@ -139,13 +139,13 @@ impl UUID { } #[getter] - fn bytes_le<'py>(&self, py: Python<'py>) -> &'py PyBytes { + fn bytes_le<'py>(&self, py: Python<'py>) -> Bound<'py, PyBytes> { let bytes = *self.uuid.as_bytes(); let bytes = [ bytes[3], bytes[2], bytes[1], bytes[0], bytes[5], bytes[4], bytes[7], bytes[6], bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15], ]; - PyBytes::new(py, &bytes) + PyBytes::new_bound(py, &bytes) } #[getter] @@ -255,7 +255,7 @@ impl UUID { } #[staticmethod] - fn from_bytes(bytes: &PyBytes) -> PyResult { + fn from_bytes(bytes: &Bound<'_, PyBytes>) -> PyResult { let bytes: Bytes = bytes.extract()?; Ok(UUID { uuid: Uuid::from_bytes(bytes), @@ -263,7 +263,7 @@ impl UUID { } #[staticmethod] - fn from_bytes_le(bytes: &PyBytes) -> PyResult { + fn from_bytes_le(bytes: &Bound<'_, PyBytes>) -> PyResult { let bytes: Bytes = bytes.extract()?; Ok(UUID { uuid: Uuid::from_bytes_le(bytes), @@ -372,7 +372,7 @@ fn uuid7(timestamp: Option) -> PyResult { } #[pyfunction] -fn uuid8(bytes: &PyBytes) -> PyResult { +fn uuid8(bytes: &Bound<'_, PyBytes>) -> PyResult { let bytes: Bytes = bytes.extract()?; Ok(UUID { uuid: Uuid::new_v8(bytes), @@ -411,7 +411,7 @@ fn getnode() -> PyResult { } #[pymodule] -fn _uuid_utils(_py: Python, m: &PyModule) -> PyResult<()> { +fn _uuid_utils(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add("__version__", env!("CARGO_PKG_VERSION"))?; m.add_class::()?; m.add_function(wrap_pyfunction!(uuid1, m)?)?; From 772188a44f714c75c390e27338be051c1af13fe3 Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Fri, 3 May 2024 11:04:55 +0200 Subject: [PATCH 2/2] update --- python/uuid_utils/__init__.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/python/uuid_utils/__init__.pyi b/python/uuid_utils/__init__.pyi index 6226226..6ee0189 100644 --- a/python/uuid_utils/__init__.pyi +++ b/python/uuid_utils/__init__.pyi @@ -112,6 +112,7 @@ class UUID: """Get UUID timestamp milliseconds since epoch. Only works for UUID versions 1, 6 and 7, otherwise raises ValueError.""" ... + @property def urn(self) -> str: ... @property