Skip to content

Commit 4929334

Browse files
committed
Avoid '../' when writing license paths to wheel/metadata
1 parent dd0c994 commit 4929334

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

setuptools/_core_metadata.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ def write_field(key, value):
207207
if self.long_description_content_type:
208208
write_field('Description-Content-Type', self.long_description_content_type)
209209

210-
self._write_list(file, 'License-File', self.license_files or [])
210+
safe_license_files = map(_safe_license_file, self.license_files or [])
211+
self._write_list(file, 'License-File', safe_license_files)
211212
_write_requirements(self, file)
212213

213214
for field, attr in _POSSIBLE_DYNAMIC_FIELDS.items():
@@ -293,6 +294,14 @@ def _distribution_fullname(name: str, version: str) -> str:
293294
)
294295

295296

297+
def _safe_license_file(file):
298+
# XXX: Do we need this after the deprecation discussed in #4892??
299+
normalized = os.path.normpath(file).replace(os.sep, "/")
300+
if "../" in normalized:
301+
return os.path.basename(normalized) # Temporarily restore pre PEP639 behaviour
302+
return normalized
303+
304+
296305
_POSSIBLE_DYNAMIC_FIELDS = {
297306
# Core Metadata Field x related Distribution attribute
298307
"author": "author",

setuptools/command/bdist_wheel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from wheel.wheelfile import WheelFile
2424

2525
from .. import Command, __version__, _shutil
26+
from .._core_metadata import _safe_license_file
2627
from .._normalization import safer_name
2728
from ..warnings import SetuptoolsDeprecationWarning
2829
from .egg_info import egg_info as egg_info_cls
@@ -582,7 +583,8 @@ def adios(p: str) -> None:
582583

583584
licenses_folder_path = os.path.join(distinfo_path, "licenses")
584585
for license_path in self.license_paths:
585-
dist_info_license_path = os.path.join(licenses_folder_path, license_path)
586+
safe_path = _safe_license_file(license_path)
587+
dist_info_license_path = os.path.join(licenses_folder_path, safe_path)
586588
os.makedirs(os.path.dirname(dist_info_license_path), exist_ok=True)
587589
shutil.copy(license_path, dist_info_license_path)
588590

0 commit comments

Comments
 (0)