Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix perf scripts #225

Merged
merged 1 commit into from
Oct 17, 2024
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
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ classifiers = [
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Programming Language :: Python :: Implementation :: GraalPy",
# no graalpy classifier yet (pypa/trove-classifiers#188)
# "Programming Language :: Python :: Implementation :: GraalPy",
]

[project.optional-dependencies]
Expand All @@ -54,6 +55,12 @@ where = ["src"]
[tool.setuptools.package-data]
"ua_parser" = ["py.typed"]

[tool.ruff]
exclude = [
"src/ua_parser/_lazy.py",
"src/ua_parser/_matchers.py",
]

[tool.ruff.lint]
select = ["F", "E", "W", "I", "RET", "RUF", "PT"]
ignore = [
Expand Down
24 changes: 21 additions & 3 deletions src/ua_parser/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
import threading
import time
import tracemalloc
import types
from typing import (
Any,
Callable,
Expand All @@ -38,8 +38,15 @@
)
from .caching import Cache, Local
from .loaders import load_builtins, load_yaml
from .re2 import Resolver as Re2Resolver
from .regex import Resolver as RegexResolver

try:
from .re2 import Resolver as Re2Resolver
except ImportError:
pass
try:
from .regex import Resolver as RegexResolver
except ImportError:
pass
from .user_agent_parser import Parse

CACHEABLE = {
Expand All @@ -60,6 +67,17 @@
]
)

try:
import tracemalloc
except ImportError:
snapshot = types.SimpleNamespace(
compare_to=lambda _1, _2: [],
)
tracemalloc = types.SimpleNamespace( # type: ignore
start=lambda: None,
take_snapshot=lambda: snapshot,
)


def get_rules(parsers: List[str], regexes: Optional[io.IOBase]) -> Matchers:
if regexes:
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
min_version = 4.0
env_list = py3{9,10,11,12}
pypy3.10
#graalpy-24
graalpy-24
flake8, black, typecheck
labels =
test = py3{9,10,11,12},pypy3.10#,graalpy-24
test = py3{9,10,11,12},pypy3.10,graalpy-24
cpy = py3{9,10,11,12}
pypy = pypy3.10
#graal = graalpy-24
graal = graalpy-24
check = flake8, black, typecheck

[testenv]
Expand Down