Skip to content

gh-161299: Resolve Gecko profiler resources to module names - #161310

Open
makwana-akshat wants to merge 2 commits into
python:mainfrom
makwana-akshat:gh-161299-gecko-resource-names
Open

makwana-akshat wants to merge 2 commits into
python:mainfrom
makwana-akshat:gh-161299-gecko-resource-names

Conversation

@makwana-akshat

@makwana-akshat makwana-akshat commented Nov 4, 2026 •

Copy link
Copy Markdown

Summary

  • Resolve Gecko profiler resource names to Python module names where available.
  • Distinguish resources from different packages that contain files with identical basenames.
  • Preserve readable fallback names for unresolved paths and synthetic filenames.
  • Add regression tests for module-name resolution and path handling.

Tests

  • Gecko collector tests: 17 passed using the local test runner.
  • module_utils tests: 4 passed using the local test runner.
  • git diff --check: passed.
  • The full CPython test suite has not been run locally because the required CPython build and extension modules are unavailable.

Issue

Related to #161299.

resource_name = (
os.path.basename(filename) if "/" in filename else filename
norm_filename = (
filename.replace("\\", "/") if "\\" in filename else filename

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not just using os.path.sep for the separator in filenames? You don't need to have the if either. And it's not really a norm_filename as normalized filenames are not that.

resource_idx = len(resource_names)
resource_name = (
os.path.basename(filename) if "/" in filename else filename
norm_filename = (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think a lot of this logic can be simplified using pathlib.Path.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for both suggestions!

I've simplified the fallback path handling using pathlib, replacing the manual string-splitting logic with Path.name and Path.parent.name. I've also removed the misleading norm_filename variable and the unnecessary conditional around separator replacement.

I retained PureWindowsPath to handle Windows-style paths correctly on POSIX systems. Backslashes are replaced with forward slashes before calling extract_module_name() to ensure module names are resolved consistently across platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants