Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,27 @@ repos:
args: ["--autofix", "--no-sort-keys", "--indent", "4"]
- id: check-added-large-files

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
- id: pyupgrade
args: ["--py312-plus"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.2
hooks:
- id: ruff
args: [ "--fix" ]
- id: ruff-format

- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: autoflake

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
- id: mypy
args: ["--pretty"]
additional_dependencies: ["pygobject-stubs", "types-PyYAML", "types-Markdown", "types-requests", "types-pycurl", "types-chardet", "pytest-stub", "types-orjson", "pathvalidate", "requirements-parser", "icoextract", "fvs", "patool", "git+https://gitlab.com/TheEvilSkeleton/vkbasalt-cli.git@main"]

- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: autoflake
3 changes: 1 addition & 2 deletions bottles/backend/cabextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import shlex
import shutil
import subprocess
from typing import Optional

from bottles.backend.logger import Logger

Expand Down Expand Up @@ -47,7 +46,7 @@ def run(
self,
path: str,
name: str = "",
files: Optional[list] = None,
files: list | None = None,
destination: str = "",
):
if files is None:
Expand Down
3 changes: 1 addition & 2 deletions bottles/backend/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import shutil
import sys
import time
from typing import Optional

import requests

Expand All @@ -38,7 +37,7 @@ class Downloader:
"""

def __init__(
self, url: str, file: str, update_func: Optional[TaskStreamUpdateHandler] = None
self, url: str, file: str, update_func: TaskStreamUpdateHandler | None = None
):
self.start_time = None
self.url = url
Expand Down
5 changes: 2 additions & 3 deletions bottles/backend/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import os
import shutil
from pathlib import Path
from typing import Dict
from bottles.backend.utils import yaml, json


Expand Down Expand Up @@ -82,12 +81,12 @@ class TrdyPaths:
vmtouch_available = shutil.which("vmtouch") or False
base_version = ""
if os.path.isfile("/app/manifest.json"):
with open("/app/manifest.json", mode="r", encoding="utf-8") as file:
with open("/app/manifest.json", encoding="utf-8") as file:
base_version = (
json.load(file) # type: ignore
.get("base-version", "")
.removeprefix("stable-")
)

# encoding detection correction, following windows defaults
locale_encodings: Dict[str, str] = {"ja_JP": "cp932", "zh_CN": "gbk"}
locale_encodings: dict[str, str] = {"ja_JP": "cp932", "zh_CN": "gbk"}
7 changes: 3 additions & 4 deletions bottles/backend/managers/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import shutil
import tarfile
from functools import lru_cache
from typing import Optional

import pycurl

Expand Down Expand Up @@ -131,7 +130,7 @@ def download(
file: str,
rename: str = "",
checksum: str = "",
func: Optional[TaskStreamUpdateHandler] = None,
func: TaskStreamUpdateHandler | None = None,
) -> bool:
"""Download a component from the Bottles repository."""

Expand Down Expand Up @@ -274,7 +273,7 @@ def extract(name: str, component: str, archive: str) -> bool:
root_dir = tar.getnames()[0]
tar.extractall(path)
tar.close()
except (tarfile.TarError, IOError, EOFError):
except (tarfile.TarError, OSError, EOFError):
with contextlib.suppress(FileNotFoundError):
os.remove(os.path.join(Paths.temp, archive))
with contextlib.suppress(FileNotFoundError):
Expand All @@ -301,7 +300,7 @@ def install(
self,
component_type: str,
component_name: str,
func: Optional[TaskStreamUpdateHandler] = None,
func: TaskStreamUpdateHandler | None = None,
):
"""
This function is used to install a component. It automatically
Expand Down
13 changes: 6 additions & 7 deletions bottles/backend/managers/conf.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import os
from configparser import ConfigParser
from typing import Optional

from bottles.backend.utils import yaml, json


class ConfigManager(object):
class ConfigManager:
def __init__(
self,
config_file: Optional[str] = None,
config_file: str | None = None,
config_type: str = "ini",
config_string: Optional[str] = None,
config_string: str | None = None,
):
self.config_file = config_file
self.config_string = config_string
Expand Down Expand Up @@ -44,10 +43,10 @@ def read(self):
# noinspection PyProtectedMember
res = config._sections
elif self.config_type == "json":
with open(self.config_file, "r") as f:
with open(self.config_file) as f:
res = json.load(f)
elif self.config_type == "yaml" or self.config_type == "yml":
with open(self.config_file, "r") as f:
with open(self.config_file) as f:
res = yaml.load(f)
else:
raise ValueError("Invalid configuration type")
Expand Down Expand Up @@ -94,7 +93,7 @@ def write_ini(self):
with open(self.config_file, "w") as f:
config.write(f)

def write_dict(self, config_file: Optional[str] = None):
def write_dict(self, config_file: str | None = None):
if self.config_file is None and config_file is None:
raise ValueError("No config path specified")
elif self.config_file is None and config_file is not None:
Expand Down
2 changes: 1 addition & 1 deletion bottles/backend/managers/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self):

def __get_data(self):
try:
with open(self.__p_data, "r") as s:
with open(self.__p_data) as s:
self.__data = yaml.load(s)
if self.__data is None:
raise AttributeError
Expand Down
4 changes: 3 additions & 1 deletion bottles/backend/managers/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def install(self, config: BottleConfig, dependency: list) -> Result:
task_id = TaskManager.add(Task(title=dependency[0]))

logging.info(
"Installing dependency [%s] in bottle [%s]." % (dependency[0], config.Name),
"Installing dependency [{}] in bottle [{}].".format(
dependency[0], config.Name
),
)
manifest = self.get_dependency(dependency[0])
if not manifest:
Expand Down
2 changes: 1 addition & 1 deletion bottles/backend/managers/epicgamesstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_installed_games(config: BottleConfig) -> list:
if dat_path is None:
return []

with open(dat_path, "r") as dat:
with open(dat_path) as dat:
data = json.load(dat)

for game in data["InstallationList"]:
Expand Down
3 changes: 1 addition & 2 deletions bottles/backend/managers/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import subprocess
import uuid
from functools import lru_cache
from typing import Optional

import markdown
import pycurl
Expand Down Expand Up @@ -358,7 +357,7 @@ def install(
installer: dict,
step_fn: callable,
is_final: bool = True,
local_resources: Optional[dict] = None,
local_resources: dict | None = None,
):
manifest = self.get_installer(installer[0])
_config = config
Expand Down
5 changes: 2 additions & 3 deletions bottles/backend/managers/journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import shutil
import uuid
from datetime import datetime, timedelta
from typing import Optional

from bottles.backend.globals import Paths
from bottles.backend.utils import yaml
Expand Down Expand Up @@ -52,7 +51,7 @@ def __get_journal() -> dict:
with open(JournalManager.path, "w") as f:
yaml.dump({}, f)

with open(JournalManager.path, "r") as f:
with open(JournalManager.path) as f:
try:
journal = yaml.load(f)
except yaml.YAMLError:
Expand Down Expand Up @@ -100,7 +99,7 @@ def __clean_old():
JournalManager.__save_journal(journal)

@staticmethod
def __save_journal(journal: Optional[dict] = None):
def __save_journal(journal: dict | None = None):
"""Save the journal to the journal file."""
if journal is None:
journal = JournalManager.__get_journal()
Expand Down
2 changes: 1 addition & 1 deletion bottles/backend/managers/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def load_library(self, silent=False):
self.__library = {}
self.save_library()
else:
with open(self.library_path, "r") as library_file:
with open(self.library_path) as library_file:
self.__library = yaml.load(library_file)

if self.__library is None:
Expand Down
22 changes: 11 additions & 11 deletions bottles/backend/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from datetime import datetime
from gettext import gettext as _
from glob import glob
from typing import Any, Dict, List, Optional
from typing import Any

import pathvalidate

