Skip to content

fix(publish): keep the dist dir a single argument when building - #11171

Merged
radoering merged 2 commits into
python-poetry:mainfrom
simpleqt:fix/publish-dist-dir-with-spaces
Oct 30, 2026
Merged

radoering merged 2 commits into
python-poetry:mainfrom
simpleqt:fix/publish-dist-dir-with-spaces

Conversation

@simpleqt

Copy link
Copy Markdown
Contributor

Problem

poetry publish --build --dist-dir <dir> passes the directory to the build command as a plain string:

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

cleo wraps that string in a StringInput, whose token parser splits on whitespace, so a directory that contains a space — common on Windows, and possible in any absolute path — arrives as two arguments. The build then writes its artifacts to a truncated directory (e.g. <project>/my instead of <project>/my dist) and publish aborts with the misleading No files to publish and exit code 1.

>>> StringInput('--output my dist')._tokens
['--output', 'my', 'dist']
>>> StringInput('--output "my dist"')._tokens
['--output', 'my dist']

Change

The value is quoted and normalized before it is handed over. Path() drops a trailing separator that would otherwise swallow the closing quote, and " is escaped, which cleo honours inside such a token — Windows backslashes are unaffected:

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

Tests

tests/console/commands/test_publish.py::test_publish_dist_dir_with_spaces_and_build_options (parametrized over a relative and an absolute directory containing a space, offline: simple_project fixture plus the responses mock). It fails on main — assert 1 == 0, with the artifacts written to a bogus my directory — and passes with the change. The pre-existing assertion that pinned the unquoted argument string was updated. tests/console/commands/test_publish.py is 20 passed; test_build.py + test_publish.py + tests/publishing are 101 passed.

Prepared with AI assistance; every line was verified by running the cases above.

Copilot AI balanced review requested due to automatic review settings October 26, 2026 13:05

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/console/commands/test_publish.py" line_range="244" />
<code_context>
+
+    if dist_dir == "absolute":
+        output_dir = target_dir / "my dist"
+    else:
+        output_dir = target_dir / dist_dir
+
</code_context>
<issue_to_address>
**Relative-path case is never exercised**

When the `, `target_dir / dist_dir` makes the `

Use a relative `output_dir` for the relative parameter and resolve the expected artifact location against the project directory for assertions.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if the quoted output path is still parsed incorrectly, the build could leave generated artifacts in the wrong directory. Those files remain after a revert, but they can be removed and the build rerun.

Blocking findings: tests/console/commands/test_publish.py:244


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

Comment thread tests/console/commands/test_publish.py Resolved
@simpleqt
simpleqt force-pushed the fix/publish-dist-dir-with-spaces branch from 205525a to f9a6ed1 Compare October 29, 2026 05:28
simpleqt and others added 2 commits October 30, 2026 17:49
`poetry publish --build --dist-dir <dir>` passed the output directory to the
build command as part of an argument string, which cleo parses with its own
tokenizer. A directory containing whitespace was therefore split into several
arguments: the artifacts were written to a truncated directory and publish
aborted with "No files to publish".

The directory is now quoted (and normalized) before it is handed over.
@radoering
radoering force-pushed the fix/publish-dist-dir-with-spaces branch from f9a6ed1 to f1a29b2 Compare October 30, 2026 16:50
@radoering
radoering enabled auto-merge (squash) October 30, 2026 16:56
@radoering
radoering merged commit 906ba21 into python-poetry:main Oct 30, 2026
100 of 102 checks passed
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.

3 participants