Skip to content

Commit

Permalink
Fix perf scripts
Browse files Browse the repository at this point in the history
- enable graal on tox (24.1 with master's virtualenv plugin seems to
  work)
- make tracemalloc optional in CLI script (doesn't work in pypy)
- add regex to CLI script
- comment graalpy trove classifier (doesn't exist yet)

fixes #206
  • Loading branch information
masklinn committed Oct 17, 2024
1 parent 46778e7 commit 60e1c0f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
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

0 comments on commit 60e1c0f

Please sign in to comment.