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

PR: Add option to prepend or append Pythonpath Manager paths to sys.path #21769

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

mrclary
Copy link
Contributor

@mrclary mrclary commented Feb 6, 2024

Description of Changes

  • Wrote at least one-line docstrings (for any new functions)
  • Added unit test(s) covering the changes (if testable)
  • Included a screenshot or animation (if affecting the UI, see Licecap)

Primary Changes

Added toggle button to Pythonpath Manager dialog that determines whether active paths should be prepended to or appended to sys.path in IPython console and Jedi completion environments.
Screenshot 2024-03-04 at 11 11 45 AM

  • Spyder's transient configuration now includes user_paths, system_paths, and prioritize. user_paths and system_paths are dictionaries with path as key and enabled state as value. prioritize is a boolean. The unofficial configuration keys path, user_path, and system_path are no longer used. The spyder_pythonpath configuration key remains unchanged.
  • SPY_PYTHONPATH environment variable is eliminated in favor of directly accessing the spyder_pythonpath configuration key in the pythonpath_manager configuration section on startup of IPython console kernels.
  • sig_pythonpath_changed now sends the new spyder_pythonpath value (list of strings) and prioritize (boolean). This signal no longer sends the "old" paths. The old paths were only required by spyder-kernels in order to remove those paths from sys.path before adding the new paths to sys.path. The update to spyder-kernels in the companion PR eliminates the need for sending the "old" paths.
  • Fixed an issue where changes made by the user in the UI were applied even when the user presses the cancel button, if the system paths had changed on disk.

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.

  • The internal attributes of the PythonpathContainer container object and the PathManager widget object were changed from path, not_active_path, user_path, system_path, and original_path_dict, to the less ambiguous user_paths and system_paths. The latter are maintained as OrderedDict objects throughout.
  • The pythonpath_manager configurations are now only set in PythonpathContainer._save_paths, and only on condition of change, rather than in multiple locations throughout the container and PathManager widget.
  • The sig_pythonpath_changed signal is emitted only in PythonpathContainer._save_paths, and only on condition that spyder_pythonpath or prioritize has changed.

Companion PRs

Outstanding questions

  • Should python-lsp-server.pylsp.Document.sys_path be removed (API break)?
  • Why does new_dlg.kfp.text() == pytest.kfp and new_dlg.pw.text() == pytest.pw fail on latest master? Why are they skipped for CI?
  • What icon should be used for the prioritze button?

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

@pep8speaks
Copy link

pep8speaks commented Feb 6, 2024

Hello @mrclary! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 537:80: E501 line too long (85 > 79 characters)
Line 574:80: E501 line too long (84 > 79 characters)

Line 362:80: E501 line too long (83 > 79 characters)
Line 363:80: E501 line too long (84 > 79 characters)
Line 366:80: E501 line too long (87 > 79 characters)
Line 367:80: E501 line too long (93 > 79 characters)
Line 476:80: E501 line too long (83 > 79 characters)
Line 479:80: E501 line too long (82 > 79 characters)

Line 293:80: E501 line too long (101 > 79 characters)
Line 294:80: E501 line too long (102 > 79 characters)

Comment last updated at 2024-05-16 20:44:59 UTC

@mrclary mrclary force-pushed the ppm-syspath branch 2 times, most recently from 3999697 to 3c2c64d Compare February 12, 2024 23:25
@mrclary mrclary force-pushed the ppm-syspath branch 2 times, most recently from b11ccad to a433e97 Compare February 22, 2024 21:31
@mrclary mrclary force-pushed the ppm-syspath branch 13 times, most recently from 5f68078 to ffd9395 Compare March 4, 2024 21:27
@mrclary mrclary marked this pull request as ready for review March 4, 2024 22:11
@mrclary mrclary marked this pull request as draft March 4, 2024 22:11
@mrclary mrclary marked this pull request as ready for review March 4, 2024 22:14
@mrclary mrclary force-pushed the ppm-syspath branch 3 times, most recently from 0a04027 to 73e407e Compare March 13, 2024 00:54
mrclary added 22 commits May 16, 2024 11:55
test_ipythoncosonle.py had many failures on latest master; attempting CI=1 skipped many tests but hangs on test_pdb_ignore_lib[True]
…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.
… Note that spyder-kernels must be updated to accommodate.
@mrclary mrclary force-pushed the ppm-syspath branch 2 times, most recently from d50d5d7 to e7e480a Compare May 16, 2024 19:30
Icon and tooltip are changed to reflect current state.
Co-authored-by: Jitse Niesen <jitseniesen@yahoo.com>

Typographical errors.
Improved docstring clarity
…lary/spyder-kernels.git --update external-deps/spyder-kernels

subrepo:
  subdir:   "external-deps/spyder-kernels"
  merged:   "c33971502"
upstream:
  origin:   "https://github.com/mrclary/spyder-kernels.git"
  branch:   "issue-22304"
  commit:   "c33971502"
git-subrepo:
  version:  "0.4.6"
  origin:   "???"
  commit:   "???"
…lary/python-lsp-server.git --update --force external-deps/python-lsp-server

subrepo:
  subdir:   "external-deps/python-lsp-server"
  merged:   "e32005ed3"
upstream:
  origin:   "https://github.com/mrclary/python-lsp-server.git"
  branch:   "ppm-syspath"
  commit:   "e32005ed3"
git-subrepo:
  version:  "0.4.6"
  origin:   "???"
  commit:   "???"
@mrclary
Copy link
Contributor Author

mrclary commented May 16, 2024

I also have one general comment: is it necessary to use an OrderedDict? The normal dict is ordered since Python 3.7 and we require at least Python 3.8 at the moment.

No, it is not necessary to use an OrderedDict. I simply retained its use since that was what we were already using. We can change this in the future, if desired.

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

Successfully merging this pull request may close these issues.

Suggestion: insert paths from PYTHONPATH manager before system's PYTHONPATH
4 participants