Skip to content

Commit

Permalink
Add inital support for pixi in grayskull (#580)
Browse files Browse the repository at this point in the history
* Add pixi

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Use modern type hint syntax throughout the codebase

This commit replaces the use of 'Union' type hints with the modern '|' syntax in multiple files for better readability and conciseness. Additionally, it removes unnecessary imports of 'Union' from the 'typing' module.

Signed-off-by: Marcelo Trevisani <[email protected]>

---------

Signed-off-by: Marcelo Trevisani <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
marcelotrevisani and pre-commit-ci[bot] authored Nov 13, 2024
1 parent 10f13e5 commit 5b29307
Show file tree
Hide file tree
Showing 9 changed files with 2,226 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SCM syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,7 @@ dmypy.json

# Project version
grayskull/_version.py

# pixi environments
.pixi
*.egg-info
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
2 changes: 1 addition & 1 deletion grayskull/strategy/py_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def _fix_list_requirements(key_deps: str) -> list:
if isinstance(val_deps, str):
val_deps = [val_deps]
for val in val_deps:
if isinstance(val, (tuple, list)):
if isinstance(val, tuple | list):
list_req.extend(list(map(str, val)))
else:
list_req.append(str(val))
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
Loading

0 comments on commit 5b29307

Please sign in to comment.