Skip to content
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

Support module and package names in the codemod context #662

Merged
merged 4 commits into from
Mar 23, 2022

Conversation

lpetre
Copy link
Contributor

@lpetre lpetre commented Mar 23, 2022

Summary

Relative imports are relative to the module's package, not the module's name.

Therefore we need to compute the package from the file.

Test Plan

~/EllipticalFrightenedOpposites$ tree -I __pycache__ x/
x/
├── __init__.py
└── y
    ├── __init__.py
    └── z.py

1 directory, 3 files

~/EllipticalFrightenedOpposites$ python3 -c 'import x.y.z as mod; print(mod.__package__, mod.__name__)'
x.y x.y.z

~/EllipticalFrightenedOpposites$ python3 -c 'import x.y as mod; print(mod.__package__, mod.__name__)'
x.y x.y

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 23, 2022
Copy link
Member

@zsol zsol left a comment

Choose a reason for hiding this comment

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

Nice.

libcst/codemod/_cli.py Outdated Show resolved Hide resolved
@lpetre lpetre force-pushed the add_full_package_name branch 4 times, most recently from acf5cb5 to 25a6202 Compare March 23, 2022 14:57
@lpetre lpetre force-pushed the add_full_package_name branch from 25a6202 to dc42ecd Compare March 23, 2022 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants