-
Notifications
You must be signed in to change notification settings - Fork 69
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
Preserve symlink contents in sdists #713
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
import argparse | ||
import collections | ||
import contextlib | ||
import copy | ||
import difflib | ||
import functools | ||
import importlib.machinery | ||
|
@@ -854,6 +855,17 @@ def sdist(self, directory: Path) -> pathlib.Path: | |
|
||
with tarfile.open(meson_dist_path, 'r:gz') as meson_dist, mesonpy._util.create_targz(sdist_path) as sdist: | ||
for member in meson_dist.getmembers(): | ||
# Wheels do not support links, though sdist tarballs could. For portability, reduce these to regular files. | ||
if member.islnk() or member.issym(): | ||
# Symlinks are relative to member directory, but hard links are relative to tarball root. | ||
path = member.name.rsplit('/', 1)[0] + '/' if member.issym() else '' | ||
orig = meson_dist.getmember(path + member.linkname) | ||
member = copy.copy(member) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the copy here necessary? |
||
member.mode = orig.mode | ||
member.mtime = orig.mtime | ||
member.size = orig.size | ||
member.type = tarfile.REGTYPE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can't the link point to a directory, or to a special file? |
||
|
||
if member.isfile(): | ||
file = meson_dist.extractfile(member.name) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# SPDX-FileCopyrightText: 2024 The meson-python developers | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
project('symlinks', version: '1.0.0') | ||
|
||
py = import('python').find_installation() | ||
|
||
install_subdir( | ||
'subdir', | ||
install_dir: py.get_install_dir(pure: false), | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-FileCopyrightText: 2024 The meson-python developers | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
[build-system] | ||
build-backend = 'mesonpy' | ||
requires = ['meson-python'] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# SPDX-FileCopyrightText: 2024 The meson-python developers | ||
# | ||
# SPDX-License-Identifier: MIT |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test.py |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# SPDX-FileCopyrightText: 2024 The meson-python developers | ||
# | ||
# SPDX-License-Identifier: MIT |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,6 +339,23 @@ def test_install_subdir(wheel_install_subdir): | |
} | ||
|
||
|
||
def test_install_symlink(wheel_symlinks): | ||
artifact = wheel.wheelfile.WheelFile(wheel_symlinks) | ||
# Handling of the exclude_files and exclude_directories requires | ||
# Meson 1.1.0, see https://github.com/mesonbuild/meson/pull/11432. | ||
# Run the test anyway to ensure that meson-python can produce a | ||
# wheel also for older versions of Meson. | ||
if MESON_VERSION >= (1, 1, 99): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't use |
||
assert wheel_contents(artifact) == { | ||
'symlinks-1.0.0.dist-info/METADATA', | ||
'symlinks-1.0.0.dist-info/RECORD', | ||
'symlinks-1.0.0.dist-info/WHEEL', | ||
'subdir/__init__.py', | ||
'subdir/test.py', | ||
'subdir/symlink.py', | ||
} | ||
|
||
|
||
def test_vendored_meson(wheel_vendored_meson): | ||
# This test will error if the vendored meson.py wrapper script in | ||
# the test package isn't used. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are meson or git enforcing that symlinks do not point to location outside the tarball or outside the repository?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git does not appear to enforce any rules about committed symlinks.