Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEP: prefer stdlib tomllib over tomli when available #577

Merged
merged 1 commit into from
Nov 13, 2024
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
10 changes: 7 additions & 3 deletions grayskull/strategy/py_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from urllib.parse import urlparse

import requests
import tomli
from colorama import Fore, Style
from packaging.specifiers import SpecifierSet
from packaging.utils import canonicalize_version
Expand All @@ -37,6 +36,11 @@
sha256_checksum,
)

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

log = logging.getLogger(__name__)
RE_DEPS_NAME = re.compile(r"^\s*([\.a-zA-Z0-9_-]+)", re.MULTILINE)
PIN_PKG_COMPILER = {"numpy": "<{ pin_compatible('numpy') }}"}
Expand Down Expand Up @@ -630,8 +634,8 @@ def get_entry_points_from_sdist(sdist_metadata: dict) -> list:
all_parts[-1] = f"'{all_parts[-1]}'"
all_lines.append("=".join(all_parts))
try:
all_entry_points = tomli.loads("\n".join(all_lines))
except tomli.TOMLDecoderError:
all_entry_points = tomllib.loads("\n".join(all_lines))
except tomllib.TOMLDecoderError:
return []

if all_entry_points.get("console_scripts") or all_entry_points.get("gui_scripts"):
Expand Down
10 changes: 7 additions & 3 deletions grayskull/strategy/py_toml.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import sys
from collections import defaultdict
from functools import singledispatch
from pathlib import Path
from typing import Tuple, Union

import tomli

from grayskull.strategy.parse_poetry_version import encode_poetry_version
from grayskull.utils import nested_dict

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


class InvalidPoetryDependency(BaseException):
pass
Expand Down Expand Up @@ -207,7 +211,7 @@ def add_pep725_metadata(metadata: dict, toml_metadata: dict):

def get_all_toml_info(path_toml: Union[Path, str]) -> dict:
with open(path_toml, "rb") as f:
toml_metadata = tomli.load(f)
toml_metadata = tomllib.load(f)
toml_metadata = defaultdict(dict, toml_metadata)
metadata = nested_dict()
toml_project = toml_metadata.get("project", {}) or {}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies = [
"setuptools >=30.3.0",
"semver >=3.0.0,==3.0.*",
"stdlib-list",
"tomli",
"tomli; python_version < '3.11'",
"tomli-w",
]

Expand Down
Loading