Skip to content

Commit

Permalink
Various improvements to the SDK generation process (cvat-ai#5678)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpecLad authored Feb 14, 2023
1 parent 89f403b commit 87f07fd
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 288 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ jobs:
--entrypoint /bin/bash -u root cvat/server \
-c 'python manage.py spectacular --file /transfer/schema.yml'
pip3 install --user -r cvat-sdk/gen/requirements.txt
cd cvat-sdk/
gen/generate.sh
cd ..
./cvat-sdk/gen/generate.sh
cp -r cvat-sdk/* /tmp/cvat_sdk/
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/helm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ jobs:
kubectl exec $(kubectl get pods -l component=server -o jsonpath='{.items[0].metadata.name}') -- /bin/bash -c "python manage.py spectacular --file /tmp/schema.yml"
kubectl cp $(kubectl get pods -l component=server -o jsonpath='{.items[0].metadata.name}'):/tmp/schema.yml cvat-sdk/schema/schema.yml
pip3 install --user -r cvat-sdk/gen/requirements.txt
cd cvat-sdk/
gen/generate.sh
cd ..
./cvat-sdk/gen/generate.sh
- name: Install test requirements
run: |
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ jobs:
--entrypoint /bin/bash -u root cvat/server \
-c 'python manage.py spectacular --file /transfer/schema.yml'
pip3 install --user -r cvat-sdk/gen/requirements.txt
cd cvat-sdk/
gen/generate.sh
cd ..
./cvat-sdk/gen/generate.sh
cp -r cvat-sdk/* /tmp/cvat_sdk/
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ jobs:
--entrypoint /bin/bash -u root cvat/server \
-c 'python manage.py spectacular --file /transfer/schema.yml'
pip3 install --user -r cvat-sdk/gen/requirements.txt
cd cvat-sdk/
gen/generate.sh
cd ..
./cvat-sdk/gen/generate.sh
pip3 install --user 'cvat-sdk/[pytorch]'
pip3 install --user cvat-cli/
Expand Down
4 changes: 1 addition & 3 deletions cvat-sdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ schema/
# Generated code
/cvat_sdk/api_client/
/cvat_sdk/version.py
/requirements/
/docs/
/requirements/api_client.txt
/setup.py
/README.md
/MANIFEST.in
2 changes: 2 additions & 0 deletions cvat-sdk/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#!docs/README.md

# For safety
/MANIFEST.in
/cvat_sdk/__init__.py
/config
/gen
Expand All @@ -31,6 +32,7 @@
/types.py

# Don't generate these files
/README.md
/git_push.sh
/setup.cfg
/test-requirements.txt
Expand Down
1 change: 0 additions & 1 deletion cvat-sdk/.remarkignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
cvat-sdk/docs/
cvat-sdk/README.md
File renamed without changes.
File renamed without changes.
33 changes: 15 additions & 18 deletions cvat-sdk/gen/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,39 @@ GENERATOR_VERSION="v6.0.1"
VERSION="2.3.0"
LIB_NAME="cvat_sdk"
LAYER1_LIB_NAME="${LIB_NAME}/api_client"
DST_DIR="."
TEMPLATE_DIR="gen"
DST_DIR="$(cd "$(dirname -- "$0")/.." && pwd)"
TEMPLATE_DIR_NAME="gen"
TEMPLATE_DIR="$DST_DIR/$TEMPLATE_DIR_NAME"
POST_PROCESS_SCRIPT="${TEMPLATE_DIR}/postprocess.py"

mkdir -p "${DST_DIR}/"
rm -f -r "${DST_DIR}/docs" "${DST_DIR}/${LAYER1_LIB_NAME}" "requirements/"
cp "${TEMPLATE_DIR}/templates/openapi-generator/.openapi-generator-ignore" "${DST_DIR}/"
rm -f -r "${DST_DIR}/docs" "${DST_DIR}/${LAYER1_LIB_NAME}" \
"${DST_DIR}/requirements/api_client.txt"

# Pass template dir here
# https://github.com/OpenAPITools/openapi-generator/issues/8420
docker run --rm -v "$PWD":"/local" -u "$(id -u)":"$(id -g)" \
docker run --rm -v "$DST_DIR:/local" -u "$(id -u)":"$(id -g)" \
openapitools/openapi-generator-cli:${GENERATOR_VERSION} generate \
-t "/local/${TEMPLATE_DIR}/templates/openapi-generator/" \
-t "/local/${TEMPLATE_DIR_NAME}/templates/openapi-generator/" \
-i "/local/schema/schema.yml" \
--config "/local/${TEMPLATE_DIR}/generator-config.yml" \
--config "/local/${TEMPLATE_DIR_NAME}/generator-config.yml" \
-p "packageVersion=$VERSION" \
-g python \
-o "/local/${DST_DIR}/"
-o "/local/"

sed -e "s|{{packageVersion}}|${VERSION}|g" "${TEMPLATE_DIR}/templates/version.py.template" > "${DST_DIR}/${LIB_NAME}/version.py"
cp -r "${TEMPLATE_DIR}/templates/requirements" "${DST_DIR}/"
cp -r "${TEMPLATE_DIR}/templates/MANIFEST.in" "${DST_DIR}/"
echo "VERSION = \"$VERSION\"" > "${DST_DIR}/${LIB_NAME}/version.py"
mv "${DST_DIR}/requirements.txt" "${DST_DIR}/requirements/api_client.txt"

# Do custom postprocessing for code files
"${POST_PROCESS_SCRIPT}" --schema "schema/schema.yml" --input-path "${DST_DIR}/${LIB_NAME}"
"${POST_PROCESS_SCRIPT}" --schema "${DST_DIR}/schema/schema.yml" \
--input-path "${DST_DIR}/${LIB_NAME}"

# Do custom postprocessing for docs files
"${POST_PROCESS_SCRIPT}" --schema "schema/schema.yml" --input-path "${DST_DIR}/docs" --file-ext '.md'
"${POST_PROCESS_SCRIPT}" --schema "schema/schema.yml" --input-path "${DST_DIR}/README.md"
"${POST_PROCESS_SCRIPT}" --schema "${DST_DIR}/schema/schema.yml" \
--input-path "${DST_DIR}/docs" --file-ext '.md'

API_DOCS_DIR="${DST_DIR}/docs/apis/"
MODEL_DOCS_DIR="${DST_DIR}/docs/models/"
mkdir "${API_DOCS_DIR}"
mkdir "${MODEL_DOCS_DIR}"
mv "${DST_DIR}/docs/"*Api.md "${API_DOCS_DIR}"
mv "${DST_DIR}/docs/"*.md "${MODEL_DOCS_DIR}"
mv "${DST_DIR}/README.md" "${DST_DIR}/docs/"

cp "${TEMPLATE_DIR}/templates/README.md.template" "${DST_DIR}/README.md"
1 change: 0 additions & 1 deletion cvat-sdk/gen/generator-config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
additionalProperties:
projectName: "cvat_sdk"
packageVersion: "2.0-alpha"
packageUrl: "https://github.com/cvat-ai/cvat"
packageName: "cvat_sdk.api_client"
initRequiredVars: true
Expand Down
2 changes: 2 additions & 0 deletions cvat-sdk/gen/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def main(args=None):
processor.process_dir(args.input_path, file_ext=args.file_ext)
elif osp.isfile(args.input_path):
processor.process_file(args.input_path)
else:
return f"error: input {args.input_path} is neither a file nor a directory"

return 0

Expand Down
40 changes: 0 additions & 40 deletions cvat-sdk/gen/templates/openapi-generator/.openapi-generator-ignore

This file was deleted.

36 changes: 0 additions & 36 deletions cvat-sdk/gen/templates/openapi-generator/README.mustache

This file was deleted.

Loading

0 comments on commit 87f07fd

Please sign in to comment.