Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# This file is managed by Copier; DO NOT EDIT OR REMOVE.
_commit: v0.2.1
_commit: v0.3.0
_src_path: https://github.com/quantco/copier-template-python-open-source
add_autobump_workflow: false
author_email: noreply@quantco.com
author_name: QuantCo, Inc.
github_url: https://github.com/quantco/multiregex
github_user: pavelzw
minimal_python_version: py38
minimal_python_version: py39
project_short_description: Quickly match many regexes against a string. Provides 2-10x
speedups over naïve regex matching.
project_slug: multiregex
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,5 @@ jobs:
with:
name: artifact
path: dist
- name: Publish package on TestPyPi
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
with:
repository-url: https://test.pypi.org/legacy/
- name: Publish package on PyPi
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ jobs:

pytest:
timeout-minutes: 30
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
environment:
- py38
- py39
- py310
- py311
- py312
- py313
os:
- ubuntu-latest
- macos-latest
Expand Down
20 changes: 8 additions & 12 deletions multiregex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@
except AttributeError:
import sre_constants
import sre_parse
from collections.abc import Iterable
from re import Pattern
from typing import (
Dict,
Iterable,
List,
Optional,
Pattern,
Set,
Tuple,
TypeVar,
Union,
cast,
Expand All @@ -54,8 +50,8 @@

V = TypeVar("V")
PatternOrStr = Union[Pattern, str]
Prematchers = Set[str]
FalsePositivesCounter = Dict[str, int]
Prematchers = set[str]
FalsePositivesCounter = dict[str, int]


class AhocorasickError(Exception):
Expand All @@ -66,7 +62,7 @@ class RegexMatcher:
def __init__(
self,
patterns: Iterable[
Union[PatternOrStr, Tuple[PatternOrStr, Optional[Iterable[str]]]]
Union[PatternOrStr, tuple[PatternOrStr, Optional[Iterable[str]]]]
],
count_prematcher_false_positives=False,
):
Expand Down Expand Up @@ -205,7 +201,7 @@ def run(self, match_func, s, enable_prematchers=True):
"""Alias for ``run(re.fullmatch, ...)``."""
fullmatch = functools.partialmethod(run, re.fullmatch)

def get_pattern_candidates(self, s: str) -> List[Pattern]:
def get_pattern_candidates(self, s: str) -> list[Pattern]:
"""Get a list of patterns that potentially match `s`.

Pattern order is the same the order of `patterns` given to `__init__`.
Expand All @@ -220,7 +216,7 @@ def get_pattern_candidates(self, s: str) -> List[Pattern]:

def get_prematcher_false_positives(
self,
) -> List[Tuple[Pattern, FalsePositivesCounter]]:
) -> list[tuple[Pattern, FalsePositivesCounter]]:
if not self.count_prematcher_false_positives:
raise RuntimeError("Prematcher profiling not enabled")
return sorted(
Expand Down Expand Up @@ -321,7 +317,7 @@ def _sre_find_terminals(sre_ast):
i += 1


def _ahocorasick_make_automaton(words: Dict[str, V]) -> "ahocorasick.Automaton[V]":
def _ahocorasick_make_automaton(words: dict[str, V]) -> "ahocorasick.Automaton[V]":
"""Make an ahocorasick automaton from a dictionary of `needle -> value`
items."""
automaton = ahocorasick.Automaton() # type: ahocorasick.Automaton[V]
Expand Down
5,452 changes: 2,180 additions & 3,272 deletions pixi.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ platforms = ["osx-arm64", "osx-64", "linux-64", "win-64"]
postinstall = "pip install --no-build-isolation --no-deps --disable-pip-version-check -e ."

[dependencies]
python = ">=3.8"
python = ">=3.9"
pyahocorasick = "*"

[host-dependencies]
Expand All @@ -26,6 +26,7 @@ test-coverage = "pytest --cov=multiregex --cov-report=xml --cov-report=term-miss
[feature.build.dependencies]
python-build = "*"
twine = "*"
wheel = "*"
[feature.build.tasks]
build-wheel = "python -m build --no-isolation ."
check-wheel = "twine check dist/*"
Expand All @@ -43,8 +44,6 @@ typos = "*"
pre-commit-install = "pre-commit install"
pre-commit-run = "pre-commit run -a"

[feature.py38.dependencies]
python = "3.8.*"
[feature.py39.dependencies]
python = "3.9.*"
[feature.py310.dependencies]
Expand All @@ -53,13 +52,15 @@ python = "3.10.*"
python = "3.11.*"
[feature.py312.dependencies]
python = "3.12.*"
[feature.py313.dependencies]
python = "3.13.*"

[environments]
default = ["test"]
py38 = ["py38", "test"]
py39 = ["py39", "test"]
py310 = ["py310", "test"]
py311 = ["py311", "test"]
py312 = ["py312", "test"]
py313 = ["py313", "test"]
build = ["build"]
lint = { features = ["lint"], no-default-feature = true }
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ dynamic = ["version"]
maintainers = [{ name = "Bela Stoyan", email = "bela.stoyan@quantco.com" }]
classifiers = [
"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",
"Programming Language :: Python :: 3.13",
]
requires-python = ">=3.8"
requires-python = ">=3.9"
readme = "README.md"
dependencies = ["pyahocorasick"]

Expand Down Expand Up @@ -61,7 +61,7 @@ quote-style = "double"
indent-style = "space"

[tool.mypy]
python_version = '3.8'
python_version = '3.9'
no_implicit_optional = true
check_untyped_defs = true
allow_redefinition = true
Expand Down
3 changes: 2 additions & 1 deletion stubs/ahocorasick.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Generic, Iterator, TypeVar
from collections.abc import Iterator
from typing import Generic, TypeVar

T = TypeVar("T")

Expand Down