Skip to content

Commit bf52b05

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. 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 2476d04 commit bf52b05

File tree

17 files changed

+297
-283
lines changed

17 files changed

+297
-283
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ name: CI
33
on:
44
push:
55
pull_request:
6-
workflow_dispatch:
76

87
jobs:
98
checks:
109
runs-on: ubuntu-latest
1110
steps:
1211
- name: Checkout working copy
1312
uses: actions/checkout@v4
13+
with:
14+
submodules: true
15+
fetch-depth: 0
1416
- name: ruff check
1517
uses: chartboost/ruff-action@v1
1618
- name: ruff format
@@ -29,7 +31,7 @@ jobs:
2931
if: ${{ always() && steps.setup_python.conclusion == 'success' }}
3032
run: |
3133
python -mpip install --upgrade pip
32-
python -mpip install mypy types-PyYaml
34+
python -mpip install mypy types-PyYaml ./ua-parser-builtins
3335
- name: mypy
3436
if: ${{ always() && steps.install_mypy.conclusion == 'success' }}
3537
run: mypy
@@ -101,6 +103,7 @@ jobs:
101103
uses: actions/checkout@v4
102104
with:
103105
submodules: true
106+
fetch-depth: 0
104107
- name: Set up Python ${{ matrix.python-version }}
105108
uses: actions/setup-python@v5
106109
with:
@@ -115,6 +118,7 @@ jobs:
115118
sudo apt install libyaml-dev
116119
fi
117120
- run: python -mpip install pytest pyyaml
121+
- run: python -mpip install ./ua-parser-builtins
118122
# install rs accelerator if available, ignore if not
119123
- run: python -mpip install ua-parser-rs || true
120124
# re2 is basically impossible to install from source so don't

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+
)

0 commit comments

Comments
 (0)