Skip to content
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

for wheel, not follow symbolic links #481

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

lucasiscovici2
Copy link
Contributor

@lucasiscovici2 lucasiscovici2 commented Sep 23, 2022

When a symbolic link is included into a wheel, this link is resolved an it may happen that the resource is not added as expected

  • Added tests for changed code.
  • Updated documentation for changed code.

I added the possibility to not resolve symbolic link in BuildIncludeFile.

Path.resolve uses os.path.realpath which "eliminates any symbolic links encountered in the path".

The only possibility is to use Path.absolute which is currently not documented/tested

Allow the builder to not resolve symlinks when "find_files_to_add"
Only set resolve_symlinks(BuildIncludeFile) to true when resolve_symlinks(find_files_to_add) is True or file is not a symlink

Only set resolve_symlinks to false when building wheel

Add test_package_with_include_symbolic_links inside tests/masonry/builders/test_complete.py

Path.resolve uses os.path.realpath which "eliminates any symbolic links encountered in the path".
symbolic links encountered in the path".

The only possibility is to use Path.absolute which is currently not documented/tested
only set resolve_symlinks(BuildIncludeFile) to true when resolve_symlinks(find_files_to_add) is True or file is not a symlink
@neersighted
Copy link
Member

@python-poetry/triage

In the future, please refrain from pinging on PRs that are this new. This change is not obviously correct -- what issue are you trying to solve? Are you attempting to ship symlinks inside a built wheel? What is the use case/is this a common practice permitted by other tools or required for a specific use case?

@neersighted
Copy link
Member

neersighted commented Sep 26, 2022

In fact, symlinks are currently outside the wheel spec and not supported.

See discussion at https://discuss.python.org/t/symbolic-links-in-wheels/1945 for more information.

@lucasiscovici2
Copy link
Contributor Author

lucasiscovici2 commented Sep 26, 2022

@neersighted hello, and thank you for your answer.
But i don't want build wheel with symlink !
I only don't want to follow symlink when building a wheel with a include file/dir which is a symlink, and add the directory as a normal directory, what we expect when building the wheel

@lucasiscovici2
Copy link
Contributor Author

lucasiscovici2 commented Sep 26, 2022

@neersighted This Pr only five the possibility to include the directory (which is a symlink), but without following it and adding only its content, so there is no symlink in the wheel.
For an example, you can look at the test I added. (https://github.com/lucasiscovici2/poetry-core/tree/d628672f28dd8902c095d82548a834bb19868cff/tests/masonry/builders/fixtures/with-include-symbolic) (https://github.com/lucasiscovici2/poetry-core/blob/d628672f28dd8902c095d82548a834bb19868cff/tests/masonry/builders/fixtures/with-include-symbolic/pyproject.toml#L35)

@lucasiscovici2
Copy link
Contributor Author

@neersighted i think you can re-open this PR, it's usefull and it doesn't change the current behavior (when there is no symlink), but is more intuitive and expected when there is a symlink

@neersighted
Copy link
Member

neersighted commented Sep 26, 2022

There is no need to ping three times in 10 minutes 😆

As a participant in this thread I will get a notification every time you comment.

There are three possible behaviors for symlinks:

  1. Treat them transparently, and naively recurse into them (like a directory) and read files like they do not exist.

  2. Treat them as opaque (identifying them with lstat(2)), and copy the symlink itself instead of recursing into it (incompatible with the wheel standard).

  3. See through them (also identifying them with lstat(2)), resolving them to their absolute path and then recursing/manipulating that set of paths.

Poetry currently does behavior 3, and as I understand it, you want to do behavior 1. I originally thought you intended to do behavior 2.

Can you further explain what workflow this enables? sdists need to be able to produce bdists -- if this is intended to enable out-of-tree symlinks to be built into wheels, I see that as counterproductive. If you need assets that are out of your tree, they should be a dependency or incorporated in tree.

Even if we accept it, this will be a breaking change, so I'm not 100% sure about including it before the Poetry 1.3 release at the very least.

@neersighted neersighted reopened this Sep 26, 2022
@lucasiscovici2
Copy link
Contributor Author

lucasiscovici2 commented Sep 26, 2022

Haha sorry, I like to send multiple comments.

Yes it's 1.

So the data and src directory is usually at root level.
When we have to add the data to the package. There are some difficulties. If we include the directory data it will be added in site-packages (this is not what we want).
I found another solution. It is to create a symbolic link of data into the package (in src).
For the sdist we could keep the symbolic link and for the bdist (wheel) we could treat them transparently (as you explained (1.)

@neersighted
Copy link
Member

Right, but the sdist will only be buildable on your system if it references paths that are not in the tree. Is the intention that sdists also should be transparent, so that the files are captured in the sdist as well as the bdist?

What use case do you have where depending on out-of-tree files is necessary and can't be solved by an in-tree method?

@lucasiscovici2
Copy link
Contributor Author

The symlink is in the tree but not inside the package. it's as package data.

@neersighted
Copy link
Member

neersighted commented Sep 26, 2022

I see -- so you want to include data files that are not in the package, but symlinked from elsewhere in the repo -- include = [] will not work for you as that only affects the sdist.

This makes more sense now -- I still would like to get some more eyeballs (cc @finswimmer @radoering) on it to decide if it makes sense.

Would you mind examining some other common tools (e.g. hatch, setuptools, pipenv) and summarizing their existing behavior so we can compare to the rest of the ecosystem?

@sonarcloud
Copy link

sonarcloud bot commented Sep 27, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants