MonkeyCanCode commented on code in PR #2192: URL: https://github.com/apache/polaris/pull/2192#discussion_r2261827685
########## client/python/generate_clients.py: ########## @@ -0,0 +1,267 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import sys +import os.path +import subprocess +from pathlib import Path +import fnmatch + +# Paths +CLIENT_DIR = Path(__file__).parent +PROJECT_ROOT = CLIENT_DIR.parent.parent +HEADER_DIR = CLIENT_DIR.parent / "templates" +SPEC_DIR = os.path.join(PROJECT_ROOT, "spec") +POLARIS_MANAGEMENT_SPEC = os.path.join(SPEC_DIR, "polaris-management-service.yml") +ICEBERG_CATALOG_SPEC = os.path.join(SPEC_DIR, "iceberg-rest-catalog-open-api.yaml") +POLARIS_CATALOG_SPEC = os.path.join(SPEC_DIR, "polaris-catalog-service.yaml") +OPEN_API_GENERATOR_IGNORE = os.path.join(CLIENT_DIR, ".openapi-generator-ignore") + +# Open API Generator Configs +PACKAGE_NAME_POLARIS_MANAGEMENT = ( + "--additional-properties=packageName=polaris.management" +) +PACKAGE_NAME_POLARIS_CATALOG = "--additional-properties=packageName=polaris.catalog" +PYTHON_VERSION = "--additional-properties=pythonVersion=3.9" + +# Cleanup +KEEP_TEST_FILES = [ + Path("test/test_cli_parsing.py"), +] +EXCLUDE_PATHS = [ + Path(".gitignore"), + Path(".openapi-generator/"), + Path(".openapi-generator-ignore"), + Path(".pytest_cache/"), + Path("test/test_cli_parsing.py"), + Path("cli/"), + Path("polaris/__pycache__/"), + Path("polaris/catalog/__pycache__/"), + Path("polaris/catalog/models/__pycache__/"), + Path("polaris/catalog/api/__pycache__/"), + Path("polaris/management/__pycache__/"), + Path("polaris/management/models/__pycache__/"), + Path("polaris/management/api/__pycache__/"), + Path("integration_tests/"), + Path(".github/workflows/python.yml"), + Path(".gitlab-ci.yml"), + Path("pyproject.toml"), + Path("requirements.txt"), + Path("test-requirements.txt"), + Path("setup.py"), + Path(".DS_Store"), + Path("Makefile"), + Path("poetry.lock"), + Path("docker-compose.yml"), + Path(".pre-commit-config.yaml"), + Path("README.md"), + Path("generate_clients.py"), + Path(".venv"), +] +EXCLUDE_EXTENSIONS = [ + "json", + "iml", + "keep", + "gitignore", +] + + +def clean_old_tests() -> None: + print("Deleting old tests...") + test_dir = CLIENT_DIR / "test" + if not test_dir.exists(): + print(f"Test directory {test_dir} does not exist, skipping test cleanup.") + return + + for item in test_dir.rglob("*"): + if item.is_file(): + # Check if the file should be kept relative to CLIENT_DIR + relative_path = item.relative_to(CLIENT_DIR) + if relative_path not in KEEP_TEST_FILES: + try: + os.remove(item) + print(f"{relative_path}: removed") + except OSError as e: + print(f"Error removing {relative_path}: {e}") + else: + print(f"{relative_path}: skipped") + + init_py_to_delete = CLIENT_DIR / "test" / "__init__.py" + if init_py_to_delete.exists(): + try: + os.remove(init_py_to_delete) + print(f"{init_py_to_delete.relative_to(CLIENT_DIR)}: removed") + except OSError as e: + print(f"Error removing {init_py_to_delete.relative_to(CLIENT_DIR)}: {e}") + print("Old test deletion complete.") + + +def generate_polaris_management_client() -> None: + subprocess.check_call( + [ + "openapi-generator-cli", + "generate", + "-i", + POLARIS_MANAGEMENT_SPEC, + "-g", + "python", + "-o", + CLIENT_DIR, + PACKAGE_NAME_POLARIS_MANAGEMENT, + "--additional-properties=apiNamePrefix=polaris", + PYTHON_VERSION, + "--additional-properties=generateSourceCodeOnly=true", + "--skip-validate-spec", + "--ignore-file-override", + OPEN_API_GENERATOR_IGNORE, + ], + stdout=subprocess.DEVNULL, + ) + + +def generate_polaris_catalog_client() -> None: + subprocess.check_call( + [ + "openapi-generator-cli", + "generate", + "-i", + POLARIS_CATALOG_SPEC, + "-g", + "python", + "-o", + CLIENT_DIR, + PACKAGE_NAME_POLARIS_CATALOG, + "--additional-properties=apiNameSuffix=", + PYTHON_VERSION, Review Comment: Resolved with `"--global-property apiDocs=false modelDocs=false"` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@polaris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org