diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 71457b7..564ae01 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,7 +1,7 @@ -# This file is autogenerated by maturin v1.11.5 +# This file is autogenerated by maturin v1.12.0 # To update, run # -# maturin generate-ci --pytest github +# maturin generate-ci github # name: CI @@ -53,31 +53,6 @@ jobs: with: name: wheels-linux-${{ matrix.platform.target }} path: dist - - name: pytest - if: ${{ startsWith(matrix.platform.target, 'x86_64') }} - shell: bash - run: | - set -e - python3 -m venv .venv - source .venv/bin/activate - pip install urlpattern --find-links dist --force-reinstall - pip install pytest - pytest - - name: pytest - if: ${{ !startsWith(matrix.platform.target, 'x86') && matrix.platform.target != 'ppc64' }} - uses: uraimo/run-on-arch-action@v2 - with: - arch: ${{ matrix.platform.target }} - distro: ubuntu22.04 - githubToken: ${{ github.token }} - install: | - apt-get update - apt-get install -y --no-install-recommends python3 python3-pip - pip3 install -U pip pytest - run: | - set -e - pip3 install urlpattern --find-links dist --force-reinstall - pytest musllinux: runs-on: ${{ matrix.platform.runner }} @@ -109,36 +84,6 @@ jobs: with: name: wheels-musllinux-${{ matrix.platform.target }} path: dist - - name: pytest - if: ${{ startsWith(matrix.platform.target, 'x86_64') }} - uses: addnab/docker-run-action@v3 - with: - image: alpine:latest - options: -v ${{ github.workspace }}:/io -w /io - run: | - set -e - apk add py3-pip py3-virtualenv - python3 -m virtualenv .venv - source .venv/bin/activate - pip install urlpattern --no-index --find-links dist --force-reinstall - pip install pytest - pytest - - name: pytest - if: ${{ !startsWith(matrix.platform.target, 'x86') }} - uses: uraimo/run-on-arch-action@v2 - with: - arch: ${{ matrix.platform.target }} - distro: alpine_latest - githubToken: ${{ github.token }} - install: | - apk add py3-virtualenv - run: | - set -e - python3 -m virtualenv .venv - source .venv/bin/activate - pip install pytest - pip install urlpattern --find-links dist --force-reinstall - pytest windows: runs-on: ${{ matrix.platform.runner }} @@ -171,15 +116,6 @@ jobs: with: name: wheels-windows-${{ matrix.platform.target }} path: dist - - name: pytest - shell: bash - run: | - set -e - python3 -m venv .venv - source .venv/Scripts/activate - pip install urlpattern --find-links dist --force-reinstall - pip install pytest - pytest macos: runs-on: ${{ matrix.platform.runner }} @@ -206,14 +142,6 @@ jobs: with: name: wheels-macos-${{ matrix.platform.target }} path: dist - - name: pytest - run: | - set -e - python3 -m venv .venv - source .venv/bin/activate - pip install urlpattern --find-links dist --force-reinstall - pip install pytest - pytest sdist: runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index 95c208f..c5e9a4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,12 +11,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "autocfg" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" - [[package]] name = "displaydoc" version = "0.2.5" @@ -145,20 +139,11 @@ dependencies = [ "icu_properties", ] -[[package]] -name = "indoc" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706" -dependencies = [ - "rustversion", -] - [[package]] name = "libc" -version = "0.2.180" +version = "0.2.182" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" [[package]] name = "litemap" @@ -168,18 +153,9 @@ checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" [[package]] name = "memchr" -version = "2.7.6" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" - -[[package]] -name = "memoffset" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" -dependencies = [ - "autocfg", -] +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "once_cell" @@ -195,9 +171,9 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "portable-atomic" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" [[package]] name = "potential_utf" @@ -219,35 +195,32 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.27.2" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab53c047fcd1a1d2a8820fe84f05d6be69e9526be40cb03b73f86b6b03e6d87d" +checksum = "14c738662e2181be11cb82487628404254902bb3225d8e9e99c31f3ef82a405c" dependencies = [ - "indoc", "libc", - "memoffset", "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", - "unindent", ] [[package]] name = "pyo3-build-config" -version = "0.27.2" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b455933107de8642b4487ed26d912c2d899dec6114884214a0b3bb3be9261ea6" +checksum = "f9ca0864a7dd3c133a7f3f020cbff2e12e88420da854c35540fd20ce2d60e435" dependencies = [ "target-lexicon", ] [[package]] name = "pyo3-ffi" -version = "0.27.2" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c85c9cbfaddf651b1221594209aed57e9e5cff63c4d11d1feead529b872a089" +checksum = "9dfc1956b709823164763a34cc42bbfd26b8730afa77809a3df8b94a3ae3b059" dependencies = [ "libc", "pyo3-build-config", @@ -255,9 +228,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.27.2" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a5b10c9bf9888125d917fb4d2ca2d25c8df94c7ab5a52e13313a07e050a3b02" +checksum = "29dc660ad948bae134d579661d08033fbb1918f4529c3bbe3257a68f2009ddf2" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -267,9 +240,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.27.2" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b51720d314836e53327f5871d4c0cfb4fb37cc2c4a11cc71907a86342c40f9" +checksum = "e78cd6c6d718acfcedf26c3d21fe0f053624368b0d44298c55d7138fde9331f7" dependencies = [ "heck", "proc-macro2", @@ -280,7 +253,7 @@ dependencies = [ [[package]] name = "python-urlpattern" -version = "0.1.8" +version = "0.1.9" dependencies = [ "pyo3", "urlpattern", @@ -297,9 +270,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.12.2" +version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" dependencies = [ "aho-corasick", "memchr", @@ -309,9 +282,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" dependencies = [ "aho-corasick", "memchr", @@ -320,15 +293,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" - -[[package]] -name = "rustversion" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" +checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c" [[package]] name = "serde" @@ -374,9 +341,9 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" [[package]] name = "syn" -version = "2.0.114" +version = "2.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +checksum = "6e614ed320ac28113fa64972c4262d5dbc89deacdfd00c34a3e4cea073243c12" dependencies = [ "proc-macro2", "quote", @@ -412,15 +379,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" - -[[package]] -name = "unindent" -version = "0.2.4" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3" +checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e" [[package]] name = "url" @@ -436,9 +397,9 @@ dependencies = [ [[package]] name = "urlpattern" -version = "0.5.2" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ffe0983283c841b6c6e9f116833a0061cc690c0eb67994d65bbdfa5cd3f24e" +checksum = "df16f50ef4cc145211879a3867ba757076b25dfee812040dcb0658bd9ae7904b" dependencies = [ "icu_properties", "regex", diff --git a/Cargo.toml b/Cargo.toml index bafa905..3ad3677 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "python-urlpattern" -version = "0.1.8" +version = "0.1.9" authors = ["방성범 (Bang Seongbeom) "] edition = "2024" description = "An implementation of the URL Pattern Standard for Python written in Rust." @@ -14,5 +14,5 @@ categories = ["web-programming"] crate-type = ["cdylib"] [dependencies] -pyo3 = "0.27.2" -deno_urlpattern = { package = "urlpattern", version = "0.5.2" } +pyo3 = "0.28.0" +deno_urlpattern = { package = "urlpattern", version = "0.6.0" } diff --git a/README.md b/README.md index 6616e5b..d7580b2 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,12 @@ print(result["pathname"]["groups"]["id"]) # output: 4163 ```py from urlpattern import URLPattern -pattern = URLPattern({"pathname": "/admin/*"}, "https://example.com") -print(pattern.test({"pathname": "/admin/main/"}, "https://example.com")) # output: True -print(pattern.test("/admin/main/", "https://example.com")) # output: True +pattern = URLPattern("b", "https://example.com/a/") +print(pattern.test("a/b", "https://example.com/")) # output: True +print(pattern.test("b", "https://example.com/a/")) # output: True +print( + pattern.test({"pathname": "b", "baseURL": "https://example.com/a/"}) +) # output: True ``` ### `ignoreCase` diff --git a/src/lib.rs b/src/lib.rs index 9e6e278..1dc8f6a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![allow(non_snake_case)] +use std::borrow::Cow; use std::collections::HashMap; use pyo3::{ @@ -201,13 +202,13 @@ pub enum UrlPatternInput<'py> { Init(Bound<'py, PyDict>), } -impl<'py> TryFrom> for deno_urlpattern::quirks::StringOrInit { +impl<'py> TryFrom> for deno_urlpattern::quirks::StringOrInit<'static> { type Error = pyo3::PyErr; fn try_from(input: UrlPatternInput<'py>) -> Result { Ok(match input { UrlPatternInput::String(pattern) => { - deno_urlpattern::quirks::StringOrInit::String(pattern) + deno_urlpattern::quirks::StringOrInit::String(Cow::Owned(pattern)) } UrlPatternInput::Init(init) => deno_urlpattern::quirks::StringOrInit::Init( deno_urlpattern::quirks::UrlPatternInit { @@ -254,7 +255,10 @@ impl<'py> TryFrom> for deno_urlpattern::quirks::StringOrIni } pub struct UrlPatternResult { - pub inputs: (deno_urlpattern::quirks::StringOrInit, Option), + pub inputs: ( + deno_urlpattern::quirks::StringOrInit<'static>, + Option, + ), pub protocol: UrlPatternComponentResult, pub username: UrlPatternComponentResult, pub password: UrlPatternComponentResult, @@ -278,7 +282,7 @@ impl<'py> IntoPyObject<'py> for UrlPatternResult { match string_or_init { deno_urlpattern::quirks::StringOrInit::String(string) => { - list.append(string).unwrap(); + list.append(string.into_owned()).unwrap(); } deno_urlpattern::quirks::StringOrInit::Init(init) => { let init_dict = PyDict::new(py); @@ -353,7 +357,7 @@ impl From for Error { } /// A Python module implemented in Rust. -#[pymodule(gil_used = false)] +#[pymodule] mod urlpattern { #[pymodule_export] use super::UrlPattern;