Skip to content

Commit 7da56fd

Browse files
committed
run ruff in default configuration and swap flake8 and black out
The codebase is so small that it doesn't seem any faster, but it's hype and then we can enable a bunch more checks, especially isort which is currently dearly missing. Fixes #174
1 parent 16c1324 commit 7da56fd

File tree

10 files changed

+32
-36
lines changed

10 files changed

+32
-36
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ jobs:
2020
steps:
2121
- name: Checkout working copy
2222
uses: actions/checkout@v3
23+
- name: ruff check
24+
uses: chartboost/ruff-action@v1
25+
- name: ruff format
26+
uses: chartboost/ruff-action@v1
27+
with:
28+
args: format --diff
2329
- name: Set up Python
2430
uses: actions/setup-python@v4
2531
with:
2632
python-version: "3.11"
27-
- name: Install checkers
33+
- name: Install mypy
2834
run: |
2935
python -mpip install --upgrade pip
30-
python -mpip install black flake8 mypy types-PyYaml
31-
- name: flake
32-
run: flake8 .
33-
- name: black
34-
run: black --check --diff --color --quiet .
36+
python -mpip install mypy types-PyYaml
3537
- name: mypy
3638
run: mypy
3739

src/ua_parser/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@
4545
"parse_user_agent",
4646
]
4747

48-
VERSION = (1, 0, 0)
49-
5048
import contextlib
51-
from typing import Callable, Optional, Type
49+
from typing import Callable, Optional
5250

5351
from .core import (
5452
DefaultedParseResult,
@@ -73,6 +71,7 @@
7371
from .re2 import Parser as Re2Parser
7472

7573

74+
VERSION = (1, 0, 0)
7675
parser: Parser
7776

7877

src/ua_parser/basic.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
import io
2-
import os
31
from operator import methodcaller
42
from typing import List
53

64
from .core import (
75
Device,
8-
DeviceMatcher,
96
Domain,
107
Matcher,
118
Matchers,
129
OS,
13-
OSMatcher,
1410
Parser as AbstractParser,
1511
PartialParseResult,
1612
UserAgent,
17-
UserAgentMatcher,
1813
)
1914

2015

src/ua_parser/caching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import abc
22
from collections import OrderedDict
33
import threading
4-
from typing import Callable, ContextManager, Dict, Optional, MutableMapping
4+
from typing import Dict, Optional
55

66
from .core import Parser, Domain, PartialParseResult
77

src/ua_parser/core.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,13 @@ def _replacer(repl: str, m: Match[str]) -> Optional[str]:
225225

226226
class Matcher(abc.ABC, Generic[T]):
227227
@abc.abstractmethod
228-
def __call__(self, ua: str) -> Optional[T]: ...
228+
def __call__(self, ua: str) -> Optional[T]:
229+
...
229230

230231
@property
231232
@abc.abstractmethod
232-
def pattern(self) -> str: ...
233+
def pattern(self) -> str:
234+
...
233235

234236
@property
235237
def flags(self) -> int:

src/ua_parser/loaders.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,8 @@ def load_lazy(d: MatchersData) -> Matchers:
165165

166166

167167
class FileLoader(Protocol):
168-
def __call__(
169-
self, path: PathOrFile, loader: DataLoader = load_data
170-
) -> Matchers: ...
168+
def __call__(self, path: PathOrFile, loader: DataLoader = load_data) -> Matchers:
169+
...
171170

172171

173172
def load_json(f: PathOrFile, loader: DataLoader = load_data) -> Matchers:

src/ua_parser/re2.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from __future__ import annotations
22

3-
import io
4-
import os
53
import re
6-
from typing import List, Tuple, Union
4+
from typing import List
75

86
import re2 # type: ignore
97

@@ -16,9 +14,6 @@
1614
Matchers,
1715
OS,
1816
UserAgent,
19-
UserAgentMatcher,
20-
OSMatcher,
21-
DeviceMatcher,
2217
)
2318

2419

src/ua_parser/threaded.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import argparse
2-
import itertools
32
import os
43
import random
54
import threading
@@ -11,7 +10,6 @@
1110
BasicParser,
1211
CachingParser,
1312
Clearing,
14-
Domain,
1513
Locking,
1614
LRU,
1715
Parser,

src/ua_parser/user_agent_parser.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import re
33
import warnings
4-
from typing import *
4+
from typing import Any, Dict, Optional, Tuple
55

66

77
class UserAgentParser(object):
@@ -21,7 +21,9 @@ def __init__(
2121
self.v1_replacement = v1_replacement
2222
self.v2_replacement = v2_replacement
2323

24-
def Parse(self, user_agent_string: str) -> Tuple[
24+
def Parse(
25+
self, user_agent_string: str
26+
) -> Tuple[
2527
Optional[str],
2628
Optional[str],
2729
Optional[str],
@@ -81,7 +83,9 @@ def __init__(
8183
self.os_v3_replacement = os_v3_replacement
8284
self.os_v4_replacement = os_v4_replacement
8385

84-
def Parse(self, user_agent_string: str) -> Tuple[
86+
def Parse(
87+
self, user_agent_string: str
88+
) -> Tuple[
8589
Optional[str],
8690
Optional[str],
8791
Optional[str],
@@ -153,7 +157,9 @@ def __init__(
153157
self.brand_replacement = brand_replacement
154158
self.model_replacement = model_replacement
155159

156-
def Parse(self, user_agent_string: str) -> Tuple[
160+
def Parse(
161+
self, user_agent_string: str
162+
) -> Tuple[
157163
Optional[str],
158164
Optional[str],
159165
Optional[str],

tox.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ deps =
3030

3131
[testenv:flake8]
3232
package = skip
33-
deps = flake8
34-
commands = flake8 {posargs}
33+
deps = ruff
34+
commands = ruff check {posargs}
3535

3636
[testenv:black]
3737
package = skip
38-
deps = black
39-
commands = black --check --diff {posargs:.}
38+
deps = ruff
39+
commands = ruff format --diff {posargs:.}
4040

4141
[testenv:typecheck]
4242
package = skip

0 commit comments

Comments
 (0)