Skip to content

chore(generator): use absolute paths in __lazy_modules__#17614

Merged
hebaalazzeh merged 3 commits into
mainfrom
pr-17573-pep810-update
Jul 2, 2026
Merged

chore(generator): use absolute paths in __lazy_modules__#17614
hebaalazzeh merged 3 commits into
mainfrom
pr-17573-pep810-update

Conversation

@hebaalazzeh

Copy link
Copy Markdown
Contributor

The GAPIC generator template now uses the {{package_path}} variable instead of evaluating name at runtime. The generator will now output the literal absolute strings (e.g., "google.cloud.compute_v1.services.accelerator_types") directly into the lazy_modules set, keeping the execution as lightweight as possible.

@hebaalazzeh hebaalazzeh force-pushed the pr-17573-pep810-update branch from 0fea5b8 to 46cf01b Compare July 1, 2026 22:17

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for PEP 0810 explicit lazy imports in generated packages, adds shared mTLS utility functions for the KMS service, and implements a Python SDK import profiling tool with documentation. Feedback on the changes highlights a redundant import of tracemalloc and a platform compatibility issue with the default CPU pinning value in profiler.py, as well as an unused import and several unused variables in rewrite_init.py.

Comment on lines +270 to +271
import tracemalloc
tracemalloc.start()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The tracemalloc module is already imported at the module level (line 6). Importing it again inside _mprofile_worker is redundant and violates the rule against importing modules inside functions when they are already imported at the module level.

Suggested change
import tracemalloc
tracemalloc.start()
tracemalloc.start()
References
  1. Do not import modules or classes inside functions if they are already imported at the module level.

{_format_stats("Physical RSS RAM (MB)", rss_memories, p50_rss, p90_rss, p99_rss, ".4f")}"""
print(final_output.strip())

def run_master(iterations, target_module, cpu=0, csv_path=None, clear_cache=True):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Hardcoding cpu=0 as the default value in run_master will cause failures on non-Linux platforms (like macOS or Windows) if the function is called programmatically without overriding cpu, because it will attempt to use taskset. Using NO_CPU_PINNING as the default value ensures platform-independent behavior by default.

Suggested change
def run_master(iterations, target_module, cpu=0, csv_path=None, clear_cache=True):
def run_master(iterations, target_module, cpu=NO_CPU_PINNING, csv_path=None, clear_cache=True):

Comment thread scripts/import_profiler/rewrite_init.py Outdated
@@ -0,0 +1,126 @@
import re
import os

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The os module is imported but never used in this script. It should be removed to keep the imports clean.

Comment thread scripts/import_profiler/rewrite_init.py Outdated
Comment on lines +19 to +21
import_pattern = re.compile(r'^from\s+(\.[a-zA-Z0-9_.]+)\s+import\s+(.*?)$', re.MULTILINE | re.DOTALL)

imports = []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The variables import_pattern and imports are defined but never used anywhere in the script. Removing them keeps the code clean and maintainable.

Comment thread scripts/import_profiler/rewrite_init.py Outdated
Comment on lines +29 to +32
new_lines = []

in_import = False
import_module = ""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The variables new_lines, in_import, and import_module are defined but never used in the script. Removing them improves code readability and maintainability.

@hebaalazzeh hebaalazzeh force-pushed the pr-17573-pep810-update branch from 46cf01b to 7b7a8a1 Compare July 1, 2026 22:23
@hebaalazzeh hebaalazzeh marked this pull request as ready for review July 1, 2026 23:08
@hebaalazzeh hebaalazzeh requested a review from a team as a code owner July 1, 2026 23:08
# For more information, see:
# https://docs.python.org/3.15/library/sys.html#sys.set_lazy_imports_filter
# Older Python versions safely ignore this variable.
# We use absolute paths (via package_path) rather than __name__ to avoid runtime evaluation overhead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove this comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

@ohmayr ohmayr changed the title Chore: Pr 17573 pep810 update chore(generator): use absolute paths in _lazy_modules Jul 1, 2026
@ohmayr ohmayr changed the title chore(generator): use absolute paths in _lazy_modules chore(generator): use absolute paths in __lazy_modules__ Jul 1, 2026
@hebaalazzeh hebaalazzeh force-pushed the pr-17573-pep810-update branch from d217d25 to 13c40f3 Compare July 2, 2026 00:16
"google.cloud.asset_v1.types.asset_enrichment_resourceowners",
"google.cloud.asset_v1.types.asset_service",
"google.cloud.asset_v1.types.assets",
}

@daniel-sanche daniel-sanche Jul 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit, but it seems like these strings should probably be indented

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

@hebaalazzeh hebaalazzeh force-pushed the pr-17573-pep810-update branch from 9bde644 to 1888d4b Compare July 2, 2026 01:04
@hebaalazzeh hebaalazzeh enabled auto-merge (squash) July 2, 2026 01:09
@hebaalazzeh hebaalazzeh merged commit bbcf902 into main Jul 2, 2026
95 of 96 checks passed
@hebaalazzeh hebaalazzeh deleted the pr-17573-pep810-update branch July 2, 2026 01:09
@parthea parthea mentioned this pull request Jul 6, 2026
parthea added a commit that referenced this pull request Jul 6, 2026
Update the goldens following
#17614. This PR is
needed to unblock release PR
#17600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants