-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement copying python import path from opened file #25026
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
base: main
Are you sure you want to change the base?
Implement copying python import path from opened file #25026
Conversation
@microsoft-github-policy-service agree |
} | ||
|
||
/** | ||
* Resolves a Python import-style dotted path from an absolute file path. |
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.
As described here, the strategy for resolving the Python import path is as follows:
- If the file is located under any entry in
sys.path
, the path relative to that entry is used. - If the file is located under the current workspace folder, the path relative to the workspace root is used.
- Otherwise, the import path falls back to the file name (without extension).
I believe this approach is reasonable, but if you have any suggestions for improvement, I’d love to hear them!
@@ -1126,6 +1131,11 @@ | |||
} | |||
], | |||
"keybindings": [ | |||
{ | |||
"command": "python.copyImportPath", | |||
"key": "ctrl+alt+shift+i", |
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.
I've set Ctrl+Alt+Shift+I
as the default keybinding.
If you find it inconvenient or have a better suggestion, please let me know!
Hi, just a quick note regarding the CI failure: It appears that the error is not related to the changes in this PR. Please let me know if anything needs to be changed on my end. Thanks! |
Summary
This PR implements a new feature that allows users to copy the Python import path of the currently opened file to the clipboard via the file tab context menu.
What was done
python.copyImportPath
command.Example
For a file at /home/user/project/src/pkg/module.py and sys.path containing /home/user/project/src, the copied import path will be: