Skip to content

Commit

Permalink
Merge branch 'main' of github.com:pawamoy/aria2p
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Oct 10, 2023
2 parents e259a40 + 8effdac commit 0713e4d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"appdirs>=1.4",
"loguru>=0.5",
"requests>=2.19",
"toml>=0.10",
"tomli>=2.0; python_version < '3.11'",
"websocket-client>=0.58",
]

Expand Down Expand Up @@ -78,7 +78,7 @@ docs = [
"mkdocs-material>=7.3",
"mkdocs-minify-plugin>=0.6.4",
"mkdocstrings[python]>=0.18",
"toml>=0.10",
"tomli>=2.0; python_version < '3.11'",
]
maintain = [
"black>=23.1",
Expand Down
13 changes: 10 additions & 3 deletions scripts/gen_credits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
from __future__ import annotations

import re
import sys
from importlib.metadata import PackageNotFoundError, metadata
from itertools import chain
from pathlib import Path
from textwrap import dedent
from typing import Mapping, cast

import toml
from jinja2 import StrictUndefined
from jinja2.sandbox import SandboxedEnvironment

if sys.version_info < (3, 11):
import tomli as tomllib
else:
import tomllib

project_dir = Path(".")
pyproject = toml.load(project_dir / "pyproject.toml")
with (project_dir / "pyproject.toml").open("rb") as pyproject_file:
pyproject = tomllib.load(pyproject_file)
project = pyproject["project"]
pdm = pyproject["tool"]["pdm"]
lock_data = toml.load(project_dir / "pdm.lock")
with (project_dir / "pdm.lock").open("rb") as lock_file:
lock_data = tomllib.load(lock_file)
lock_pkgs = {pkg["name"].lower(): pkg for pkg in lock_data["package"]}
project_name = project["name"]
regex = re.compile(r"(?P<dist>[\w.-]+)(?P<spec>.*)$")
Expand Down
11 changes: 9 additions & 2 deletions src/aria2p/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from __future__ import annotations

import signal
import sys
import textwrap
from importlib import metadata
from pathlib import Path
Expand All @@ -18,6 +19,11 @@
from datetime import timedelta
from types import FrameType

if sys.version_info < (3, 11):
import tomli as tomllib
else:
import tomllib


class SignalHandler:
"""A helper class to handle signals."""
Expand Down Expand Up @@ -231,14 +237,15 @@ def load_configuration() -> dict[str, Any]:
"""

config_dict = {}
config_dict["DEFAULT"] = toml.loads(default_config)
config_dict["DEFAULT"] = tomllib.loads(default_config)

# Check for configuration file
config_file_path = Path(user_config_dir("aria2p")) / "config.toml"

if config_file_path.exists():
try:
config_dict["USER"] = toml.load(config_file_path)
with config_file_path.open("rb") as config_file:
config_dict["USER"] = tomllib.load(config_file)
except Exception as error: # noqa: BLE001
logger.error(f"Failed to load configuration file: {error}")
else:
Expand Down

0 comments on commit 0713e4d

Please sign in to comment.