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 Sep 27, 2024
1 parent 83f3e1c commit 7f7ad7c
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 115 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, Tuple, 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
15 changes: 6 additions & 9 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 Dict, List, Optional, Tuple, 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 All @@ -72,7 +69,7 @@ def solve_version_delimiter(delimiter_exp: str, pkg_cfg: ConfigPkg) -> str:
return ",".join(result)


def _version_solver(list_exp: List, pkg_cfg: ConfigPkg) -> List:
def _version_solver(list_exp: list, pkg_cfg: ConfigPkg) -> list:
result = []
for op, version in list_exp:
if op in ["==", ""]:
Expand All @@ -98,7 +95,7 @@ def _version_solver(list_exp: List, pkg_cfg: ConfigPkg) -> List:
return result


def parse_delimiter(delimiter_exp: str) -> List[Optional[Tuple[str, str]]]:
def parse_delimiter(delimiter_exp: str) -> list[tuple[str, str] | None]:
re_search = re.compile(r"([!=><]+)\s*([a-z0-9\-\.\_]+)", re.IGNORECASE)
result = re_search.findall(delimiter_exp)
if not result:
Expand Down
3 changes: 1 addition & 2 deletions grayskull/cli/parser.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import re
from pathlib import Path
from typing import Optional, Tuple

from grayskull.utils import origin_is_github, origin_is_local_sdist


def parse_pkg_name_version(
pkg_name: str,
) -> Tuple[str, str, Optional[str]]:
) -> tuple[str, str, str | None]:
origin = ""
if origin_is_local_sdist(pkg_name):
# Try to get package name and version from sdist archive
Expand Down
3 changes: 1 addition & 2 deletions grayskull/cli/stdout.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import re
from contextlib import contextmanager
from copy import deepcopy
from typing import Dict, List

import progressbar
from colorama import Fore, Style
Expand Down Expand Up @@ -62,7 +61,7 @@ def update(self, *args, **kargs):


def print_requirements(
requirements: Dict[str, List[str]], optional_requirements: Dict[str, List[str]]
requirements: dict[str, list[str]], optional_requirements: dict[str, list[str]]
) -> set:
all_missing_deps = set()
re_search = re.compile(r"^\s*([a-z0-9\.\-\_]+)(.*)", re.IGNORECASE | re.DOTALL)
Expand Down
31 changes: 15 additions & 16 deletions grayskull/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass, field
from typing import Dict, List, Optional, Tuple