Expand Down Expand Up @@ -91,7 +91,7 @@ class Manager(metaclass=Singleton):
vkd3d_available = []
nvapi_available = []
latencyflex_available = []
local_bottles: Dict[str, BottleConfig] = {}
local_bottles: dict[str, BottleConfig] = {}
supported_runtimes = {}
supported_winebridge = {}
supported_wine_runners = {}
Expand Down Expand Up @@ -413,7 +413,7 @@ def check_runners(self, install_latest: bool = True) -> bool:

if len(self.runners_available) > 0:
logging.info(
"Runners found:\n - {0}".format("\n - ".join(self.runners_available))
"Runners found:\n - {}".format("\n - ".join(self.runners_available))
)

tmp_runners = [x for x in self.runners_available if not x.startswith("sys-")]
Expand Down Expand Up @@ -464,7 +464,7 @@ def check_runtimes(self, install_latest: bool = True) -> bool:
manifest = os.path.join(Paths.runtimes, runtime, "manifest.yml")

if os.path.exists(manifest):
with open(manifest, "r") as f:
with open(manifest) as f:
data = yaml.load(f)
version = data.get("version")
if version:
Expand Down Expand Up @@ -493,7 +493,7 @@ def check_winebridge(

version_file = os.path.join(Paths.winebridge, "VERSION")
if os.path.exists(version_file):
with open(version_file, "r") as f:
with open(version_file) as f:
version = f.read().strip()
if version:
self.winebridge_available = [f"winebridge-{version}"]
Expand Down Expand Up @@ -630,7 +630,7 @@ def __check_component(

if len(component["available"]) > 0:
logging.info(
"{0}s found:\n - {1}".format(
"{}s found:\n - {}".format(
component_type.capitalize(), "\n - ".join(component["available"])
)
)
Expand Down Expand Up @@ -663,7 +663,7 @@ def __check_component(
except ValueError:
return sorted(component["available"], reverse=True)

def get_programs(self, config: BottleConfig) -> List[dict]:
def get_programs(self, config: BottleConfig) -> list[dict]:
"""
Get the list of programs (both from the drive and the user defined
in the bottle configuration file).
Expand Down Expand Up @@ -825,7 +825,7 @@ def process_bottle(bottle):
_config = os.path.join(_bottle, "bottle.yml")

if os.path.exists(_placeholder):
with open(_placeholder, "r") as f:
with open(_placeholder) as f:
try:
placeholder_yaml = yaml.load(f)
if placeholder_yaml.get("Path"):
Expand Down Expand Up @@ -951,7 +951,7 @@ def process_bottle(bottle):

if len(self.local_bottles) > 0 and not silent:
logging.info(
"Bottles found:\n - {0}".format("\n - ".join(self.local_bottles))
"Bottles found:\n - {}".format("\n - ".join(self.local_bottles))
)

if (
Expand Down Expand Up @@ -1138,7 +1138,7 @@ def create_bottle(
sandbox: bool = False,
fn_logger: callable = None,
arch: str = "win64",
custom_environment: Optional[str] = None,
custom_environment: str | None = None,
) -> Result[dict]:
"""
Create a new bottle from the given arguments.
Expand Down Expand Up @@ -1392,7 +1392,7 @@ def components_check():
env = Samples.environments[environment.lower()]
elif custom_environment:
try:
with open(custom_environment, "r") as f:
with open(custom_environment) as f:
env = yaml.load(f.read())
logging.warning("Using a custom environment recipe…")
log_update(_("(!) Using a custom environment recipe…"))
Expand Down
9 changes: 4 additions & 5 deletions bottles/backend/managers/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@
import os
import shlex
import subprocess
from typing import Optional


class SandboxManager:
def __init__(
self,
envs: Optional[dict] = None,
chdir: Optional[str] = None,
envs: dict | None = None,
chdir: str | None = None,
clear_env: bool = False,
share_paths_ro: Optional[list] = None,
share_paths_rw: Optional[list] = None,
share_paths_ro: list | None = None,
share_paths_rw: list | None = None,
share_net: bool = False,
share_user: bool = False,
share_host_ro: bool = True,
Expand Down
Loading
Loading