summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2023-01-24 00:49:17 +0000
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2023-01-24 01:14:45 +0000
commit5e7b76f786e8a8fbfc3bfa4755033a8d9c2e06d8 (patch)
tree6af90381dbdde44223e64d973f24455a094544a6
parent99b7b6450f4a71eed229607ccc1b8d567b59bf02 (diff)
downloadpython-setuptools-git-5e7b76f786e8a8fbfc3bfa4755033a8d9c2e06d8.tar.gz
Replace/move _normalization.path with/to _path.samepath and _path.normpath
-rw-r--r--setuptools/_normalization.py9
-rw-r--r--setuptools/_path.py10
-rw-r--r--setuptools/command/develop.py22
-rw-r--r--setuptools/command/editable_wheel.py15
4 files changed, 30 insertions, 26 deletions
diff --git a/setuptools/_normalization.py b/setuptools/_normalization.py
index d6343ca5..7012ffea 100644
--- a/setuptools/_normalization.py
+++ b/setuptools/_normalization.py
@@ -1,6 +1,4 @@
-import os
import re
-import sys
import warnings
from inspect import cleandoc
from pathlib import Path
@@ -17,13 +15,6 @@ _VALID_NAME = re.compile(r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", re.I)
_UNSAFE_NAME_CHARS = re.compile(r"[^A-Z0-9.]+", re.I)
-def path(filename: _Path) -> str:
- """Normalize a file/dir name for comparison purposes."""
- # See pkg_resources.normalize_path
- file = os.path.abspath(filename) if sys.platform == 'cygwin' else filename
- return os.path.normcase(os.path.realpath(os.path.normpath(file)))
-
-
def safe_identifier(name: str) -> str:
"""Make a string safe to be used as Python identifier.
>>> safe_identifier("12abc")
diff --git a/setuptools/_path.py b/setuptools/_path.py
index 3767523b..b99d9dad 100644
--- a/setuptools/_path.py
+++ b/setuptools/_path.py
@@ -1,4 +1,5 @@
import os
+import sys
from typing import Union
_Path = Union[str, os.PathLike]
@@ -26,4 +27,11 @@ def same_path(p1: _Path, p2: _Path) -> bool:
>>> same_path("a", "a/b")
False
"""
- return os.path.normpath(p1) == os.path.normpath(p2)
+ return normpath(p1) == normpath(p2)
+
+
+def normpath(filename: _Path) -> str:
+ """Normalize a file/dir name for comparison purposes."""
+ # See pkg_resources.normalize_path for notes about cygwin
+ file = os.path.abspath(filename) if sys.platform == 'cygwin' else filename
+ return os.path.normcase(os.path.realpath(os.path.normpath(file)))
diff --git a/setuptools/command/develop.py b/setuptools/command/develop.py
index 5f9690f6..08ae7f0d 100644
--- a/setuptools/command/develop.py
+++ b/setuptools/command/develop.py
@@ -6,8 +6,8 @@ import glob
import io
from setuptools.command.easy_install import easy_install
+from setuptools import _path
from setuptools import namespaces
-from setuptools import _normalization
import setuptools
@@ -63,20 +63,17 @@ class develop(namespaces.DevelopInstaller, easy_install):
if self.egg_path is None:
self.egg_path = os.path.abspath(ei.egg_base)
- target = _normalization.path(self.egg_base)
- egg_path = _normalization.path(
- os.path.join(self.install_dir, self.egg_path)
- )
- if egg_path != target:
+ egg_path = os.path.join(self.install_dir, self.egg_path)
+ if not _path.same_path(egg_path, self.egg_base):
raise DistutilsOptionError(
"--egg-path must be a relative path from the install"
- " directory to " + target
+ f" directory to {self.egg_base}"
)
# Make a distribution for the package's source
self.dist = pkg_resources.Distribution(
- target,
- pkg_resources.PathMetadata(target, os.path.abspath(ei.egg_info)),
+ self.egg_base,
+ pkg_resources.PathMetadata(self.egg_base, os.path.abspath(ei.egg_info)),
project_name=ei.egg_name,
)
@@ -96,15 +93,16 @@ class develop(namespaces.DevelopInstaller, easy_install):
path_to_setup = egg_base.replace(os.sep, '/').rstrip('/')
if path_to_setup != os.curdir:
path_to_setup = '../' * (path_to_setup.count('/') + 1)
- resolved = _normalization.path(
+ resolved = _path.normpath(
os.path.join(install_dir, egg_path, path_to_setup)
)
- if resolved != _normalization.path(os.curdir):
+ curdir = _path.normpath(os.curdir)
+ if resolved != curdir:
raise DistutilsOptionError(
"Can't get a consistent path to setup script from"
" installation directory",
resolved,
- _normalization.path(os.curdir),
+ curdir,
)
return path_to_setup
diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py
index 1875641f..a3c7bd79 100644
--- a/setuptools/command/editable_wheel.py
+++ b/setuptools/command/editable_wheel.py
@@ -35,7 +35,14 @@ from typing import (
Union,
)
-from .. import Command, SetuptoolsDeprecationWarning, errors, namespaces, _normalization
+from .. import (
+ Command,
+ SetuptoolsDeprecationWarning,
+ _normalization,
+ _path,
+ errors,
+ namespaces,
+)
from ..discovery import find_package_path
from ..dist import Distribution
from .build_py import build_py as build_py_cls
@@ -568,7 +575,7 @@ def _simple_layout(
return set(package_dir) in ({}, {""})
parent = os.path.commonpath([_parent_path(k, v) for k, v in layout.items()])
return all(
- _normalization.path(Path(parent, *key.split('.'))) == _normalization.path(value)
+ _path.same_path(Path(parent, *key.split('.')), value)
for key, value in layout.items()
)
@@ -697,11 +704,11 @@ def _is_nested(pkg: str, pkg_path: str, parent: str, parent_path: str) -> bool:
>>> _is_nested("b.a", "path/b/a", "a", "path/a")
False
"""
- norm_pkg_path = _normalization.path(pkg_path)
+ norm_pkg_path = _path.normpath(pkg_path)
rest = pkg.replace(parent, "", 1).strip(".").split(".")
return (
pkg.startswith(parent)
- and norm_pkg_path == _normalization.path(Path(parent_path, *rest))
+ and norm_pkg_path == _path.normpath(Path(parent_path, *rest))
)