Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34c307b

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 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).
1 parent 2476d04 commit 34c307b

File tree

22 files changed

+309
-295
lines changed

22 files changed

+309
-295
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/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
from __future__ import annotations
2121

2222
__all__ = [
23+
"OS",
2324
"BasicResolver",
24-
"CachingResolver",
2525
"Cache",
26+
"CachingResolver",
2627
"DefaultedResult",
2728
"Device",
2829
"Domain",
2930
"Matchers",
30-
"OS",
31-
"Result",
32-
"Resolver",
3331
"PartialResult",
32+
"Resolver",
33+
"Result",
3434
"UserAgent",
3535
"load_builtins",
3636
"load_lazy_builtins",

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/caching.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __setitem__(self, key: str, value: PartialResult) -> None:
7878

7979
@dataclasses.dataclass
8080
class CacheEntry:
81-
__slots__ = ["key", "value", "freq"]
81+
__slots__ = ["freq", "key", "value"]
8282
key: str
8383
value: PartialResult
8484
freq: int
@@ -161,7 +161,7 @@ def _evict_small(self) -> None:
161161

162162
@dataclasses.dataclass
163163
class SieveNode:
164-
__slots__ = ("key", "value", "visited", "next")
164+
__slots__ = ("key", "next", "value", "visited")
165165
key: str
166166
value: PartialResult
167167
visited: bool

src/ua_parser/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
from typing import Generic, List, Optional, Protocol, Tuple, TypeVar
55

66
__all__ = [
7+
"OS",
78
"DefaultedResult",
89
"Device",
910
"Domain",
1011
"Matchers",
11-
"OS",
12-
"Result",
1312
"PartialResult",
1413
"Resolver",
14+
"Result",
1515
"UserAgent",
1616
]
1717

@@ -74,7 +74,7 @@ def __init__(
7474
class Device:
7575
"""Device information parsed from the user agent string."""
7676

77-
__slots__ = ("family", "brand", "model")
77+
__slots__ = ("brand", "family", "model")
7878
family: str
7979
brand: Optional[str]
8080
model: Optional[str]
@@ -172,7 +172,7 @@ class PartialResult:
172172
173173
"""
174174

175-
__slots__ = ("domains", "user_agent", "os", "device", "string")
175+
__slots__ = ("device", "domains", "os", "string", "user_agent")
176176
domains: Domain
177177
user_agent: Optional[UserAgent]
178178
os: Optional[OS]

0 commit comments

Comments
 (0)