From be03cb752389ec43f622ac9f1fb25618693b197e Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Thu, 20 Mar 2025 18:17:52 -0400 Subject: [PATCH] chore: Don't hide stderr from api generator (#1720) # What does this PR do? If the generator fails, pre-commit logs will now show how it failed. Note: stdout is still suppressed, so that regular informational messages do not pollute pre-commit output when all the hook does is update generated files. [//]: # (If resolving an issue, uncomment and update the line below) [//]: # (Closes #[issue-number]) ## Test Plan Inject a failure in the generator code and confirm it's seen in the output. ``` $ git diff diff --git a/docs/openapi_generator/pyopenapi/utility.py b/docs/openapi_generator/pyopenapi/utility.py index f60a33bb..482e26ef 100644 --- a/docs/openapi_generator/pyopenapi/utility.py +++ b/docs/openapi_generator/pyopenapi/utility.py @@ -127,6 +127,7 @@ def is_optional_type(type_: Any) -> bool: def validate_api_method_return_types() -> List[str]: """Validate that all API methods have proper return types.""" + raise NotImplementedError("This function is not implemented yet") errors = [] protocols = api_protocol_map() ``` ``` $ pre-commit run --all-files check for merge conflicts................................................Passed trim trailing whitespace.................................................Passed check for added large files..............................................Passed fix end of files.........................................................Passed Insert license in comments...............................................Passed ruff.....................................................................Passed ruff-format..............................................................Passed blacken-docs.............................................................Passed uv-lock..................................................................Passed uv-export................................................................Passed mypy.....................................................................Passed Distribution Template Codegen............................................Passed API Spec Codegen.........................................................Failed - hook id: openapi-codegen - exit code: 1 warning: `VIRTUAL_ENV=/Users/ihrachys/.cache/pre-commit/repo9p35zuhm/py_env-python3` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/Users/ihrachys/src/llama-stack/docs/openapi_generator/generate.py", line 91, in fire.Fire(main) File "/Users/ihrachys/.cache/uv/archive-v0/FBgkcwcN-PaJ0NAur__7J/lib/python3.11/site-packages/fire/core.py", line 135, in Fire component_trace = _Fire(component, args, parsed_flag_args, context, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ihrachys/.cache/uv/archive-v0/FBgkcwcN-PaJ0NAur__7J/lib/python3.11/site-packages/fire/core.py", line 468, in _Fire component, remaining_args = _CallAndUpdateTrace( ^^^^^^^^^^^^^^^^^^^^ File "/Users/ihrachys/.cache/uv/archive-v0/FBgkcwcN-PaJ0NAur__7J/lib/python3.11/site-packages/fire/core.py", line 684, in _CallAndUpdateTrace component = fn(*varargs, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ihrachys/src/llama-stack/docs/openapi_generator/generate.py", line 44, in main return_type_errors = validate_api_method_return_types() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ihrachys/src/llama-stack/docs/openapi_generator/pyopenapi/utility.py", line 130, in validate_api_method_return_types raise NotImplementedError("This function is not implemented yet") NotImplementedError: This function is not implemented yet ``` Signed-off-by: Ihar Hrachyshka --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e83e64672..7490b1d8d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -89,7 +89,7 @@ repos: name: API Spec Codegen additional_dependencies: - uv==0.6.2 - entry: sh -c 'uv run --with ".[dev]" ./docs/openapi_generator/run_openapi_generator.sh > /dev/null 2>&1' + entry: sh -c 'uv run --with ".[dev]" ./docs/openapi_generator/run_openapi_generator.sh > /dev/null' language: python pass_filenames: false require_serial: true