sublime-search 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,181 @@
1
+ # This file is autogenerated by maturin v1.8.2
2
+ # To update, run
3
+ #
4
+ # maturin generate-ci github
5
+ #
6
+ name: CI
7
+
8
+ on:
9
+ push:
10
+ branches:
11
+ - main
12
+ - master
13
+ tags:
14
+ - '*'
15
+ pull_request:
16
+ workflow_dispatch:
17
+
18
+ permissions:
19
+ contents: read
20
+
21
+ jobs:
22
+ linux:
23
+ runs-on: ${{ matrix.platform.runner }}
24
+ strategy:
25
+ matrix:
26
+ platform:
27
+ - runner: ubuntu-22.04
28
+ target: x86_64
29
+ - runner: ubuntu-22.04
30
+ target: x86
31
+ - runner: ubuntu-22.04
32
+ target: aarch64
33
+ - runner: ubuntu-22.04
34
+ target: armv7
35
+ - runner: ubuntu-22.04
36
+ target: s390x
37
+ - runner: ubuntu-22.04
38
+ target: ppc64le
39
+ steps:
40
+ - uses: actions/checkout@v4
41
+ - uses: actions/setup-python@v5
42
+ with:
43
+ python-version: 3.x
44
+ - name: Build wheels
45
+ uses: PyO3/maturin-action@v1
46
+ with:
47
+ target: ${{ matrix.platform.target }}
48
+ args: --release --out dist --find-interpreter
49
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
50
+ manylinux: auto
51
+ - name: Upload wheels
52
+ uses: actions/upload-artifact@v4
53
+ with:
54
+ name: wheels-linux-${{ matrix.platform.target }}
55
+ path: dist
56
+
57
+ musllinux:
58
+ runs-on: ${{ matrix.platform.runner }}
59
+ strategy:
60
+ matrix:
61
+ platform:
62
+ - runner: ubuntu-22.04
63
+ target: x86_64
64
+ - runner: ubuntu-22.04
65
+ target: x86
66
+ - runner: ubuntu-22.04
67
+ target: aarch64
68
+ - runner: ubuntu-22.04
69
+ target: armv7
70
+ steps:
71
+ - uses: actions/checkout@v4
72
+ - uses: actions/setup-python@v5
73
+ with:
74
+ python-version: 3.x
75
+ - name: Build wheels
76
+ uses: PyO3/maturin-action@v1
77
+ with:
78
+ target: ${{ matrix.platform.target }}
79
+ args: --release --out dist --find-interpreter
80
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
81
+ manylinux: musllinux_1_2
82
+ - name: Upload wheels
83
+ uses: actions/upload-artifact@v4
84
+ with:
85
+ name: wheels-musllinux-${{ matrix.platform.target }}
86
+ path: dist
87
+
88
+ windows:
89
+ runs-on: ${{ matrix.platform.runner }}
90
+ strategy:
91
+ matrix:
92
+ platform:
93
+ - runner: windows-latest
94
+ target: x64
95
+ - runner: windows-latest
96
+ target: x86
97
+ steps:
98
+ - uses: actions/checkout@v4
99
+ - uses: actions/setup-python@v5
100
+ with:
101
+ python-version: 3.x
102
+ architecture: ${{ matrix.platform.target }}
103
+ - name: Build wheels
104
+ uses: PyO3/maturin-action@v1
105
+ with:
106
+ target: ${{ matrix.platform.target }}
107
+ args: --release --out dist --find-interpreter
108
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
109
+ - name: Upload wheels
110
+ uses: actions/upload-artifact@v4
111
+ with:
112
+ name: wheels-windows-${{ matrix.platform.target }}
113
+ path: dist
114
+
115
+ macos:
116
+ runs-on: ${{ matrix.platform.runner }}
117
+ strategy:
118
+ matrix:
119
+ platform:
120
+ - runner: macos-13
121
+ target: x86_64
122
+ - runner: macos-14
123
+ target: aarch64
124
+ steps:
125
+ - uses: actions/checkout@v4
126
+ - uses: actions/setup-python@v5
127
+ with:
128
+ python-version: 3.x
129
+ - name: Build wheels
130
+ uses: PyO3/maturin-action@v1
131
+ with:
132
+ target: ${{ matrix.platform.target }}
133
+ args: --release --out dist --find-interpreter
134
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
135
+ - name: Upload wheels
136
+ uses: actions/upload-artifact@v4
137
+ with:
138
+ name: wheels-macos-${{ matrix.platform.target }}
139
+ path: dist
140
+
141
+ sdist:
142
+ runs-on: ubuntu-latest
143
+ steps:
144
+ - uses: actions/checkout@v4
145
+ - name: Build sdist
146
+ uses: PyO3/maturin-action@v1
147
+ with:
148
+ command: sdist
149
+ args: --out dist
150
+ - name: Upload sdist
151
+ uses: actions/upload-artifact@v4
152
+ with:
153
+ name: wheels-sdist
154
+ path: dist
155
+
156
+ release:
157
+ name: Release
158
+ runs-on: ubuntu-latest
159
+ if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
160
+ needs: [linux, musllinux, windows, macos, sdist]
161
+ permissions:
162
+ # Use to sign the release artifacts
163
+ id-token: write
164
+ # Used to upload release artifacts
165
+ contents: write
166
+ # Used to generate artifact attestation
167
+ attestations: write
168
+ steps:
169
+ - uses: actions/download-artifact@v4
170
+ - name: Generate artifact attestation
171
+ uses: actions/attest-build-provenance@v1
172
+ with:
173
+ subject-path: 'wheels-*/*'
174
+ - name: Publish to PyPI
175
+ if: ${{ startsWith(github.ref, 'refs/tags/') }}
176
+ uses: PyO3/maturin-action@v1
177
+ env:
178
+ MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
179
+ with:
180
+ command: upload
181
+ args: --non-interactive --skip-existing wheels-*/*
@@ -0,0 +1,72 @@
1
+ /target
2
+
3
+ # Byte-compiled / optimized / DLL files
4
+ __pycache__/
5
+ .pytest_cache/
6
+ *.py[cod]
7
+
8
+ # C extensions
9
+ *.so
10
+
11
+ # Distribution / packaging
12
+ .Python
13
+ .venv/
14
+ env/
15
+ bin/
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ eggs/
20
+ lib/
21
+ lib64/
22
+ parts/
23
+ sdist/
24
+ var/
25
+ include/
26
+ man/
27
+ venv/
28
+ *.egg-info/
29
+ .installed.cfg
30
+ *.egg
31
+
32
+ # Installer logs
33
+ pip-log.txt
34
+ pip-delete-this-directory.txt
35
+ pip-selfcheck.json
36
+
37
+ # Unit test / coverage reports
38
+ htmlcov/
39
+ .tox/
40
+ .coverage
41
+ .cache
42
+ nosetests.xml
43
+ coverage.xml
44
+
45
+ # Translations
46
+ *.mo
47
+
48
+ # Mr Developer
49
+ .mr.developer.cfg
50
+ .project
51
+ .pydevproject
52
+
53
+ # Rope
54
+ .ropeproject
55
+
56
+ # Django stuff:
57
+ *.log
58
+ *.pot
59
+
60
+ .DS_Store
61
+
62
+ # Sphinx documentation
63
+ docs/_build/
64
+
65
+ # PyCharm
66
+ .idea/
67
+
68
+ # VSCode
69
+ .vscode/
70
+
71
+ # Pyenv
72
+ .python-version
@@ -0,0 +1,171 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "autocfg"
7
+ version = "1.4.0"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
10
+
11
+ [[package]]
12
+ name = "cfg-if"
13
+ version = "1.0.0"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
16
+
17
+ [[package]]
18
+ name = "heck"
19
+ version = "0.5.0"
20
+ source = "registry+https://github.com/rust-lang/crates.io-index"
21
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
22
+
23
+ [[package]]
24
+ name = "indoc"
25
+ version = "2.0.5"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5"
28
+
29
+ [[package]]
30
+ name = "libc"
31
+ version = "0.2.170"
32
+ source = "registry+https://github.com/rust-lang/crates.io-index"
33
+ checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828"
34
+
35
+ [[package]]
36
+ name = "memoffset"
37
+ version = "0.9.1"
38
+ source = "registry+https://github.com/rust-lang/crates.io-index"
39
+ checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
40
+ dependencies = [
41
+ "autocfg",
42
+ ]
43
+
44
+ [[package]]
45
+ name = "once_cell"
46
+ version = "1.20.3"
47
+ source = "registry+https://github.com/rust-lang/crates.io-index"
48
+ checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
49
+
50
+ [[package]]
51
+ name = "portable-atomic"
52
+ version = "1.11.0"
53
+ source = "registry+https://github.com/rust-lang/crates.io-index"
54
+ checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
55
+
56
+ [[package]]
57
+ name = "proc-macro2"
58
+ version = "1.0.93"
59
+ source = "registry+https://github.com/rust-lang/crates.io-index"
60
+ checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
61
+ dependencies = [
62
+ "unicode-ident",
63
+ ]
64
+
65
+ [[package]]
66
+ name = "pyo3"
67
+ version = "0.23.5"
68
+ source = "registry+https://github.com/rust-lang/crates.io-index"
69
+ checksum = "7778bffd85cf38175ac1f545509665d0b9b92a198ca7941f131f85f7a4f9a872"
70
+ dependencies = [
71
+ "cfg-if",
72
+ "indoc",
73
+ "libc",
74
+ "memoffset",
75
+ "once_cell",
76
+ "portable-atomic",
77
+ "pyo3-build-config",
78
+ "pyo3-ffi",
79
+ "pyo3-macros",
80
+ "unindent",
81
+ ]
82
+
83
+ [[package]]
84
+ name = "pyo3-build-config"
85
+ version = "0.23.5"
86
+ source = "registry+https://github.com/rust-lang/crates.io-index"
87
+ checksum = "94f6cbe86ef3bf18998d9df6e0f3fc1050a8c5efa409bf712e661a4366e010fb"
88
+ dependencies = [
89
+ "once_cell",
90
+ "target-lexicon",
91
+ ]
92
+
93
+ [[package]]
94
+ name = "pyo3-ffi"
95
+ version = "0.23.5"
96
+ source = "registry+https://github.com/rust-lang/crates.io-index"
97
+ checksum = "e9f1b4c431c0bb1c8fb0a338709859eed0d030ff6daa34368d3b152a63dfdd8d"
98
+ dependencies = [
99
+ "libc",
100
+ "pyo3-build-config",
101
+ ]
102
+
103
+ [[package]]
104
+ name = "pyo3-macros"
105
+ version = "0.23.5"
106
+ source = "registry+https://github.com/rust-lang/crates.io-index"
107
+ checksum = "fbc2201328f63c4710f68abdf653c89d8dbc2858b88c5d88b0ff38a75288a9da"
108
+ dependencies = [
109
+ "proc-macro2",
110
+ "pyo3-macros-backend",
111
+ "quote",
112
+ "syn",
113
+ ]
114
+
115
+ [[package]]
116
+ name = "pyo3-macros-backend"
117
+ version = "0.23.5"
118
+ source = "registry+https://github.com/rust-lang/crates.io-index"
119
+ checksum = "fca6726ad0f3da9c9de093d6f116a93c1a38e417ed73bf138472cf4064f72028"
120
+ dependencies = [
121
+ "heck",
122
+ "proc-macro2",
123
+ "pyo3-build-config",
124
+ "quote",
125
+ "syn",
126
+ ]
127
+
128
+ [[package]]
129
+ name = "quote"
130
+ version = "1.0.38"
131
+ source = "registry+https://github.com/rust-lang/crates.io-index"
132
+ checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
133
+ dependencies = [
134
+ "proc-macro2",
135
+ ]
136
+
137
+ [[package]]
138
+ name = "sublime_search"
139
+ version = "0.1.0"
140
+ dependencies = [
141
+ "pyo3",
142
+ ]
143
+
144
+ [[package]]
145
+ name = "syn"
146
+ version = "2.0.98"
147
+ source = "registry+https://github.com/rust-lang/crates.io-index"
148
+ checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1"
149
+ dependencies = [
150
+ "proc-macro2",
151
+ "quote",
152
+ "unicode-ident",
153
+ ]
154
+
155
+ [[package]]
156
+ name = "target-lexicon"
157
+ version = "0.12.16"
158
+ source = "registry+https://github.com/rust-lang/crates.io-index"
159
+ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
160
+
161
+ [[package]]
162
+ name = "unicode-ident"
163
+ version = "1.0.17"
164
+ source = "registry+https://github.com/rust-lang/crates.io-index"
165
+ checksum = "00e2473a93778eb0bad35909dff6a10d28e63f792f16ed15e404fca9d5eeedbe"
166
+
167
+ [[package]]
168
+ name = "unindent"
169
+ version = "0.2.3"
170
+ source = "registry+https://github.com/rust-lang/crates.io-index"
171
+ checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce"
@@ -0,0 +1,12 @@
1
+ [package]
2
+ name = "sublime_search"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
+ [lib]
8
+ name = "sublime_search"
9
+ crate-type = ["cdylib"]
10
+
11
+ [dependencies]
12
+ pyo3 = { version = "0.23.3", features = ["extension-module"] }
@@ -0,0 +1,35 @@
1
+ Metadata-Version: 2.4
2
+ Name: sublime-search
3
+ Version: 0.1.0
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
9
+
10
+ # sublime-search
11
+
12
+ A simple, fast, Rust implementation of sublime-text style fuzzy matching for Python.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pip install sublime-search
18
+ uv add sublime-search
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```python
24
+ import sublime_search
25
+
26
+ # Check if a pattern matches a string with a score
27
+ is_match, score = sublime_search.fuzzy_match("abc", "abcdef")
28
+ print(f"Match: {is_match}, Score: {score}")
29
+
30
+ # Find best matching strings from a list of candidates
31
+ results = sublime_search.get_best_matches("abc", ["abcdef", "xabc", "testing"])
32
+ for candidate, score in results:
33
+ print(f"{candidate}: {score}")
34
+ ```
35
+
@@ -0,0 +1,25 @@
1
+ # sublime-search
2
+
3
+ A simple, fast, Rust implementation of sublime-text style fuzzy matching for Python.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install sublime-search
9
+ uv add sublime-search
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```python
15
+ import sublime_search
16
+
17
+ # Check if a pattern matches a string with a score
18
+ is_match, score = sublime_search.fuzzy_match("abc", "abcdef")
19
+ print(f"Match: {is_match}, Score: {score}")
20
+
21
+ # Find best matching strings from a list of candidates
22
+ results = sublime_search.get_best_matches("abc", ["abcdef", "xabc", "testing"])
23
+ for candidate, score in results:
24
+ print(f"{candidate}: {score}")
25
+ ```
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["maturin>=1.8,<2.0"]
3
+ build-backend = "maturin"
4
+
5
+ [project]
6
+ name = "sublime-search"
7
+ requires-python = ">=3.11"
8
+ classifiers = [
9
+ "Programming Language :: Rust",
10
+ "Programming Language :: Python :: Implementation :: CPython",
11
+ "Programming Language :: Python :: Implementation :: PyPy",
12
+ ]
13
+ dynamic = ["version"]
14
+
15
+ [tool.maturin]
16
+ features = ["pyo3/extension-module"]
17
+ python-source = "python"
18
+ module-name = "sublime_search._sublime_search"
19
+
20
+ [dependency-groups]
21
+ dev = ["pytest", "pytest-cov"]
22
+
23
+ docs = [
24
+ "mkdocs-mknodes",
25
+ "mkdocs-material",
26
+ # Only add below (Copier)
27
+ ]
@@ -0,0 +1,59 @@
1
+ from __future__ import annotations
2
+
3
+ # Import the Rust-compiled extension
4
+ from ._sublime_search import fuzzy_match as _fuzzy_match
5
+ from ._sublime_search import get_best_matches as _get_best_matches
6
+
7
+
8
+ def fuzzy_match(
9
+ pattern: str,
10
+ instring: str,
11
+ adj_bonus: int = 5,
12
+ sep_bonus: int = 10,
13
+ camel_bonus: int = 10,
14
+ lead_penalty: int = -3,
15
+ max_lead_penalty: int = -9,
16
+ unmatched_penalty: int = -1,
17
+ ) -> tuple[bool, int]:
18
+ """Return match boolean and match score.
19
+
20
+ Args:
21
+ pattern: the pattern to be matched
22
+ instring: the containing string to search against
23
+ adj_bonus: bonus for adjacent matches
24
+ sep_bonus: bonus if match occurs after a separator
25
+ camel_bonus: bonus if match is uppercase
26
+ lead_penalty: penalty applied for each letter before 1st match
27
+ max_lead_penalty: maximum total lead_penalty
28
+ unmatched_penalty: penalty for each unmatched letter
29
+
30
+ Returns:
31
+ A tuple with match truthiness and score
32
+ """
33
+ return _fuzzy_match(
34
+ pattern,
35
+ instring,
36
+ adj_bonus,
37
+ sep_bonus,
38
+ camel_bonus,
39
+ lead_penalty,
40
+ max_lead_penalty,
41
+ unmatched_penalty,
42
+ )
43
+
44
+
45
+ def get_best_matches(search_string: str, candidates: list[str]) -> list[tuple[str, int]]:
46
+ """Return sorted list of all matches.
47
+
48
+ Args:
49
+ search_string: The pattern to search for
50
+ candidates: List of strings to search through
51
+
52
+ Returns:
53
+ List of tuples containing (candidate, score) sorted by descending score
54
+ """
55
+ return _get_best_matches(search_string, candidates)
56
+
57
+
58
+ # Make these the public API
59
+ __all__ = ["fuzzy_match", "get_best_matches"]
File without changes