Skip to content

publish --build --dist-dir fails when the directory ends with a separator #11199

Open

Description

@BlueX888

Description

poetry publish --build --dist-dir <dir> does not write artifacts to <dir> when <dir> ends with a native directory separator, e.g. --dist-dir 'dist\' or --dist-dir "C:\path with space\" on Windows.

This is a regression from #11171. PublishCommand.handle() creates the nested build command's argument string like this:

escaped_dist_dir = dist_dir.replace('"', '\\"')
exit_code = self.call("build", args=f'--output "{escaped_dist_dir}"')

When dist_dir ends with a backslash, the generated string ends in \". Cleo's tokenizer treats \" as an escaped quote, so the closing quote is consumed and the build target becomes dist" (with a literal quote character).

On Windows the build fails immediately:

Building sdist
  - Building sdist
  [WinError 123] The filename, directory name, or volume label syntax is incorrect: '...\dist"'

The tokenizer behavior is platform-independent; the reproduction and fix are verified on Windows, where a trailing native separator is a backslash.

Expected: artifacts are written to exactly the directory passed to --dist-dir for a normal directory path, including a path with a trailing separator. (Filesystem-root paths such as C:\ are a separate pre-existing tokenization edge and are not covered here.) The description of #11171 said the path was normalized with str(Path(dist_dir)), but commit f1a29b2 removed that normalization from the merged code.

Reproduced on main at 6ecadf5 (Poetry 2.5.1), on Windows 11:

$ python -m poetry publish --build --dry-run --dist-dir 'dist\'
Building repro-project (0.1.0)
Building sdist
  - Building sdist
[WinError 123] The filename, directory name, or volume label syntax is incorrect: '...\dist"'

The control --dist-dir "my dist" (space, no trailing separator) succeeds and writes into my dist.

Workarounds

Drop the trailing separator: use --dist-dir dist instead of --dist-dir 'dist\'.

Poetry Installation Method

other (source checkout)

Operating System

Windows 11 Pro 10.0.26200 (reproduction and fix verified on Windows; the tokenizer itself is platform-independent).

Poetry Version

Poetry (version 2.5.1), main at 6ecadf5 (unreleased main after #11171; the 2.5.1 release predates #11171 and is unaffected).

Poetry Configuration

Paths redacted; the remaining values are the defaults from poetry config --list.

cache-dir = "<cache-dir>"
data-dir = "<data-dir>"
installer.parallel = true
installer.re-resolve = false
keyring.enabled = true
python.installation-dir = "{data-dir}/python"
requests.max-retries = 0
solver.lazy-wheel = true
solver.min-release-age = 0
system-git-client = false
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = false

Python Sysconfig

Platform: win-amd64; Python version: 3.12; scheme: venv. Full paths omitted.

Example pyproject.toml

[tool.poetry]
name = "repro-project"
version = "0.1.0"
description = ""
authors = ["Test <[email protected]>"]
packages = [{ include = "mypkg" }]

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

Poetry Runtime Logs

# python -m poetry -vvv publish --build --dry-run --dist-dir 'dist\'
...
  1  .../poetry/core/masonry/builders/sdist.py:68 in build
       67│         if not target_dir.exists():
    →  68│             target_dir.mkdir(parents=True)

  OSError

  [WinError 123] The filename, directory name, or volume label syntax is incorrect: '...\dist"'

  at .../pathlib.py:1311 in mkdir

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions