This is an automated email from the ASF dual-hosted git repository.

msumit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new 428ce03  Update python openapi gen script to generate code in a 
submodule (#14932)
428ce03 is described below

commit 428ce03783cb0864ac58027ffb326d006ffae784
Author: Sumit Maheshwari <[email protected]>
AuthorDate: Tue Mar 23 14:15:44 2021 +0530

    Update python openapi gen script to generate code in a submodule (#14932)
---
 clients/README.md     |  2 +-
 clients/gen/common.sh | 16 +++++++++++++++-
 clients/gen/go.sh     |  3 +++
 clients/gen/python.sh | 23 +++++++++++++++++++++--
 4 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/clients/README.md b/clients/README.md
index ced9ad6..c192354 100644
--- a/clients/README.md
+++ b/clients/README.md
@@ -22,7 +22,7 @@
 Supported languages:
 
 * [Golang](https://github.com/apache/airflow-client-go) generated through 
`./gen/go.sh`.
-
+* [Python](https://github.com/apache/airflow-client-python) generated through 
`./gen/python.sh`.
 
 ## Dependencies
 
diff --git a/clients/gen/common.sh b/clients/gen/common.sh
index 3688713..c37a94d 100755
--- a/clients/gen/common.sh
+++ b/clients/gen/common.sh
@@ -17,7 +17,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
-OPENAPI_GENERATOR_CLI_VER=5.0.1
+OPENAPI_GENERATOR_CLI_VER=5.1.0
 readonly OPENAPI_GENERATOR_CLI_VER
 
 GIT_USER=${GIT_USER:-apache}
@@ -45,10 +45,24 @@ function validate_input {
     OUTPUT_DIR=$(realpath "$2")
     readonly OUTPUT_DIR
 
+    # cleanup the existing generated code, otherwise generator would skip them
+    for dir in "${CLEANUP_DIRS[@]}"
+    do
+        local dirToClean="${OUTPUT_DIR}/${dir}"
+        echo "Cleaning up ${dirToClean}"
+        rm -rf "${dirToClean:?}"
+    done
+
     # create openapi ignore file to keep generated code clean
     cat <<EOF > "${OUTPUT_DIR}/.openapi-generator-ignore"
 .travis.yml
 git_push.sh
+.gitlab-ci.yml
+requirements.txt
+setup.cfg
+setup.py
+test-requirements.txt
+tox.ini
 EOF
 }
 
diff --git a/clients/gen/go.sh b/clients/gen/go.sh
index d0bff9a..c66339f 100755
--- a/clients/gen/go.sh
+++ b/clients/gen/go.sh
@@ -19,6 +19,9 @@
 CLIENTS_GEN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && 
pwd )"
 readonly CLIENTS_GEN_DIR
 
+CLEANUP_DIRS=(api docs)
+readonly CLEANUP_DIRS
+
 # shellcheck source=./clients/gen/common.sh
 source "${CLIENTS_GEN_DIR}/common.sh"
 
diff --git a/clients/gen/python.sh b/clients/gen/python.sh
index c177521..82905a0 100755
--- a/clients/gen/python.sh
+++ b/clients/gen/python.sh
@@ -19,6 +19,9 @@
 CLIENTS_GEN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && 
pwd )"
 readonly CLIENTS_GEN_DIR
 
+CLEANUP_DIRS=(client docs test README.md)
+readonly CLEANUP_DIRS
+
 # shellcheck source=./clients/gen/common.sh
 source "${CLIENTS_GEN_DIR}/common.sh"
 
@@ -32,8 +35,24 @@ python_config=(
 validate_input "$@"
 
 gen_client python \
-    --package-name airflow_client \
-    --git-repo-id airflow-client-python/airflow \
+    --package-name client \
+    --git-repo-id airflow-client-python \
     --additional-properties "${python_config[*]}"
 
+echo "--- Patching generated code..."
+
+# Post-processing of the generated Python wrapper.
+
+touch "${OUTPUT_DIR}/__init__.py"
+find "${OUTPUT_DIR}/test" -type f -name \*.py -exec sed -i '' -e 
's/client/airflow_client.client/g' {} +
+find "${OUTPUT_DIR}" -type f -a -name \*.md -exec sed -i '' -e 's/# client/# 
Apache Airflow Python Client/g' {} +
+find "${OUTPUT_DIR}" -type f -a -name \*.md -exec sed -i '' -e 's/import 
client/import airflow_client.client/g' {} +
+find "${OUTPUT_DIR}" -type f -a -name \*.md -exec sed -i '' -e 's/from 
client/from airflow_client.client/g' {} +
+find "${OUTPUT_DIR}" -type f -a -name \*.md -exec sed -i '' -e 
's/getattr(client\.models/getattr(airflow_client.client.models/g' {} +
+
+# fix imports
+find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i '' -e 's/import 
client\./import airflow_client.client./g' {} +
+find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i '' -e 's/from 
client/from airflow_client.client/g' {} +
+find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i '' -e 
's/getattr(client\.models/getattr(airflow_client.client.models/g' {} +
+
 run_pre_commit

Reply via email to