Skip to content

Commit fbf3aa6

Browse files
authored
Add pre commit checks (#19)
* add pre commit checks * Add black and isort * Change python and black version * remove isort * New lock file, messed up in merge * remove isort from pyproject.toml * remove `branches:[main,release]`
1 parent 014322a commit fbf3aa6

File tree

7 files changed

+224
-87
lines changed

7 files changed

+224
-87
lines changed

.github/workflows/precommits.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Pre-commit checks
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
env:
8+
POETRY_VERSION: "1.8.3"
9+
10+
jobs:
11+
python-pre-commit:
12+
name: Pre-commit checks
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
18+
19+
steps:
20+
- name: Checkout Repository
21+
uses: actions/checkout@v4
22+
23+
- name: Install Python
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
28+
- name: Install Poetry
29+
run: |
30+
pipx install poetry==${{ env.POETRY_VERSION }}
31+
32+
- name: Check Poetry File
33+
run: |
34+
poetry check
35+
36+
- name: Install Package Dependencies
37+
run: |
38+
poetry env use $pythonLocation/bin/python
39+
poetry install -n
40+
41+
- name: Run unit tests
42+
run: |
43+
poetry run pytest tests/unit
44+
45+
- name: Lint check
46+
run: |
47+
poetry run pylint --disable=R,C playwright_stealth
48+
49+
- name: Code style check
50+
run: |
51+
poetry run black playwright_stealth --check --diff

playwright_stealth/properties/_header_properties.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ def _generate_sec_ch_ua_platform(self) -> str:
6161

6262
def _generate_sec_ch_ua(self, brands: List[dict]) -> str:
6363
"""Generates the Sec_Ch_Ua based brands generated"""
64-
merged_brands = "".join(
65-
[f'"{brand["brand"]}";v="{brand["version"]}",' for brand in brands]
66-
)
64+
merged_brands = "".join([f'"{brand["brand"]}";v="{brand["version"]}",' for brand in brands])
6765
return merged_brands
6866

6967
def _generate_sec_ch_ua_form_factors(self) -> str:
@@ -78,6 +76,4 @@ def _generate_sec_ch_ua_mobile(self) -> str:
7876

7977
def as_dict(self) -> dict:
8078
# Convert all keys to kebab case and return a new dictionary
81-
return {
82-
key.replace("_", "-").lower(): value for key, value in self.__dict__.items()
83-
}
79+
return {key.replace("_", "-").lower(): value for key, value in self.__dict__.items()}

playwright_stealth/properties/_navigator_properties.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ def __init__(self, brands: List[dict], dnt: str, **kwargs):
3333
self.appVersion = self._generate_app_version(kwargs["User-Agent"])
3434
self.vendor = self._generate_vendor(kwargs["User-Agent"])
3535
self.deviceMemory = self._generate_device_memory()
36-
self.hardwareConcurrency = self._generate_hardware_concurrency(
37-
self.deviceMemory
38-
)
36+
self.hardwareConcurrency = self._generate_hardware_concurrency(self.deviceMemory)
3937
self.maxTouchPoints = self._generate_max_touch_points()
4038
self.mobile = self._generate_mobile()
4139

playwright_stealth/properties/_properties.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ def __init__(self):
2525
dnt = self._generate_dnt()
2626

2727
# Generate properties
28-
self.header = HeaderProperties(
29-
brands=brands, dnt=dnt, **spoofed_headers.as_header_dict()
30-
)
28+
self.header = HeaderProperties(brands=brands, dnt=dnt, **spoofed_headers.as_header_dict())
3129
self.navigator = NavigatorProperties(
3230
brands=brands, dnt=dnt, **spoofed_headers.as_header_dict()
3331
)
@@ -61,7 +59,9 @@ def _generate_brands(self, user_agent: str, browser: str = "chrome") -> str:
6159

6260
escaped_chars = [" ", " ", ";"]
6361

64-
greasey_brand = f"{escaped_chars[order[0]]}Not{escaped_chars[order[1]]}A{escaped_chars[order[2]]}Brand"
62+
greasey_brand = (
63+
f"{escaped_chars[order[0]]}Not{escaped_chars[order[1]]}A{escaped_chars[order[2]]}Brand"
64+
)
6565

6666
greased_brand_version_list = [{}, {}, {}]
6767

playwright_stealth/stealth.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ def combine_scripts(properties: Properties, config: StealthConfig):
1919

2020
def generate_stealth_headers(properties: Properties, page: Union[AsyncPage, SyncPage]):
2121
"""Generates the stealth headers for the page by replacing the original headers with the spoofed ones for every request."""
22-
page.route(
23-
"**/*", lambda route: route.continue_(headers=properties.as_dict()["header"])
24-
)
22+
page.route("**/*", lambda route: route.continue_(headers=properties.as_dict()["header"]))
2523

2624

2725
def stealth_sync(page: SyncPage, config: StealthConfig = None):

0 commit comments

Comments
 (0)