Skip to content

Commit

Permalink
run ruff in default configuration and swap flake8 and black out
Browse files Browse the repository at this point in the history
  • Loading branch information
masklinn committed Feb 19, 2024
1 parent 16c1324 commit 6bf36b4
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 35 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ jobs:
- name: Install checkers
run: |
python -mpip install --upgrade pip
python -mpip install black flake8 mypy types-PyYaml
- name: flake
run: flake8 .
- name: black
run: black --check --diff --color --quiet .
python -mpip install mypy types-PyYaml
- name: ruff check
uses: chartboost/ruff-action@v1
- name: ruff format
uses: chartboost/ruff-action@v1
with:
optins: format
- name: mypy
run: mypy

Expand Down
5 changes: 2 additions & 3 deletions src/ua_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@
"parse_user_agent",
]

VERSION = (1, 0, 0)

import contextlib
from typing import Callable, Optional, Type
from typing import Callable, Optional

from .core import (
DefaultedParseResult,
Expand All @@ -73,6 +71,7 @@
from .re2 import Parser as Re2Parser


VERSION = (1, 0, 0)
parser: Parser


Expand Down
5 changes: 0 additions & 5 deletions src/ua_parser/basic.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import io
import os
from operator import methodcaller
from typing import List

from .core import (
Device,
DeviceMatcher,
Domain,
Matcher,
Matchers,
OS,
OSMatcher,
Parser as AbstractParser,
PartialParseResult,
UserAgent,
UserAgentMatcher,
)


Expand Down
2 changes: 1 addition & 1 deletion src/ua_parser/caching.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import abc
from collections import OrderedDict
import threading
from typing import Callable, ContextManager, Dict, Optional, MutableMapping
from typing import Dict, Optional

from .core import Parser, Domain, PartialParseResult

Expand Down
6 changes: 4 additions & 2 deletions src/ua_parser/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,13 @@ def _replacer(repl: str, m: Match[str]) -> Optional[str]:

class Matcher(abc.ABC, Generic[T]):
@abc.abstractmethod
def __call__(self, ua: str) -> Optional[T]: ...
def __call__(self, ua: str) -> Optional[T]:
...

@property
@abc.abstractmethod
def pattern(self) -> str: ...
def pattern(self) -> str:
...

@property
def flags(self) -> int:
Expand Down
5 changes: 2 additions & 3 deletions src/ua_parser/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ def load_lazy(d: MatchersData) -> Matchers:


class FileLoader(Protocol):
def __call__(
self, path: PathOrFile, loader: DataLoader = load_data
) -> Matchers: ...
def __call__(self, path: PathOrFile, loader: DataLoader = load_data) -> Matchers:
...


def load_json(f: PathOrFile, loader: DataLoader = load_data) -> Matchers:
Expand Down
7 changes: 1 addition & 6 deletions src/ua_parser/re2.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from __future__ import annotations

import io
import os
import re
from typing import List, Tuple, Union
from typing import List

import re2 # type: ignore

Expand All @@ -16,9 +14,6 @@
Matchers,
OS,
UserAgent,
UserAgentMatcher,
OSMatcher,
DeviceMatcher,
)


Expand Down
2 changes: 0 additions & 2 deletions src/ua_parser/threaded.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import itertools
import os
import random
import threading
Expand All @@ -11,7 +10,6 @@
BasicParser,
CachingParser,
Clearing,
Domain,
Locking,
LRU,
Parser,
Expand Down
14 changes: 10 additions & 4 deletions src/ua_parser/user_agent_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import re
import warnings
from typing import *
from typing import Any, Dict, Optional, Tuple


class UserAgentParser(object):
Expand All @@ -21,7 +21,9 @@ def __init__(
self.v1_replacement = v1_replacement
self.v2_replacement = v2_replacement

def Parse(self, user_agent_string: str) -> Tuple[
def Parse(
self, user_agent_string: str
) -> Tuple[
Optional[str],
Optional[str],
Optional[str],
Expand Down Expand Up @@ -81,7 +83,9 @@ def __init__(
self.os_v3_replacement = os_v3_replacement
self.os_v4_replacement = os_v4_replacement

def Parse(self, user_agent_string: str) -> Tuple[
def Parse(
self, user_agent_string: str
) -> Tuple[
Optional[str],
Optional[str],
Optional[str],
Expand Down Expand Up @@ -153,7 +157,9 @@ def __init__(
self.brand_replacement = brand_replacement
self.model_replacement = model_replacement

def Parse(self, user_agent_string: str) -> Tuple[
def Parse(
self, user_agent_string: str
) -> Tuple[
Optional[str],
Optional[str],
Optional[str],
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ deps =

[testenv:flake8]
package = skip
deps = flake8
commands = flake8 {posargs}
deps = ruff
commands = ruff check {posargs}

[testenv:black]
package = skip
deps = black
commands = black --check --diff {posargs:.}
deps = ruff
commands = ruff format --diff {posargs:.}

[testenv:typecheck]
package = skip
Expand Down

0 comments on commit 6bf36b4

Please sign in to comment.