Skip to content

Commit

Permalink
update python
Browse files Browse the repository at this point in the history
  • Loading branch information
Lips7 committed Jun 11, 2024
1 parent 21d48d9 commit 7759d60
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build]
rustflags = ["-Z", "threads=8"]
rustflags = ["-C", "target-cpu=native", "-Z", "threads=8"]
22 changes: 4 additions & 18 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,13 @@ jobs:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
- runner: ubuntu-latest
target: s390x
- runner: ubuntu-latest
target: ppc64le
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.10
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
Expand All @@ -73,17 +65,13 @@ jobs:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.10
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
Expand All @@ -106,13 +94,11 @@ jobs:
platform:
- runner: windows-latest
target: x64
- runner: windows-latest
target: x86
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.10
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
Expand Down Expand Up @@ -141,7 +127,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.10
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion matcher_py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ crate-type = ["cdylib"]
[dependencies]
matcher_rs = { path = "../matcher_rs" }
numpy = "0.21.0"
pyo3 = { version = "0.21.2", features = ["extension-module", "abi3-py310", "serde"] }
pyo3 = { version = "0.21.2", features = ["extension-module", "abi3-py38", "serde"] }
rmp-serde = "1.3.0"
serde = "1.0.203"

Expand Down
2 changes: 2 additions & 0 deletions matcher_py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ classifiers = [
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand Down
10 changes: 5 additions & 5 deletions matcher_py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ impl Matcher {
fn is_match(&self, _py: Python, text: &Bound<'_, PyAny>) -> bool {
text.downcast::<PyString>().map_or(false, |text| {
self.matcher
.is_match(unsafe { text.to_str().unwrap_unchecked() })
.is_match(unsafe { text.to_cow().as_ref().unwrap_unchecked() })
})
}

#[pyo3(signature=(text))]
fn word_match(&self, _py: Python, text: &Bound<'_, PyAny>) -> HashMap<&str, String> {
text.downcast::<PyString>().map_or(HashMap::new(), |text| {
self.matcher
.word_match(unsafe { text.to_str().unwrap_unchecked() })
.word_match(unsafe { text.to_cow().as_ref().unwrap_unchecked() })
})
}

Expand All @@ -103,7 +103,7 @@ impl Matcher {
py,
&self
.matcher
.word_match_as_string(unsafe { text.to_str().unwrap_unchecked() }),
.word_match_as_string(unsafe { text.to_cow().as_ref().unwrap_unchecked() }),
)
})
.into()
Expand Down Expand Up @@ -229,15 +229,15 @@ impl SimpleMatcher {
fn is_match(&self, _py: Python, text: &Bound<'_, PyAny>) -> bool {
text.downcast::<PyString>().map_or(false, |text| {
self.simple_matcher
.is_match(unsafe { text.to_str().unwrap_unchecked() })
.is_match(unsafe { text.to_cow().as_ref().unwrap_unchecked() })
})
}

#[pyo3(signature=(text))]
fn simple_process(&self, _py: Python, text: &Bound<'_, PyAny>) -> Vec<SimpleResult> {
text.downcast::<PyString>().map_or(Vec::new(), |text| {
self.simple_matcher
.process(unsafe { text.to_str().unwrap_unchecked() })
.process(unsafe { text.to_cow().as_ref().unwrap_unchecked() })
.into_iter()
.map(|simple_result| SimpleResult(simple_result))
.collect::<Vec<_>>()
Expand Down

0 comments on commit 7759d60

Please sign in to comment.