Skip to content

Commit a5a3d5f

Browse files
committed
Split precompiled data into a sub-project (and wheel)
The goal of this is the ability to generate wheels for precompiled instances of uap-core, at whatever version we want. The goal here is ultimately to move all the precompiled stuff outside of uap-python itself and in a separate wheel, in order to generate wheels for precompiled instances of uap-core at whatever version we want 1. It resolves #146 by splitting the versioning of the API and that of the (pre-compiled) data, this is an issue for 1.0 as that detaches uap-python's versioning from uap-core's. 2. It allows users to update the API and the precompiled dataset separately, something they would otherwise need to do via yaml. 3. It fixes #221 by allowing the regular release of "preview" precompiled regexes from uap-core snapshots e.g. we could release 0.19.dev202412 at the start of december with whatever uap-core merged between the previous prerelease and then. This should not be picked up by pip by default, but would allow users to access those prerelases via `pip install --pre`. 4. If done well enough, it might allow users to build bespoke precompiled datasets so they don't have to pick between custom rules and precompiled (not sure there's any demand for this but it seems like it might be useful). 5. If it works well enough it might actually be possible to have 0.x use the legacy codegen package meaning it should not need to be updated anymore. This is implemented via hatch build hooks (which seem seem simpler than doing it via setuptools in the end). Adding `regexes.yaml` to the sdist via artifacts is a bit strange but necessary in order to generate a complete sdist which a wheel can be built from (even though the release script will likely only push the wheel).
1 parent fa17d1b commit a5a3d5f

File tree

15 files changed

+247
-264
lines changed

15 files changed

+247
-264
lines changed

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description = "Python port of Browserscope's user agent parser"
88
version = "1.0.0a1"
99
readme = "README.rst"
1010
requires-python = ">=3.9"
11-
dependencies = []
11+
dependencies = ["ua-parser-builtins"]
1212

1313
license = {text = "Apache 2.0"}
1414
urls = {repository = "https://github.com/ua-parser/uap-python"}
@@ -57,8 +57,7 @@ where = ["src"]
5757

5858
[tool.ruff]
5959
exclude = [
60-
"src/ua_parser/_lazy.py",
61-
"src/ua_parser/_matchers.py",
60+
"src/ua_parser/generate_builtins.py",
6261
]
6362

6463
[tool.ruff.lint]

setup.cfg

Lines changed: 0 additions & 8 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 221 deletions
This file was deleted.

src/ua_parser/_lazy.pyi

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/ua_parser/_matchers.pyi

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/ua_parser/_regexes.pyi

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/ua_parser/loaders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def load_builtins() -> Matchers:
5252
further imports simply reference the existing datas.
5353
5454
"""
55-
from ._matchers import MATCHERS
55+
from ua_parser_builtins.matchers import MATCHERS
5656

5757
# typing and mypy don't have safe upcast (#5756) and mypy is
5858
# unhappy about returning concrete matchers for a mixed type
@@ -66,7 +66,7 @@ def load_lazy_builtins() -> Matchers:
6666
further imports simply reference the existing datas.
6767
6868
"""
69-
from ._lazy import MATCHERS
69+
from ua_parser_builtins.lazy import MATCHERS
7070

7171
return cast(Matchers, MATCHERS)
7272

src/ua_parser/user_agent_parser.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,4 +521,8 @@ def GetFilters(
521521
del SafeLoader
522522
else:
523523
# Just load our pre-compiled versions
524-
from ._regexes import DEVICE_PARSERS, OS_PARSERS, USER_AGENT_PARSERS
524+
from ua_parser_builtins.regexes import (
525+
DEVICE_PARSERS,
526+
OS_PARSERS,
527+
USER_AGENT_PARSERS,
528+
)

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ deps =
2323
pyyaml
2424
google-re2
2525
ua-parser-rs
26+
./ua-parser-builtins
2627
commands =
2728
pytest -Werror --doctest-glob="*.rst" {posargs}
2829

@@ -31,6 +32,7 @@ deps =
3132
pytest
3233
pyyaml
3334
ua-parser-rs
35+
./ua-parser-builtins
3436

3537
[testenv:flake8]
3638
package = skip
@@ -47,4 +49,5 @@ package = skip
4749
deps =
4850
mypy
4951
types-PyYaml
52+
./ua-parser-builtins
5053
commands = mypy {posargs:}

ua-parser-builtins/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Precompiled ruleset for [ua-parser](https://pypi.org/project/ua-parser/)
2+
3+
This project does not do anything on its own, nor does it have any
4+
actual API. It only contains the dataset of
5+
[uap-core](https://github.com/ua-parser/uap-core) pre-compiled for
6+
use by [ua-parser](https://pypi.org/project/ua-parser/) to decrease
7+
load times.

0 commit comments

Comments
 (0)