Skip to content

poetry build -C ./relative/path doesnt work properly #9432

@OhioDschungel6

Description

@OhioDschungel6

Description

When your projekt looks like the following:

.
├── poetry.lock
├── pyproject.toml
└── src
    └── testproject
        └── __init__.py

the command "poetry build -C ." doesn't work properly.
In general relative paths are not resolved properly in this case (you have to specify "packages = [{include = "testproject", from="src"}]" in your pyproject.toml).

Simple way to reproduce:

  • Check out poetry repo
  • "poetry build" will work
  • "poetry build -C ." wont work

Workarounds

Use absolute paths or use "poetry build" without -C

Fix

I have provided a possible fix in 9433

Poetry Installation Method

other

Operating System

Windows 10/11

Poetry Version

1.8.3

Poetry Configuration

Clean install. No further configuration.

Python Sysconfig

No response

Example pyproject.toml

[tool.poetry]
name = "testproject"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
packages = [{include = "testproject", from="src"}]

[tool.poetry.dependencies]
python = "^3.11"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

Poetry Runtime Logs

Command:  poetry -vvv build --directory "."
Building testproject (0.1.0)
  - Building sdist
  - Adding: src\testproject\__init__.py
  - Adding: pyproject.toml
  - Built testproject-0.1.0.tar.gz
  - Building wheel
  - Adding: src\testproject\__init__.py

  Stack trace:

  12  ~\scoop\apps\poetry\1.8.3\venv\Lib\site-packages\cleo\application.py:327 in run
       325│
       326│             try:
     → 327│                 exit_code = self._run(io)
       328│             except BrokenPipeError:
       329│                 # If we are piped to another process, it may close early and send a

  11  ~\scoop\apps\poetry\1.8.3\venv\Lib\site-packages\poetry\console\application.py:190 in _run
       188│         self._load_plugins(io)
       189│
     → 190│         exit_code: int = super()._run(io)
       191│         return exit_code
       192│

  10  ~\scoop\apps\poetry\1.8.3\venv\Lib\site-packages\cleo\application.py:431 in _run
       429│             io.input.interactive(interactive)
       430│
     → 431│         exit_code = self._run_command(command, io)
       432│         self._running_command = None
       433│

   9  ~\scoop\apps\poetry\1.8.3\venv\Lib\site-packages\cleo\application.py:473 in _run_command
       471│
       472│         if error is not None:
     → 473│             raise error
       474│
       475│         return terminate_event.exit_code

   8  ~\scoop\apps\poetry\1.8.3\venv\Lib\site-packages\cleo\application.py:457 in _run_command
       455│
       456│             if command_event.command_should_run():
     → 457│                 exit_code = command.run(io)
       458│             else:
       459│                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

   7  ~\scoop\apps\poetry\1.8.3\venv\Lib\site-packages\cleo\commands\base_command.py:117 in run
       115│         io.input.validate()
       116│
     → 117│         return self.execute(io) or 0
       118│
       119│     def merge_application_definition(self, merge_args: bool = True) -> None:

   6  ~\scoop\apps\poetry\1.8.3\venv\Lib\site-packages\cleo\commands\command.py:61 in execute
        59│
        60│         try:
     →  61│             return self.handle()
        62│         except KeyboardInterrupt:
        63│             return 1

   5  ~\scoop\apps\poetry\1.8.3\venv\Lib\site-packages\poetry\console\commands\build.py:66 in handle
        64│             if not dist_dir.is_absolute():
        65│                 dist_dir = self.poetry.pyproject_path.parent / dist_dir
     →  66│             self._build(fmt, executable=env.python, target_dir=dist_dir)
        67│
        68│         return 0

   4  ~\scoop\apps\poetry\1.8.3\venv\Lib\site-packages\poetry\console\commands\build.py:49 in _build
        47│
        48│         for builder in builders:
     →  49│             builder(self.poetry, executable=executable).build(target_dir)
        50│
        51│     def handle(self) -> int:

   3  ~\scoop\apps\poetry\1.8.3\venv\Lib\site-packages\poetry\core\masonry\builders\wheel.py:124 in build
       122│             else:
       123│                 self._build(zip_file)
     → 124│                 self._copy_module(zip_file)
       125│
       126│             self._copy_file_scripts(zip_file)

   2  ~\scoop\apps\poetry\1.8.3\venv\Lib\site-packages\poetry\core\masonry\builders\wheel.py:270 in _copy_module
       268│         # sorting everything so the order is stable.
       269│         for file in sorted(to_add, key=lambda x: x.path):
     → 270│             self._add_file(wheel, file.path, file.relative_to_target_root())
       271│
       272│     def prepare_metadata(self, metadata_directory: Path) -> Path:

   1  ~\scoop\apps\poetry\1.8.3\venv\Lib\site-packages\poetry\core\masonry\builders\wheel.py:423 in _add_file
       421│
       422│         # Normalize permission bits to either 755 (executable) or 644
     → 423│         st_mode = full_path.stat().st_mode
       424│         new_mode = normalize_file_permissions(st_mode)
       425│         zinfo.external_attr = (new_mode & 0xFFFF) << 16  # Unix attributes

  FileNotFoundError

  [WinError 3] The system cannot find the path specified: 'C:\\Users\\andre\\IdeaProjects\\TestProject\\src\\src\\testproject\\__init__.py'

  at ~\scoop\apps\python\current\Lib\pathlib.py:1013 in stat
      1009│         """
      1010│         Return the result of the stat() system call on this path, like
      1011│         os.stat() does.
      1012│         """
    → 1013│         return os.stat(self, follow_symlinks=follow_symlinks)
      1014│
      1015│     def owner(self):
      1016│         """
      1017│         Return the login name of the file owner.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expectedstatus/triageThis issue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions