Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 13, 2024
1 parent a64c915 commit 7830cf3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions grayskull/base/github.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import subprocess
from typing import Any, Union
from typing import Any
from urllib.parse import urlparse, urlunparse

import requests
Expand Down Expand Up @@ -88,7 +88,7 @@ def closest_match(tag):

def handle_gh_version(
name: str, version: str, url: str, tag: str
) -> tuple[Union[str, Any], Any, Any]:
) -> tuple[str | Any, Any, Any]:
"""Method responsible for handling the version of the GitHub package.
If version is specified, gets the closest tag in the repo.
If not, gets the latest version.
Expand Down
11 changes: 4 additions & 7 deletions grayskull/base/track_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import dataclass
from functools import lru_cache
from pathlib import Path
from typing import Union

from pkg_resources import parse_version # noqa
from ruamel.yaml import YAML
Expand All @@ -27,19 +26,17 @@ def __post_init__(self):
self.conda_forge = self.name


def track_package(pkg_name: str, config_file: Union[Path, str]) -> ConfigPkg:
def track_package(pkg_name: str, config_file: Path | str) -> ConfigPkg:
all_pkg = _get_track_info_from_file(config_file)
return ConfigPkg(pkg_name, **(all_pkg.get(pkg_name, {})))


def solve_list_pkg_name(
list_pkg: list[str], config_file: Union[Path, str]
) -> list[str]:
def solve_list_pkg_name(list_pkg: list[str], config_file: Path | str) -> list[str]:
re_norm = re.compile(r",\s+")
return [re_norm.sub(",", solve_pkg_name(pkg, config_file)) for pkg in list_pkg]


def solve_pkg_name(pkg: str, config_file: Union[Path, str]) -> str:
def solve_pkg_name(pkg: str, config_file: Path | str) -> str:
pkg_name_sep = pkg.strip().split()
config_pkg = track_package(pkg_name_sep[0], config_file)
all_delimiter = " ".join(pkg_name_sep[1:])
Expand All @@ -51,7 +48,7 @@ def solve_pkg_name(pkg: str, config_file: Union[Path, str]) -> str:


@lru_cache(maxsize=5)
def _get_track_info_from_file(config_file: Union[Path, str]) -> dict:
def _get_track_info_from_file(config_file: Path | str) -> dict:
yaml = YAML()
with open(config_file, encoding="utf_8") as yaml_file:
return yaml.load(yaml_file)
Expand Down
5 changes: 2 additions & 3 deletions grayskull/strategy/py_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from collections import defaultdict
from functools import singledispatch
from pathlib import Path
from typing import Union

from grayskull.strategy.parse_poetry_version import encode_poetry_version
from grayskull.utils import nested_dict
Expand All @@ -18,7 +17,7 @@ class InvalidPoetryDependency(BaseException):


@singledispatch
def get_constrained_dep(dep_spec: Union[str, dict], dep_name: str) -> str:
def get_constrained_dep(dep_spec: str | dict, dep_name: str) -> str:
raise InvalidPoetryDependency(
"Expected Poetry dependency specification to be of type str or dict, "
f"received {type(dep_spec).__name__}"
Expand Down Expand Up @@ -209,7 +208,7 @@ def add_pep725_metadata(metadata: dict, toml_metadata: dict):
return metadata


def get_all_toml_info(path_toml: Union[Path, str]) -> dict:
def get_all_toml_info(path_toml: Path | str) -> dict:
with open(path_toml, "rb") as f:
toml_metadata = tomllib.load(f)
toml_metadata = defaultdict(dict, toml_metadata)
Expand Down
6 changes: 3 additions & 3 deletions grayskull/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from glob import glob
from pathlib import Path
from shutil import copyfile
from typing import Final, Union
from typing import Final

from ruamel.yaml import YAML
from ruamel.yaml.comments import CommentedMap
Expand Down Expand Up @@ -120,7 +120,7 @@ def string_similarity(a, b):
return SequenceMatcher(None, a, b).ratio()


def rm_duplicated_deps(all_requirements: Union[list, set, None]) -> list | None:
def rm_duplicated_deps(all_requirements: list | set | None) -> list | None:
if not all_requirements:
return None
# Keep track of requirements which have already been added to the list.
Expand Down Expand Up @@ -193,7 +193,7 @@ def format_dependencies(all_dependencies: list, name: str) -> list:
def generate_recipe(
recipe: Recipe,
config,
folder_path: Union[str, Path] = ".",
folder_path: str | Path = ".",
use_v1_format: bool = False,
):
"""Write the recipe in a location. It will create a folder with the
Expand Down

0 comments on commit 7830cf3

Please sign in to comment.