python-poetry / python-poetry/poetry

poetry-core 2.0.0 can no longer build when the sourcetree contains symlinks outside itself

Open
#9,982 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/bug status/triage
Dominant language
Python
Stars
34.3k
Forks
2.5k
Avg merge
2d 19h
Merged PRs (30d)
30

Description

Description

Since the release of poetry-core v2.0.0, twine can no longer build a poetry package whose source tree contains symlinks outside itself. Previously it could. Now it fails with errors like

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
    main()
  File "/usr/local/lib/python3.10/dist-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
    json_out["return_val"] = hook(**hook_input["kwargs"])
  File "/usr/local/lib/python3.10/dist-packages/pyproject_hooks/_in_process/_in_process.py", line 280, in build_wheel
    return _build_backend().build_wheel(
  File "/tmp/build-env-cf76kflm/lib/python3.10/site-packages/poetry/core/masonry/api.py", line 58, in build_wheel
    return WheelBuilder.make_in(
  File "/tmp/build-env-cf76kflm/lib/python3.10/site-packages/poetry/core/masonry/builders/wheel.py", line 91, in make_in
    wb.build(target_dir=directory)
  File "/tmp/build-env-cf76kflm/lib/python3.10/site-packages/poetry/core/masonry/builders/wheel.py", line 131, in build
    self._copy_module(zip_file)
  File "/tmp/build-env-cf76kflm/lib/python3.10/site-packages/poetry/core/masonry/builders/wheel.py", line 308, in _copy_module
    self._add_file(wheel, file.path, file.relative_to_target_root())
  File "/tmp/build-env-cf76kflm/lib/python3.10/site-packages/poetry/core/masonry/builders/builder.py", line 374, in relative_to_target_root
    path = self.relative_to_source_root()
  File "/tmp/build-env-cf76kflm/lib/python3.10/site-packages/poetry/core/masonry/builders/builder.py", line 371, in relative_to_source_root
    return self.path.relative_to(self.source_root)
  File "/usr/lib/python3.10/pathlib.py", line 818, in relative_to
    raise ValueError("{!r} is not in the subpath of {!r}"
ValueError: '/true/location/of/myschema.json' is not in the subpath of '/mypackage/src' OR one path is relative and the other is absolute.

Is this deliberate? I realise it is an edge case, and probably there are arguments for disallowing these symlinks.

(It doesn't seem to be possible for me to raise an issue against poetry-core itself.)

Workarounds
Poetry Installation Method

other

Operating System

Ubuntu 22.04

Poetry Version

poetry-core v2.0.0

Poetry Configuration
-
Python Sysconfig

No response

Example pyproject.toml

No response

Poetry Runtime Logs
-

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in poetry/core/masonry/builders/builder.py, especially relative_to_source_root and relative_to_target_root, then follow the wheel builder call in poetry/core/masonry/builders/wheel.py. Reproduce the reported wheel build with a source-tree symlink pointing outside the tree and determine the intended handling. Done means the reported package builds successfully without regressing existing wheel-building behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.