From 7d48843f7ff714a705dbdee588d956ba78314bc3 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Sat, 6 May 2023 00:23:56 +0200 Subject: [PATCH] Fix toml imports Add a compat layer for using tomllib from STL which allows us to drop vendored toml library. --- pipenv/project.py | 9 ++++++++- pipenv/utils/environment.py | 3 ++- pipenv/utils/toml.py | 7 ++++++- pipenv/vendor/dparse/parser.py | 6 +++++- pipenv/vendor/dparse/updater.py | 6 +++++- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/pipenv/project.py b/pipenv/project.py index 75ee7d40..55251bc5 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -13,6 +13,13 @@ import urllib.parse from json.decoder import JSONDecodeError from pathlib import Path +import click, tomlkit + +try: + import tomllib as toml +except ImportError: + import tomli as toml + from pipenv.cmdparse import Script from pipenv.environment import Environment from pipenv.environments import Setting, is_in_virtualenv, normalize_pipfile_path @@ -40,7 +47,7 @@ from pipenv.utils.shell import ( system_which, ) from pipenv.utils.toml import cleanup_toml, convert_toml_outline_tables -from pipenv.vendor import click, plette, toml, tomlkit +from pipenv.vendor import plette from pipenv.vendor.requirementslib.models.utils import get_default_pyproject_backend try: diff --git a/pipenv/utils/environment.py b/pipenv/utils/environment.py index 2e066eef..1354677c 100644 --- a/pipenv/utils/environment.py +++ b/pipenv/utils/environment.py @@ -1,7 +1,8 @@ import os +import dotenv +import click from pipenv import environments -from pipenv.vendor import click, dotenv def load_dot_env(project, as_dict=False, quiet=False): diff --git a/pipenv/utils/toml.py b/pipenv/utils/toml.py index d4157d01..27d9975a 100644 --- a/pipenv/utils/toml.py +++ b/pipenv/utils/toml.py @@ -1,4 +1,9 @@ -from pipenv.vendor import toml, tomlkit +try: + import tomllib as toml +except ImportError: + import tomli as toml + +import tomlkit def cleanup_toml(tml): diff --git a/pipenv/vendor/dparse/parser.py b/pipenv/vendor/dparse/parser.py index faaad2e8..4c59474e 100644 --- a/pipenv/vendor/dparse/parser.py +++ b/pipenv/vendor/dparse/parser.py @@ -10,6 +10,11 @@ from io import StringIO from configparser import ConfigParser, NoOptionError from pathlib import PurePath +try: + import tomllib as toml +except ImportError: + import tomli as toml + from .errors import MalformedDependencyFileError from .regex import HASH_REGEX @@ -17,7 +22,6 @@ from .dependencies import DependencyFile, Dependency from pipenv.patched.pip._vendor.packaging.requirements import Requirement as PackagingRequirement,\ InvalidRequirement from . import filetypes -import pipenv.vendor.toml as toml from pipenv.patched.pip._vendor.packaging.specifiers import SpecifierSet from pipenv.patched.pip._vendor.packaging.version import Version, InvalidVersion import json diff --git a/pipenv/vendor/dparse/updater.py b/pipenv/vendor/dparse/updater.py index 7b7ba9a5..fe20a213 100644 --- a/pipenv/vendor/dparse/updater.py +++ b/pipenv/vendor/dparse/updater.py @@ -3,9 +3,13 @@ from __future__ import absolute_import, print_function, unicode_literals import re import json import tempfile -import pipenv.vendor.toml as toml import os +try: + import tomllib as toml +except ImportError: + import tomli as toml + class RequirementsTXTUpdater(object): SUB_REGEX = r"^{}(?=\s*\r?\n?$)"