-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
PR: Add option to prepend or append Pythonpath Manager paths to sys.path #21769
base: master
Are you sure you want to change the base?
Conversation
Hello @mrclary! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2025-01-21 04:06:10 UTC |
3999697
to
3c2c64d
Compare
b11ccad
to
a433e97
Compare
5f68078
to
ffd9395
Compare
0a04027
to
73e407e
Compare
…pdate_paths method and call setup in update-paths method. This will allow the container to instantiate the PathManager widget before providing paths. Paths will not be retrieved or determined within the widget, only passed to it by the container.
These will be dictionaries and the container will handle updating the pythonpath_manager configuration and assembling the final spyder_pythonpath. There is no need for _update_system_path method because the container will handle updates to the underlying system path. Again, the widget will only handle user-interactive changes.
This will be done in the container instead.
…oritize) -> (_user_paths, _system_paths, _project_paths, _prioritize, _spyder_pythonpath). Path lists are now OrderedDict * Simplifies _load_pythonpath -> _load_paths * Move migration method from setup to _load_paths
* Promptly exits if remnants of old configuration are not present * Removes remnants of old configuration if present * Constructs user paths from old configuration remnants
* Configuration keys and private attributes for user paths, system paths, prioritize, and spyder_pythonpath are set conditionally in this method and nowhere else. * sig_pythonpath_changed is conditionally emitted from this method and nowhere else. This signal now sends only the spyder_pythonpath and prioritize, not the old spyder_pythonpath. Subscribers should update accordingly.
…ardly constructed from project, user, and system paths attributes.
…d in _save_paths if spyder_pythonpath is changed.
…d in PathManager.updat_paths
… Note that spyder-kernels must be updated to accommodate.
Icon and tooltip are changed to reflect current state.
Co-authored-by: Jitse Niesen <[email protected]> Typographical errors. Improved docstring clarity
The desired affect is project paths | user paths | system paths, where the paths are in that order and are overwritten in that order. System paths cannot overwrite user paths, which cannot overwrite project paths, i.e we cannot just do project_paths.update(user_paths) etc.
…path manager widget is invoked. If the system paths have changed since last widget invocation, then the user may not be aware and there is no indication in the widget that there has been a change. Furthermore, canceling the widget may still result in a change to the pythonpath, which would be inconsistent with the cancel action.
Rather than automatically updating the system paths, provide mechanism for user to do so.
* Test system PYTHONPATH import in test_pathmanager instead of test_mainwindow * Move restore_user_env fixture from app/tests/conftest.py to utils/tests/conftest.py * Ensure that the user environment script runs on posix while testing
…lary/spyder-kernels.git external-deps/spyder-kernels subrepo: subdir: "external-deps/spyder-kernels" merged: "66766d44b" upstream: origin: "https://github.com/mrclary/spyder-kernels.git" branch: "ppm-syspath" commit: "66766d44b" git-subrepo: version: "0.4.9" origin: "???" commit: "???"
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.
Thanks @mrclary, thanks for your work on this! This is an initial review for you.
def on_close(self): | ||
# Save current system path to detect changes next time Spyder starts | ||
self.set_conf('system_path', get_system_pythonpath()) |
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.
Why did you remove this?
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.
This on_close
would save the current system paths to the configuration on closing the plugin without user acknowledgement. With this PR, the configuration is saved and signal emitted only from PythonpathContainer._save_paths
, after user interaction, to ensure that any changes are initiated and approved by the user. In this case, there is nothing that needs to be done when closing the container, so the function no longer is needed.
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.
Please don't resolve this until I have a chance to test your PR manually.
qtbot.waitUntil(pathmanager.prioritize_button.isChecked) | ||
assert pathmanager.prioritize_button.isChecked() | ||
assert pathmanager.button_ok.isEnabled() | ||
|
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 think a test for the new prioritize button is missing. Could you add one?
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.
So the state of the OK button is tested with respect to changes to the prioritize button in test_buttons_state
. The Pythonpath Manager doesn't actually do anything with the prioritize state except to pass its value via signal, i.e. it doesn't do any path sorting, so I'm not sure what should be tested here. spyder-kernels
will actually do the sorting, and this is tested in test_console_kernel.py
, added in the companion PR. Is there something in particular you had in mind to test?
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.
Ok, but we need to check that the Spyder UI actually changes the priority of paths in the console at least (it's harder to check in the LSP).
For that then I suggest to extend test_PYTHONPATH_in_consoles
, by clicking the prioritize button in the PPM dialog and then check in the console that the paths handled by it are at the front of sys.path
.
Co-authored-by: Carlos Cordoba <[email protected]>
Co-authored-by: Carlos Cordoba <[email protected]>
@ccordoba12, thank you for reviewing this PR. I implemented most of your recommendations and have rebased onto the latest master locally, but haven't pushed them up just yet. I had a few follow-up comments which I can resolve after you get a chance to respond. After these are resolved, I'll push up all the changes for another round of review. |
Description of Changes
UI/UX Changes
sys.path
in IPython console and Jedi completion environments.Primary Changes
These changes directly affect the plugin API.
user_paths
,system_paths
, andprioritize
.user_paths
andsystem_paths
are dictionaries with path as key and enabled state as value.prioritize
is a boolean. The unofficial configuration keyspath
,user_path
, andsystem_path
are no longer used. Thespyder_pythonpath
configuration key remains unchanged.SPY_PYTHONPATH
environment variable is eliminated in favor of directly accessing thespyder_pythonpath
configuration key in thepythonpath_manager
configuration section on startup of IPython console kernels.sig_pythonpath_changed
now sends the newspyder_pythonpath
value (list of strings) andprioritize
(boolean). This signal no longer sends the "old" paths. The old paths were only required byspyder-kernels
in order to remove those paths fromsys.path
before adding the new paths tosys.path
. The update tospyder-kernels
in the companion PR eliminates the need for sending the "old" paths.UnboundLocalError
.Secondary Changes
In order to simplify the handling of PYTHONPATH, the following changes were made to the Pythonpath Manager plugin. These do not directly affect the UI, UX, or plugin API, but streamline and clarify the actions performed within the plugin.
PythonpathContainer
container object and thePathManager
widget object were changed frompath
,not_active_path
,user_path
,system_path
, andoriginal_path_dict
, to the less ambiguoususer_paths
andsystem_paths
. The latter are maintained asOrderedDict
objects throughout.pythonpath_manager
configurations are now only set inPythonpathContainer._save_paths
, and only on condition of change, rather than in multiple locations throughout the container andPathManager
widget.sig_pythonpath_changed
signal is emitted only inPythonpathContainer._save_paths
, and only on condition thatspyder_pythonpath
orprioritize
has changed.Companion PRs
extra_paths
to be placed in front ofsys.path
python-lsp/python-lsp-server#527.Outstanding questions
python-lsp-server.pylsp.Document.sys_path
be removed (API break)?Issue(s) Resolved
Fixes #17066
Affirmation
By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.
I certify the above statement is true and correct:
@mrclary