Skip to content

fix(publish): keep --dist-dir working with a trailing separator - #11200

Open
BlueX888 wants to merge 3 commits into
python-poetry:mainfrom
BlueX888:contrib/publish-dist-dir-trailing-separator
Open

BlueX888 wants to merge 3 commits into
python-poetry:mainfrom
BlueX888:contrib/publish-dist-dir-trailing-separator

Conversation

@BlueX888

@BlueX888 BlueX888 commented Nov 3, 2026

Copy link
Copy Markdown

Resolves: #11199

Summary

  • Normalize --dist-dir with str(Path(dist_dir)) before escaping it for the nested poetry build call. This restores the normalization described in fix(publish): keep the dist dir a single argument when building #11171 and prevents a trailing native directory separator from escaping the closing quote of the generated --output "..." argument. Before this change, a trailing native separator on Windows produced a dist" build target and failed with [WinError 123].
  • Add a regression case to test_publish_dist_dir_with_spaces_and_build_options, parametrized with "to build/dist" + os.sep. The test asserts artifacts land in the exact requested directory and that no dist" directory is created. It drives the command with ArgvInput because CommandTester.execute() parses a string with cleo's tokenizer and cannot represent an argument that ends with a backslash.

Testing

  • python -m pytest tests/console/commands/test_publish.py -k dist_dir -q: 10 passed with the fix; on Windows without the fix, 1 failed / 9 passed (the new trailing-separator case fails with [WinError 123] on to build\dist").
  • python -m pytest tests/console/commands/test_publish.py -q: 21 passed.
  • python -m mypy src/poetry/console/commands/publish.py: no issues.
  • Manual Windows repro: poetry publish --build --dry-run --dist-dir 'dist\' failed with [WinError 123] ... 'dist"' before the fix; after the fix it builds and uploads from dist. The --dist-dir "my dist" control (space, no trailing separator) keeps working.
  • POSIX was not executed; the native POSIX separator / already worked and is not affected by this Windows-specific path.

Checklist

  • Added tests for changed code.
  • Updated documentation for changed code (not applicable).
  • No changelog fragment added: CHANGELOG.md is updated at release time and the repo has no per-PR fragment convention.

Normalize the directory with Path before escaping it for the nested
build command, so a trailing native directory separator cannot escape
the closing quote of the generated --output argument.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Linked issues

#11199 publish --build --dist-dir fails when the directory ends with a separator · 1 of 1 met

# Requirement Status Notes
1 Write build artifacts to exactly the requested directory when --dist-dir ends with a native directory separator. ✅ Met The nested build output path is normalized with str(Path(dist_dir)) before quoting, and the regression test checks the artifacts are in the requested directory.

Sourcery assessment

Needs a human reviewer. If path normalization selects the wrong output directory, the build can leave generated artifacts there; they are bounded and can be removed or rebuilt. Reverting restores the old behavior but does not remove files already created.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@BlueX888
BlueX888 force-pushed the contrib/publish-dist-dir-trailing-separator branch from 57b2b12 to 235abe3 Compare November 3, 2026 17:43

@agammann agammann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Handle a Windows drive or UNC root ending in a separator

In publish.py, str(Path(dist_dir)) keeps the trailing backslash when dist_dir is a root such as C:\ or \\server\share\. In that case the generated quoted --output argument still ends in a backslash before its closing quote, which Cleo treats as escaped. Thus poetry publish --build --dist-dir C:\ still has the trailing-separator failure this PR addresses. Could the nested build command receive an argv list, or could this special case escape the final backslash? A Windows root-path regression case would catch it.

A Windows drive, UNC or current-drive root keeps its trailing separator
after Path normalization, so the quoted --output argument still ended in
a backslash and cleo's tokenizer consumed the closing quote. Append a
dot component instead; Path() drops it again when the nested build
command resolves the directory.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@BlueX888

BlueX888 commented Nov 4, 2026

Copy link
Copy Markdown
Author

Good catch — fixed in 275f4ef2.

Path keeps the trailing separator for a drive, UNC, or current-drive root, and passing the path as an argv list isn't available at this layer: cleo 2.1.0's Command.call(name, args: str | None) always builds a StringInput, so the nested call has to stay a string. Instead of escaping the backslash, _build_output_args now appends a dot component when the normalized path ends in a separator:

  • C:\ -> --output "C:\."
  • \server\share\ -> --output "\server\share\."
  • \ -> --output "\."

The only consumer is build.py:136 (Path(options.output)), which drops the dot again, so the directory is unchanged. Extended-length/device roots (\?\C:\, \.\C:\, \?\UNC\server\share\) also resolve back to the same path.

Added test_build_output_args_escape_final_separator, which runs the generated argument string through cleo's TokenParser for all three roots and asserts it stays one token; it fails without the dot. tests/console/commands/test_publish.py: 24 passed; ruff check / ruff format --check clean.

@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026

Copy link
Copy Markdown

Linked issues

Checked at commit 9289c26

#11199 publish --build --dist-dir fails when the directory ends with a separator · 1 of 1 met

# Requirement Status Notes
1 Write build artifacts to exactly the requested directory for a normal path ending in a native separator. ✅ Met The helper normalizes the path before quoting it, and the regression test checks that artifacts land in the requested directory when it has a trailing separator.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants