|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | +# |
| 20 | + |
| 21 | +set -e |
| 22 | + |
| 23 | +############################# |
| 24 | +# Regenerate Python clients # |
| 25 | +############################# |
| 26 | + |
| 27 | +echo "Regenerating python from the spec" |
| 28 | + |
| 29 | +# TODO skip-validate-spec is needed because the upstream Iceberg spec seems invalid. e.g.: |
| 30 | +# [main] ERROR o.o.codegen.DefaultCodegen - Required var sort-order-id not in properties |
| 31 | + |
| 32 | +docker run --rm \ |
| 33 | + -v "$(dirname "$0")/../..:/local" \ |
| 34 | + openapitools/openapi-generator-cli generate \ |
| 35 | + -i /local/spec/polaris-management-service.yml \ |
| 36 | + -g python \ |
| 37 | + -o /local/client/python \ |
| 38 | + --additional-properties=packageName=polaris.management \ |
| 39 | + --additional-properties=apiNamePrefix=polaris > /dev/null |
| 40 | + |
| 41 | +docker run --rm \ |
| 42 | + -v "$(dirname "$0")/../..:/local" \ |
| 43 | + openapitools/openapi-generator-cli generate \ |
| 44 | + -i /local/spec/polaris-catalog-service.yaml \ |
| 45 | + -g python \ |
| 46 | + -o /local/client/python \ |
| 47 | + --additional-properties=packageName=polaris.catalog \ |
| 48 | + --additional-properties=apiNameSuffix="" \ |
| 49 | + --skip-validate-spec > /dev/null |
| 50 | + |
| 51 | +docker run --rm \ |
| 52 | + -v "$(dirname "$0")/../..:/local" \ |
| 53 | + openapitools/openapi-generator-cli generate \ |
| 54 | + -i /local/spec/iceberg-rest-catalog-open-api.yaml \ |
| 55 | + -g python \ |
| 56 | + -o /local/client/python \ |
| 57 | + --additional-properties=packageName=polaris.catalog \ |
| 58 | + --additional-properties=apiNameSuffix="" \ |
| 59 | + --additional-properties=apiNamePrefix=Iceberg \ |
| 60 | + --skip-validate-spec > /dev/null |
| 61 | + |
| 62 | +############################# |
| 63 | +# Prepend Licenses # |
| 64 | +############################# |
| 65 | + |
| 66 | +echo "Re-applying license headers" |
| 67 | + |
| 68 | +prepend_header() { |
| 69 | + local file="$1" |
| 70 | + local header_file="$2" |
| 71 | + tmpfile=$(mktemp) |
| 72 | + cat "$header_file" "$file" > "$tmpfile" |
| 73 | + mv "$tmpfile" "$file" |
| 74 | +} |
| 75 | + |
| 76 | + |
| 77 | +pushd "$(dirname "$0")/.." > /dev/null |
| 78 | +TARGET_DIR="$(dirname "$0")/../python" |
| 79 | + |
| 80 | +# List of paths to exclude (.../client) |
| 81 | +EXCLUDE_PATHS=( |
| 82 | + "python/.gitignore" |
| 83 | + "python/.openapi-generator/" |
| 84 | + "python/.openapi-generator-ignore" |
| 85 | + "python/pyproject.toml" |
| 86 | +) |
| 87 | + |
| 88 | +EXCLUDE_EXTENSIONS=( |
| 89 | + "json" |
| 90 | +) |
| 91 | + |
| 92 | +# Process all files in the target directory |
| 93 | +git ls-files "${TARGET_DIR}" | while read -r file; do |
| 94 | + if [ -f "$file" ]; then |
| 95 | + # Extract the extension |
| 96 | + ext="${file##*.}" |
| 97 | + |
| 98 | + # Check if we need to exclude this extension |
| 99 | + extension_excluded=false |
| 100 | + for exclude_ext in "${EXCLUDE_EXTENSIONS[@]}"; do |
| 101 | + if [ "$ext" = "$exclude_ext" ]; then |
| 102 | + extension_excluded=true |
| 103 | + fi |
| 104 | + done |
| 105 | + |
| 106 | + # Skip this file if its extension is excluded |
| 107 | + if [ "$extension_excluded" = true ]; then |
| 108 | + echo "${file}: skipped" |
| 109 | + continue |
| 110 | + else |
| 111 | + # Construct the header file path |
| 112 | + header_file="$(dirname "$0")/header-${ext}.txt" |
| 113 | + |
| 114 | + # Only process if the license file exists |
| 115 | + if [ -f "$header_file" ]; then |
| 116 | + echo "${file}: updated" |
| 117 | + prepend_header "$file" "$header_file" |
| 118 | + else |
| 119 | + # Check if file should be excluded |
| 120 | + exclude=false |
| 121 | + for exclude_path in "${EXCLUDE_PATHS[@]}"; do |
| 122 | + if [[ "$file" == "$exclude_path"* ]]; then |
| 123 | + exclude=true |
| 124 | + fi |
| 125 | + done |
| 126 | + |
| 127 | + if [ "$exclude" = false ]; then |
| 128 | + echo "No header compatible with file ${file}" |
| 129 | + exit 2 |
| 130 | + fi |
| 131 | + fi |
| 132 | + fi |
| 133 | + fi |
| 134 | +done |
| 135 | + |
| 136 | +echo "Regeneration complete" |
| 137 | + |
| 138 | +popd > /dev/null |
| 139 | + |
0 commit comments