You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ac5d897
Browse filesBrowse the repository at this point in the historyBrowse files
Add source folder variable to Python Client (#24980)
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 #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>
Co-authored-by: Philipp Hahn <p.hahn@avm.de>
Copy file name to clipboardExpand all lines: docs/generators/python.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,6 +36,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
36
36
|projectName|python project name in setup.py (e.g. petstore-api).||null|
37
37
|recursionLimit|Set the recursion limit. If not set, use the system default value.||null|
38
38
|setEnsureAsciiToFalse|When set to true, add `ensure_ascii=False` in json.dumps when creating the HTTP request body.||false|
39
+
|sourceFolder|directory for generated python source code; 'src' for _src layout_, unset (or '.') for _flat layout_.||null|
39
40
|supportHttpxSync|Generate synchronous '_sync' variants of each API method (httpx and httpx2 libraries only). Each '_sync' method simply calls the corresponding async method and waits for its completion, so both synchronous and asynchronous methods are available from the same API class.||false|
40
41
|useIndependentImplicitClients|Give API instances without an explicit or registered default ApiClient an owned client with a copied Configuration.||false|
41
42
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped.||false|
cliOptions.add(newCliOption(BUILD_SYSTEM, "Build system to use in pyproject.toml (setuptools, hatchling).").defaultValue("setuptools"));
232
+
cliOptions.add(newCliOption(CodegenConstants.SOURCE_FOLDER, "directory for generated python source code; 'src' for _src layout_, unset (or '.') for _flat layout_."));
230
233
cliOptions.add(CliOption.newBoolean(SUPPORT_HTTPX_SYNC, "Generate synchronous '_sync' variants of each API method (httpx and httpx2 libraries only). " +
231
234
"Each '_sync' method simply calls the corresponding async method and waits for its completion, " +
232
235
"so both synchronous and asynchronous methods are available from the same API class.").defaultValue(Boolean.FALSE.toString()));
@@ -296,6 +299,9 @@ public void processOpts() {
296
299
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
0 commit comments