Replies: 2 comments
-
Hi @yhkee0404, thank you for sharing this issue! This is a limitation of the builtin Python AST parsing and unparsing feature. The output will result with the differences you mention: spaces, line breaks and comments. There's third-party tools that does the AST parsing better than the builtin Python, but I have thought of it as a good-enough tradeoff. The rewrite is only needed and recommended for the use case when building several installable packages from a Polylith repo when users expect to install more than one of those packages (to avoid namespace collisions). Additionally, I would recommend to only build wheels with this. I have thought of sdists as snapshots of the source code, but wheels as something "built" and packaged for a specific use case. |
Beta Was this translation helpful? Give feedback.
-
I will transform this into a "discussion" and in the ideas section, for further investigation about using third-party AST/CST tooling. Thank you for sharing the link to the Instagram repo 🙏 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
Setting top-namespace in
[tool.polylith.build]
ofpyproject.toml
discards single-line comments or whitespaces while rewriting the source filesTo Reproduce
Steps to reproduce the behavior:
python-polylith-example-uv
:https://github.com/DavidVujic/python-polylith-example-uv/blob/main/projects/consumer_project/pyproject.toml#L25
uv build --sdist projects/consumer_project/ && tar -xzvf dist/consumer_project-0.1.0.tar.gz -C stripped
top-namespace = "my_custom_ns"
in theprojects/consumer_project/pyproject.toml
#
or trivial whitespaces tocomponents/example/kafka/consumer.py
uv build --sdist projects/consumer_project/ && tar -xzvf dist/consumer_project-0.1.0.tar.gz -C preserved
stripped/consumer_project-0.1.0/my_custom_ns/example/kafka/consumer.py
andpreserved/consumer_project-0.1.0/example/kafka/consumer.py
Expected behavior
It should make no difference in source files other than prepending the new top-namespace to the previous single top-namespace in the
import
lines.Desktop (please complete the following information):
Additional context
python-polylith/components/polylith/parsing/rewrite.py
Line 70 in af30d4e
Beta Was this translation helpful? Give feedback.
All reactions