Repository navigation
Add source folder variable to Python Client - #24980
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 40 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
c4d20b0 to
22201b9
Compare
|
FYI: The already existing are a mess as there is |
fa0311
left a comment
There was a problem hiding this comment.
LGTM. One small suggestion: could we add a regression test for sourceFolder=src?
Currently the Python client generator generates a "flat layout", where the generated Python module is directly below the project root. This is a problem for editable installs as tools like `uv` have to generate a complicated "finder" to load the modules. Several tools like `mypy` and `ty` fail to use it as they implement their own "import mechanism" incompatible with the generated finder. This can be mitigated by switching to the "src layout", where all files live in the sub-directory "src". Tools like `uv` then only have to place the absolute path in a `.pth` file, which also works with `mypy` and `ty`. Similar to OpenAPITools#12119 but in the reverse add a new configuration option "sourceFolder" to make the base folder configurable. For backward compatibility it is unset by default, which generates the previous "flat layout". Set it to "src" to generate the "src layout". Link: https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/ Signed-off-by: Philipp Hahn <p.hahn@avm.de>
Yes, took me some time but I have added 2 new unit-tests and extended one to test, that the default is the flat-layout. |
Currently the Python client generator generates a "flat layout", where the generated Python module is directly below the project root:
This is a problem for editable installs as tools like
uvhave to generate a complicated "finder" to load the modules:Several tools like
mypyandtyfail to use it as they implement their own "import mechanism":This can be mitigated by switching to the "src layout", where all files live in the sub-directory "src".
Tools like
uvthen only have to place the absolute path in a.pthfile, which also works withmypyandty:Similar to #12119 but in the reverse add a new configuration option "sourceFolder" to make the base folder configurable. For backward compatibility it is empty by default, which generates the previous "flat layout". Set it to "src" to generate the "src layout".
@cbornet @tomplus @krjakbrjak @fa0311 Please have a look. My Java coding experience is ~15y old and I have never used Mustard.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Running the test fails for me because of some C++ errors:
As the same tests fail on
master() and I have not changed anything related to those tests, I'm ignoring the failures and post this PR anyway.CONTRIBUTING.mddoes not even provide any hint thatlibboost-json(and more) is needed. I'm using Ubuntu 24.04 LTS on amd64.Summary by cubic
Adds a
sourceFolderoption to the Python client generator so generated code can use the src layout instead of the flat layout.The flat layout (default, when
sourceFolderis empty) generates the Python module directly under the project root, which breaks editable installs in tools likeuv,mypy, andty. SettingsourceFoldertosrcplaces all generated source undersrc/, which those tools handle correctly.setup.pyis updated to usepackage_dirandfind_packages(where=...)whensourceFolderis set.sourceFolder, empty by default for backward compatibility.setup.mustacheemitspackage_dirand awhereargument forfind_packageswhen the option is set.pyproject.mustacheusessourceFolderin mypy targets and Poetry packaging when set.Written for commit 0cf6c59. Summary will update on new commits.