Skip to content

Commit

Permalink
Ensure relative imports for vendorised tomli
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Feb 7, 2022
1 parent e89c83d commit 9276edd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions setuptools/_vendor/tomli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__all__ = ("loads", "load", "TOMLDecodeError")
__version__ = "1.2.3" # DO NOT EDIT THIS LINE MANUALLY. LET bump2version UTILITY DO IT

from tomli._parser import TOMLDecodeError, load, loads
from ._parser import TOMLDecodeError, load, loads

# Pretend this exception was created here.
TOMLDecodeError.__module__ = "tomli"
TOMLDecodeError.__module__ = "setuptools.extern.tomli"
4 changes: 2 additions & 2 deletions setuptools/_vendor/tomli/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
from typing import Any, BinaryIO, Dict, FrozenSet, Iterable, NamedTuple, Optional, Tuple
import warnings

from tomli._re import (
from ._re import (
RE_DATETIME,
RE_LOCALTIME,
RE_NUMBER,
match_to_datetime,
match_to_localtime,
match_to_number,
)
from tomli._types import Key, ParseFloat, Pos
from ._types import Key, ParseFloat, Pos

ASCII_CTRL = frozenset(chr(i) for i in range(32)) | frozenset(chr(127))

Expand Down
2 changes: 1 addition & 1 deletion setuptools/_vendor/tomli/_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from typing import Any, Optional, Union

from tomli._types import ParseFloat
from ._types import ParseFloat

# E.g.
# - 00:32:00.999999
Expand Down
11 changes: 11 additions & 0 deletions tools/vendored.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ def rewrite_importlib_resources(pkg_files, new_root):
file.write_text(text)


def rewrite_tomli(pkg_files, new_root):
"""
Rewrite imports in tomli to use the relative form.
"""
for file in pkg_files.glob('*.py'):
text = file.read_text().replace('tomli.', '.')
text = text.replace('tomli', f'{new_root}.tomli')
file.write_text(text)


def clean(vendor):
"""
Remove all files out of the vendor directory except the meta
Expand Down Expand Up @@ -111,6 +121,7 @@ def update_setuptools():
rewrite_jaraco_text(vendor / 'jaraco/text', 'setuptools.extern')
rewrite_jaraco(vendor / 'jaraco', 'setuptools.extern')
rewrite_importlib_resources(vendor / 'importlib_resources', 'setuptools.extern')
rewrite_tomli(vendor / 'tomli', 'setuptools.extern')


def install_validate_pyproject(vendor):
Expand Down

0 comments on commit 9276edd

Please sign in to comment.