Skip to content

Commit

Permalink
Split precompiled data into a sub-project (and wheel)
Browse files Browse the repository at this point in the history
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 ua-parser#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 ua-parser#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).
  • Loading branch information
masklinn committed Nov 17, 2024
1 parent fa17d1b commit a5a3d5f
Show file tree
Hide file tree
Showing 15 changed files with 247 additions and 264 deletions.
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description = "Python port of Browserscope's user agent parser"
version = "1.0.0a1"
readme = "README.rst"
requires-python = ">=3.9"
dependencies = []
dependencies = ["ua-parser-builtins"]

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

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

[tool.ruff.lint]
Expand Down
8 changes: 0 additions & 8 deletions setup.cfg

This file was deleted.

221 changes: 0 additions & 221 deletions setup.py

This file was deleted.

11 changes: 0 additions & 11 deletions src/ua_parser/_lazy.pyi

This file was deleted.

11 changes: 0 additions & 11 deletions src/ua_parser/_matchers.pyi

This file was deleted.

7 changes: 0 additions & 7 deletions src/ua_parser/_regexes.pyi

This file was deleted.

4 changes: 2 additions & 2 deletions src/ua_parser/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def load_builtins() -> Matchers:
further imports simply reference the existing datas.
"""
from ._matchers import MATCHERS
from ua_parser_builtins.matchers import MATCHERS

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

return cast(Matchers, MATCHERS)

Expand Down
6 changes: 5 additions & 1 deletion src/ua_parser/user_agent_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,8 @@ def GetFilters(
del SafeLoader
else:
# Just load our pre-compiled versions
from ._regexes import DEVICE_PARSERS, OS_PARSERS, USER_AGENT_PARSERS
from ua_parser_builtins.regexes import (
DEVICE_PARSERS,
OS_PARSERS,
USER_AGENT_PARSERS,
)
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ deps =
pyyaml
google-re2
ua-parser-rs
./ua-parser-builtins
commands =
pytest -Werror --doctest-glob="*.rst" {posargs}

Expand All @@ -31,6 +32,7 @@ deps =
pytest
pyyaml
ua-parser-rs
./ua-parser-builtins

[testenv:flake8]
package = skip
Expand All @@ -47,4 +49,5 @@ package = skip
deps =
mypy
types-PyYaml
./ua-parser-builtins
commands = mypy {posargs:}
7 changes: 7 additions & 0 deletions ua-parser-builtins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Precompiled ruleset for [ua-parser](https://pypi.org/project/ua-parser/)

This project does not do anything on its own, nor does it have any
actual API. It only contains the dataset of
[uap-core](https://github.com/ua-parser/uap-core) pre-compiled for
use by [ua-parser](https://pypi.org/project/ua-parser/) to decrease
load times.
Loading

0 comments on commit a5a3d5f

Please sign in to comment.