mirror of
https://forge.fsky.io/oneflux/omegafox.git
synced 2026-02-11 03:52:05 -08:00
pythonlib: Typing & environ var fixes 0.2.1
- Fixes typing with OS_NAME - Fix exceeding environment variable length on Windows (caused by typing issue) - Fix not passing fontconfig on Linux (caused by typing issue)
This commit is contained in:
parent
f6396c1e81
commit
7d825e53d9
3 changed files with 11 additions and 11 deletions
|
|
@ -7,7 +7,7 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from io import BufferedWriter, BytesIO
|
from io import BufferedWriter, BytesIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional, Union
|
from typing import List, Literal, Optional, Union
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
@ -34,12 +34,12 @@ ARCH_MAP: dict[str, str] = {
|
||||||
'armv6l': 'arm64',
|
'armv6l': 'arm64',
|
||||||
'armv7l': 'arm64',
|
'armv7l': 'arm64',
|
||||||
}
|
}
|
||||||
OS_MAP: dict[str, str] = {'darwin': 'mac', 'linux': 'lin', 'win32': 'win'}
|
OS_MAP: dict[str, Literal['mac', 'win', 'lin']] = {'darwin': 'mac', 'linux': 'lin', 'win32': 'win'}
|
||||||
|
|
||||||
if sys.platform not in OS_MAP:
|
if sys.platform not in OS_MAP:
|
||||||
raise UnsupportedOS(f"OS {sys.platform} is not supported")
|
raise UnsupportedOS(f"OS {sys.platform} is not supported")
|
||||||
|
|
||||||
OS_NAME: str = OS_MAP[sys.platform]
|
OS_NAME: Literal['mac', 'win', 'lin'] = OS_MAP[sys.platform]
|
||||||
|
|
||||||
INSTALL_DIR: Path = Path(user_cache_dir("camoufox"))
|
INSTALL_DIR: Path = Path(user_cache_dir("camoufox"))
|
||||||
|
|
||||||
|
|
@ -179,7 +179,7 @@ class CamoufoxFetcher:
|
||||||
|
|
||||||
# Set permissions on INSTALL_DIR
|
# Set permissions on INSTALL_DIR
|
||||||
if OS_NAME != 'win':
|
if OS_NAME != 'win':
|
||||||
os.system(f'chmod -R 755 {shlex.quote(str(INSTALL_DIR))}')
|
os.system(f'chmod -R 755 {shlex.quote(str(INSTALL_DIR))}') # nosec
|
||||||
|
|
||||||
rprint('\nCamoufox successfully installed.', fg="yellow")
|
rprint('\nCamoufox successfully installed.', fg="yellow")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
from os import environ
|
from os import environ
|
||||||
from random import randrange
|
from random import randrange
|
||||||
from typing import Any, Dict, List, Optional, Tuple, Union, cast
|
from typing import Any, Dict, List, Literal, Optional, Tuple, Union, cast
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import orjson
|
import orjson
|
||||||
|
|
@ -38,7 +38,7 @@ def get_env_vars(
|
||||||
"""
|
"""
|
||||||
Gets a dictionary of environment variables for Camoufox.
|
Gets a dictionary of environment variables for Camoufox.
|
||||||
"""
|
"""
|
||||||
env_vars = {}
|
env_vars: Dict[str, Union[str, float, bool]] = {}
|
||||||
try:
|
try:
|
||||||
updated_config_data = orjson.dumps(config_map)
|
updated_config_data = orjson.dumps(config_map)
|
||||||
except orjson.JSONEncodeError as e:
|
except orjson.JSONEncodeError as e:
|
||||||
|
|
@ -46,7 +46,7 @@ def get_env_vars(
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Split the config into chunks
|
# Split the config into chunks
|
||||||
chunk_size = 2047 if OS_NAME == 'windows' else 32767
|
chunk_size = 2047 if OS_NAME == 'win' else 32767
|
||||||
config_str = updated_config_data.decode('utf-8')
|
config_str = updated_config_data.decode('utf-8')
|
||||||
|
|
||||||
for i in range(0, len(config_str), chunk_size):
|
for i in range(0, len(config_str), chunk_size):
|
||||||
|
|
@ -58,7 +58,7 @@ def get_env_vars(
|
||||||
print(f"Error setting {env_name}: {e}")
|
print(f"Error setting {env_name}: {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if OS_NAME == 'linux':
|
if OS_NAME == 'lin':
|
||||||
fontconfig_path = get_path(os.path.join("fontconfig", user_agent_os))
|
fontconfig_path = get_path(os.path.join("fontconfig", user_agent_os))
|
||||||
env_vars['FONTCONFIG_PATH'] = fontconfig_path
|
env_vars['FONTCONFIG_PATH'] = fontconfig_path
|
||||||
|
|
||||||
|
|
@ -115,7 +115,7 @@ def validate_type(value: Any, expected_type: str) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_target_os(config: Dict[str, Any]) -> str:
|
def get_target_os(config: Dict[str, Any]) -> Literal['mac', 'win', 'lin']:
|
||||||
"""
|
"""
|
||||||
Gets the OS from the config if the user agent is set,
|
Gets the OS from the config if the user agent is set,
|
||||||
otherwise returns the OS of the current system.
|
otherwise returns the OS of the current system.
|
||||||
|
|
@ -125,7 +125,7 @@ def get_target_os(config: Dict[str, Any]) -> str:
|
||||||
return OS_NAME
|
return OS_NAME
|
||||||
|
|
||||||
|
|
||||||
def determine_ua_os(user_agent: str) -> str:
|
def determine_ua_os(user_agent: str) -> Literal['mac', 'win', 'lin']:
|
||||||
"""
|
"""
|
||||||
Determines the OS from the user agent string.
|
Determines the OS from the user agent string.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
||||||
|
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "camoufox"
|
name = "camoufox"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
description = "Wrapper around Playwright to help launch Camoufox"
|
description = "Wrapper around Playwright to help launch Camoufox"
|
||||||
authors = ["daijro <daijro.dev@gmail.com>"]
|
authors = ["daijro <daijro.dev@gmail.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue