Skip to content

Commit 7f74c6d

Browse files
committed
Split asynchronous generator into its own pull request
Limit this change to synchronous Kubernetes Python generation and shared Python processing. The asynchronous entrypoint and configuration are proposed separately in #306 so the synchronous migration can land first.
1 parent d38e3aa commit 7f74c6d

2 files changed

Lines changed: 25 additions & 27 deletions

File tree

openapi/python-aio.sh

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,34 @@ source "${SETTING_FILE}"
4545

4646
# use openapi-generator to generate library
4747
source "${SCRIPT_ROOT}/openapi-generator/client-generator.sh"
48-
OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT:-v7.24.0}"
48+
OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT:-v6.6.0}"
4949

5050
CLIENT_LANGUAGE=python-asyncio
51-
CLEANUP_DIRS=(client/api client/models docs)
51+
CLEANUP_DIRS=(client/apis client/models docs test)
5252
kubeclient::generator::generate_client "${OUTPUT_DIR}"
5353

54-
echo "--- Post-processing generated code..."
54+
# Generic patches to the generated Python code, most notably renaming the library.
55+
echo "--- Patching generated code..."
5556

56-
python3 "${SCRIPT_ROOT}/postprocess_python.py" \
57-
"${OUTPUT_DIR}" \
58-
"${PACKAGE_NAME}" \
59-
asyncio \
60-
kubernetes.aio
57+
if [ ${PACKAGE_NAME} == "client" ]; then
58+
59+
# Post-processing of the generated Python wrapper.
60+
find "${OUTPUT_DIR}/test" -type f -name \*.py -exec sed -i 's/\bclient/kubernetes.aio.client/g' {} +
61+
find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i 's/\bclient/kubernetes.aio.client/g' {} +
62+
find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i 's/kubernetes.aio.client-python/client-python/g' {} +
63+
64+
# fix imports
65+
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/import client\./import kubernetes.aio.client./g' {} +
66+
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/from client/from kubernetes.aio.client/g' {} +
67+
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/getattr(client\.models/getattr(kubernetes.aio.client.models/g' {} +
68+
69+
else
70+
71+
# Post-processing of the generated Python wrapper.
72+
find "${OUTPUT_DIR}/test" -type f -name \*.py -exec sed -i "s/\\bclient/${PACKAGE_NAME}.client/g" {} +
73+
find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i "s/\\bclient/${PACKAGE_NAME}.client/g" {} +
74+
find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i "s/${PACKAGE_NAME}.client-python/client-python/g" {} +
75+
76+
fi
6177

6278
echo "---Done."

openapi/python-asyncio.xml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,14 @@
1919
<configuration>
2020
<inputSpec>${generator.spec.path}</inputSpec>
2121
<skipValidateSpec>true</skipValidateSpec>
22-
<generatorName>python</generatorName>
22+
<generatorName>python-legacy</generatorName>
2323
<library>asyncio</library>
2424
<gitUserId>kubernetes-client</gitUserId>
2525
<gitRepoId>python</gitRepoId>
26-
<generateApiTests>false</generateApiTests>
27-
<generateModelTests>false</generateModelTests>
28-
<nameMappings>
29-
<nameMapping>$schema=schema</nameMapping>
30-
<nameMapping>continue=_continue</nameMapping>
31-
<nameMapping>except=_except</nameMapping>
32-
<nameMapping>exec=_exec</nameMapping>
33-
<nameMapping>field=field</nameMapping>
34-
<nameMapping>from=_from</nameMapping>
35-
<nameMapping>not=_not</nameMapping>
36-
<nameMapping>schema=schema</nameMapping>
37-
</nameMappings>
38-
<parameterNameMappings>
39-
<parameterNameMapping>continue=_continue</parameterNameMapping>
40-
</parameterNameMappings>
4126
<configOptions>
4227
<packageName>${generator.package.name}</packageName>
4328
<packageVersion>${generator.client.version}</packageVersion>
4429
<sortParamsByRequiredFlag>true</sortParamsByRequiredFlag>
45-
<lazyImports>true</lazyImports>
46-
<useIndependentImplicitClients>true</useIndependentImplicitClients>
47-
<compatibleWithPythonLegacy>true</compatibleWithPythonLegacy>
4830
</configOptions>
4931
<output>${generator.output.path}</output>
5032
</configuration>

0 commit comments

Comments
 (0)