-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Updated diff with ruff #14952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Updated diff with ruff #14952
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bae8fc5
chore: track generation time for discoveryengine
ohmayr 5625894
test
ohmayr 9b0b0cc
update state to use latest image temporarily
ohmayr d9b9921
test
ohmayr 343f80f
test
ohmayr 2796b53
test
ohmayr 1df8a01
test
ohmayr 5cf1c6c
diff with ruff
ohmayr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| import subprocess | ||
| import sys | ||
| import tempfile | ||
| import time | ||
| import yaml | ||
| from datetime import date, datetime | ||
| from functools import lru_cache | ||
|
|
@@ -31,6 +32,40 @@ | |
| import build.util | ||
| import parse_googleapis_content | ||
|
|
||
| logging.basicConfig(stream=sys.stdout, level=logging.INFO) | ||
|
|
||
| import functools | ||
|
|
||
| PERF_LOGGING_ENABLED = os.environ.get("ENABLE_PERF_LOGS") == "1" | ||
|
|
||
| if PERF_LOGGING_ENABLED: | ||
| perf_logger = logging.getLogger("performance_metrics") | ||
| perf_logger.setLevel(logging.INFO) | ||
| perf_handler = logging.FileHandler("performance_metrics.log", mode='w') | ||
| perf_formatter = logging.Formatter('%(asctime)s | %(message)s', datefmt='%H:%M:%S') | ||
| perf_handler.setFormatter(perf_formatter) | ||
| perf_logger.addHandler(perf_handler) | ||
| perf_logger.propagate = False | ||
|
|
||
| def track_time(func): | ||
| """ | ||
| Decorator. Usage: @track_time | ||
| If logging is OFF, it returns the original function (Zero Overhead). | ||
| If logging is ON, it wraps the function to measure execution time. | ||
| """ | ||
| if not PERF_LOGGING_ENABLED: | ||
| return func | ||
|
|
||
| @functools.wraps(func) | ||
| def wrapper(*args, **kwargs): | ||
| start_time = time.perf_counter() | ||
| try: | ||
| return func(*args, **kwargs) | ||
| finally: | ||
| duration = time.perf_counter() - start_time | ||
| perf_logger.info(f"{func.__name__:<30} | {duration:.4f} seconds") | ||
|
|
||
| return wrapper | ||
|
|
||
|
Comment on lines
+68
to
69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| try: | ||
| import synthtool | ||
|
|
@@ -320,6 +355,7 @@ def _get_library_id(request_data: Dict) -> str: | |
| return library_id | ||
|
|
||
|
|
||
| @track_time | ||
| def _run_post_processor(output: str, library_id: str, is_mono_repo: bool): | ||
| """Runs the synthtool post-processor on the output directory. | ||
|
|
||
|
|
@@ -389,6 +425,7 @@ def _add_header_to_files(directory: str) -> None: | |
| f.writelines(lines) | ||
|
|
||
|
|
||
| @track_time | ||
| def _copy_files_needed_for_post_processing( | ||
| output: str, input: str, library_id: str, is_mono_repo: bool | ||
| ): | ||
|
|
@@ -435,6 +472,7 @@ def _copy_files_needed_for_post_processing( | |
| ) | ||
|
|
||
|
|
||
| @track_time | ||
| def _clean_up_files_after_post_processing( | ||
| output: str, library_id: str, is_mono_repo: bool | ||
| ): | ||
|
|
@@ -581,6 +619,7 @@ def _get_repo_name_from_repo_metadata(base: str, library_id: str, is_mono_repo: | |
| return repo_name | ||
|
|
||
|
|
||
| @track_time | ||
| def _generate_repo_metadata_file( | ||
| output: str, library_id: str, source: str, apis: List[Dict], is_mono_repo: bool | ||
| ): | ||
|
|
@@ -622,6 +661,7 @@ def _generate_repo_metadata_file( | |
| _write_json_file(output_repo_metadata, metadata_content) | ||
|
|
||
|
|
||
| @track_time | ||
| def _copy_readme_to_docs(output: str, library_id: str, is_mono_repo: bool): | ||
| """Copies the README.rst file for a generated library to docs/README.rst. | ||
|
|
||
|
|
@@ -663,6 +703,7 @@ def _copy_readme_to_docs(output: str, library_id: str, is_mono_repo: bool): | |
| f.write(content) | ||
|
|
||
|
|
||
| @track_time | ||
| def handle_generate( | ||
| librarian: str = LIBRARIAN_DIR, | ||
| source: str = SOURCE_DIR, | ||
|
|
@@ -711,6 +752,7 @@ def handle_generate( | |
| _run_post_processor(output, library_id, is_mono_repo) | ||
| _copy_readme_to_docs(output, library_id, is_mono_repo) | ||
| _clean_up_files_after_post_processing(output, library_id, is_mono_repo) | ||
|
|
||
| except Exception as e: | ||
| raise ValueError("Generation failed.") from e | ||
| logger.info("'generate' command executed.") | ||
|
|
@@ -924,6 +966,7 @@ def _stage_gapic_library(tmp_dir: str, staging_dir: str) -> None: | |
| shutil.copytree(tmp_dir, staging_dir, dirs_exist_ok=True) | ||
|
|
||
|
|
||
| @track_time | ||
| def _generate_api( | ||
| api_path: str, | ||
| library_id: str, | ||
|
|
@@ -1744,6 +1787,7 @@ def handle_release_stage( | |
| output=args.output, | ||
| input=args.input, | ||
| ) | ||
|
|
||
| elif args.command == "build": | ||
| args.func(librarian=args.librarian, repo=args.repo) | ||
| elif args.command == "release-stage": | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "id": "google-cloud-discoveryengine", | ||
| "version": "0.4.0", | ||
| "apis": [ | ||
| { | ||
| "path": "google/cloud/discoveryengine/v1", | ||
| "service_config": "discoveryengine_v1.yaml" | ||
| }, | ||
| { | ||
| "path": "google/cloud/discoveryengine/v1beta", | ||
| "service_config": "discoveryengine_v1beta.yaml" | ||
| }, | ||
| { | ||
| "path": "google/cloud/discoveryengine/v1alpha", | ||
| "service_config": "discoveryengine_v1alpha.yaml" | ||
| } | ||
| ], | ||
| "source_roots": [ | ||
| "packages/google-cloud-discoveryengine" | ||
| ], | ||
| "preserve_regex": [ | ||
| "packages/google-cloud-discoveryengine/CHANGELOG.md", | ||
| "docs/CHANGELOG.md", | ||
| "samples/README.txt", | ||
| "samples/snippets/README.rst", | ||
| "tests/system" | ||
| ], | ||
| "remove_regex": [ | ||
| "packages/google-cloud-discoveryengine/" | ||
| ], | ||
| "tag_format": "{id}-v{version}" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to PEP 8, imports should be grouped at the top of the file. Please move
import functoolsto the top section with other standard library imports (e.g., afterimport time).