from grayskull.cli.parser import parse_pkg_name_version
from grayskull.utils import PyVer
Expand All @@ -12,8 +11,8 @@
class Configuration:
name: str
version: str = ""
files_to_copy: List = field(default_factory=list)
supported_py: List[PyVer] = field(
files_to_copy: list = field(default_factory=list)
supported_py: list[PyVer] = field(
default_factory=lambda: [
PyVer(2, 7),
PyVer(3, 6),
Expand All @@ -25,7 +24,7 @@ class Configuration:
PyVer(3, 12),
]
)
py_cf_supported: List[PyVer] = field(
py_cf_supported: list[PyVer] = field(
default_factory=lambda: [
PyVer(3, 7),
PyVer(3, 8),
Expand All @@ -36,27 +35,27 @@ class Configuration:
]
)
is_strict_cf: bool = False
pkg_need_c_compiler: Tuple = field(
pkg_need_c_compiler: tuple = field(
default_factory=lambda: ("cython", "cython-blis", "blis")
)
pkg_need_cxx_compiler: Tuple = field(default_factory=lambda: ("pybind11",))
pkg_need_cxx_compiler: tuple = field(default_factory=lambda: ("pybind11",))
url_pypi: str = DEFAULT_PYPI_URL
url_pypi_metadata: str = DEFAULT_PYPI_META_URL
download: bool = False
is_arch: bool = False
repo_github: Optional[str] = None
repo_github: str | None = None
from_local_sdist: bool = False
local_sdist: Optional[str] = None
local_sdist: str | None = None
missing_deps: set = field(default_factory=set)
extras_require_test: Optional[str] = None
github_release_tag: Optional[str] = None
extras_require_include: Tuple[str] = tuple()
extras_require_exclude: Tuple[str] = tuple()
extras_require_test: str | None = None
github_release_tag: str | None = None
extras_require_include: tuple[str] = tuple()
extras_require_exclude: tuple[str] = tuple()
extras_require_all: bool = False
extras_require_split: bool = False
licence_exclude_folders: Tuple[str] = tuple()
licence_exclude_folders: tuple[str] = tuple()

def get_oldest_py3_version(self, list_py_ver: List[PyVer]) -> PyVer:
def get_oldest_py3_version(self, list_py_ver: list[PyVer]) -> PyVer:
list_py_ver = sorted(list_py_ver)
min_python_version = (
self.py_cf_supported[0] if self.is_strict_cf else PyVer(3, 0)
Expand All @@ -67,8 +66,8 @@ def get_oldest_py3_version(self, list_py_ver: List[PyVer]) -> PyVer:
return min_python_version

def get_py_version_available(
self, req_python: List[Tuple[str, str, str]]
) -> Dict[PyVer, bool]:
self, req_python: list[tuple[str, str, str]]
) -> dict[PyVer, bool]:
"""Get the python version available given the requires python received
:param req_python: Requires python
Expand Down
2 changes: 1 addition & 1 deletion grayskull/license/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@lru_cache(maxsize=2)
def get_all_licenses() -> List:
def get_all_licenses() -> list:
data_folder = os.path.dirname(__file__)
all_licenses = []
for license_file in os.listdir(data_folder):
Expand Down
51 changes: 25 additions & 26 deletions grayskull/license/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from pathlib import Path
from subprocess import check_output
from tempfile import mkdtemp
from typing import List, Optional, Tuple, Union

import requests
from colorama import Fore
Expand All @@ -27,12 +26,12 @@
@dataclass
class ShortLicense:
name: str
path: Union[str, Path, None]
path: str | Path | None
is_packaged: bool


@lru_cache(maxsize=10)
def get_all_licenses_from_spdx() -> List:
def get_all_licenses_from_spdx() -> list:
"""Get all licenses available on spdx.org
:return: List with all licenses information on spdx.org
Expand Down Expand Up @@ -163,7 +162,7 @@ def get_short_license_id(name: str) -> str:
return recipe_license["licenseId"]


def _get_license(license_id: str, all_licenses: List) -> dict:
def _get_license(license_id: str, all_licenses: list) -> dict:

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
"""Search for the license identification in all licenses received
:param license_id: license identification
Expand All @@ -175,7 +174,7 @@ def _get_license(license_id: str, all_licenses: List) -> dict:
return one_license


def _get_all_names_from_api(one_license: dict) -> List:
def _get_all_names_from_api(one_license: dict) -> list:
"""Get the names and other names which each license has.
:param one_license: License name
Expand All @@ -191,7 +190,7 @@ def _get_all_names_from_api(one_license: dict) -> List:
return list(result)


def get_other_names_from_opensource(license_spdx: str) -> List:
def get_other_names_from_opensource(license_spdx: str) -> list:
lic = get_opensource_license(license_spdx)
return [_license["name"] for _license in lic.get("other_names", [])]

Expand All @@ -213,7 +212,7 @@ def read_licence_cache():


@lru_cache(maxsize=10)
def get_opensource_license_data() -> List:
def get_opensource_license_data() -> list:
try:
response = requests.get(url="https://api.opensource.org/licenses/", timeout=5)
except requests.exceptions.RequestException:
Expand All @@ -223,7 +222,7 @@ def get_opensource_license_data() -> List:
return response.json()


def _get_all_license_choice(all_licenses: List) -> List:
def _get_all_license_choice(all_licenses: list) -> list:
"""Function responsible to get the whole licenses name
:param all_licenses: list with all licenses
Expand All @@ -237,11 +236,11 @@ def _get_all_license_choice(all_licenses: List) -> List:

def search_license_file(
folder_path: str,
git_url: Optional[str] = None,
version: Optional[str] = None,
license_name_metadata: Optional[str] = None,
folders_exclude_search: Tuple[str] = tuple(),
) -> List[ShortLicense]:
git_url: str | None = None,
version: str | None = None,
license_name_metadata: str | None = None,
folders_exclude_search: tuple[str] = tuple(),
) -> list[ShortLicense]:
"""Search for the license file. First it will try to find it in the given
folder, after that it will search on the github api and for the last it will
clone the repository and it will search for the license there.
Expand Down Expand Up @@ -286,8 +285,8 @@ def search_license_file(

@lru_cache(maxsize=13)
def search_license_api_github(
github_url: str, version: Optional[str] = None, default: Optional[str] = "Other"
) -> Optional[ShortLicense]:
github_url: str, version: str | None = None, default: str | None = "Other"
) -> ShortLicense | None:
"""Search for the license asking in the github api
:param github_url: GitHub URL
Expand Down Expand Up @@ -315,7 +314,7 @@ def search_license_api_github(
)


def _get_api_github_url(github_url: str, version: Optional[str] = None) -> str:
def _get_api_github_url(github_url: str, version: str | None = None) -> str:
"""Try to presume the github url
:param github_url: GitHub URL
Expand All @@ -331,10 +330,10 @@ def _get_api_github_url(github_url: str, version: Optional[str] = None) -> str:


def search_license_folder(
path: Union[str, Path],
default: Optional[str] = None,
folders_exclude_search: Tuple[str] = tuple(),
) -> List[ShortLicense]:
path: str | Path,
default: str | None = None,
folders_exclude_search: tuple[str] = tuple(),
) -> list[ShortLicense]:
"""Search for the license in the given folder
:param path: Sdist folder
Expand Down Expand Up @@ -366,10 +365,10 @@ def search_license_folder(

def search_license_repo(
git_url: str,
version: Optional[str],
default: Optional[str] = None,
folders_exclude_search: Tuple[str] = tuple(),
) -> Optional[List[ShortLicense]]:
version: str | None,
default: str | None = None,
folders_exclude_search: tuple[str] = tuple(),
) -> list[ShortLicense] | None:
"""Search for the license file in the given github repository
:param git_url: GitHub URL
Expand Down Expand Up @@ -399,7 +398,7 @@ def search_license_repo(
)


def _get_git_cmd(git_url: str, version: str, dest) -> List[str]:
def _get_git_cmd(git_url: str, version: str, dest) -> list[str]:
"""Return the full git command to clone the repository
:param git_url: GitHub URL
Expand All @@ -413,7 +412,7 @@ def _get_git_cmd(git_url: str, version: str, dest) -> List[str]:
return git_cmd + [git_url, str(dest)]


def get_license_type(path_license: str, default: Optional[str] = None) -> Optional[str]:
def get_license_type(path_license: str, default: str | None = None) -> str | None:
"""Function tries to match the license with one of the models present in
grayskull/license/data
Expand Down
3 changes: 1 addition & 2 deletions grayskull/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import sys
from pathlib import Path
from typing import List, Optional

import requests
from colorama import Fore, Style, init
Expand Down Expand Up @@ -445,7 +444,7 @@ def create_r_recipe(pkg_name, sections_populate=None, **kwargs):
)


def add_extra_section(recipe, maintainers: Optional[List] = None):
def add_extra_section(recipe, maintainers: list | None = None):
maintainers = maintainers or [get_git_current_user()]
if "extra" in recipe:
recipe["extra"]["recipe-maintainers"] = maintainers
Expand Down
3 changes: 1 addition & 2 deletions grayskull/strategy/cran.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from copy import deepcopy
from os.path import basename
from tempfile import mkdtemp
from typing import Optional
from urllib.request import Request, urlopen

import requests
Expand Down Expand Up @@ -235,7 +234,7 @@ def get_webpage(cran_url):
return BeautifulSoup(html_page, features="html.parser")


def get_cran_index(cran_url: str, pkg_name: str, pkg_version: Optional[str] = None):
def get_cran_index(cran_url: str, pkg_name: str, pkg_version: str | None = None):
"""Fetch the entire CRAN index and store it."""
print_msg(f"Fetching main index from {cran_url}")

Expand Down
Loading

0 comments on commit 7f7ad7c

Please sign in to comment.