Skip to content

Commit

Permalink
Change sig_pythonpath_changed arguments from dictionary to list of st…
Browse files Browse the repository at this point in the history
…rings.
  • Loading branch information
mrclary committed Feb 12, 2024
1 parent 3443920 commit 3c2c64d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
10 changes: 5 additions & 5 deletions spyder/plugins/completion/providers/languageserver/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,17 +535,17 @@ def shutdown(self):
self.stop_completion_services_for_language(language)

@Slot(object, object, bool)
def python_path_update(self, path_dict, new_path_dict, prioritize):
def python_path_update(self, old_path, new_path, prioritize):
"""
Update server configuration after a change in Spyder's Python
path.
`path_dict` corresponds to the previous state of the Python path.
`new_path_dict` corresponds to the new state of the Python path.
`old_path` corresponds to the previous state of the Python path.
`new_path` corresponds to the new state of the Python path.
`prioritize` determines whether to prioritize Python path in sys.path.
"""
# Opening/closing a project will create a diff between path_dict
# and new_path_dict, but we don't know if prioritize changed.
# Opening/closing a project will create a diff between old_path
# and new_path, but we don't know if prioritize changed.
# sig_pythonpath_changed is only emitted if there is a change so we
# should always update the confguration when this method is called.
logger.debug("Update server's sys.path")
Expand Down
8 changes: 4 additions & 4 deletions spyder/plugins/ipythonconsole/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ def save_working_directory(self, dirname):
"""
self.get_widget().save_working_directory(dirname)

def update_path(self, path_dict, new_path_dict, prioritize):
def update_path(self, old_path, new_path, prioritize):
"""
Update path on consoles.
Expand All @@ -886,9 +886,9 @@ def update_path(self, path_dict, new_path_dict, prioritize):
Parameters
----------
path_dict : dict
old_path : list of str
Corresponds to the previous state of the PYTHONPATH.
new_path_dict : dict
new_path : list of str
Corresponds to the new state of the PYTHONPATH.
prioritize : bool
Whether to prioritize PYTHONPATH in sys.path
Expand All @@ -897,7 +897,7 @@ def update_path(self, path_dict, new_path_dict, prioritize):
-------
None.
"""
self.get_widget().update_path(path_dict, new_path_dict, prioritize)
self.get_widget().update_path(old_path, new_path, prioritize)

def restart(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/ipythonconsole/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2194,13 +2194,13 @@ def on_working_directory_changed(self, dirname):
if dirname and osp.isdir(dirname):
self.sig_current_directory_changed.emit(dirname)

def update_path(self, path_dict, new_path_dict, prioritize):
def update_path(self, old_path, new_path, prioritize):
"""Update path on consoles."""
logger.debug("Update sys.path in all console clients")
for client in self.clients:
shell = client.shellwidget
if shell is not None:
shell.update_syspath(path_dict, new_path_dict, prioritize)
shell.update_syspath(old_path, new_path, prioritize)

def get_active_project_path(self):
"""Get the active project path."""
Expand Down
20 changes: 9 additions & 11 deletions spyder/plugins/pythonpath/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,20 @@ def update_active_project_path(self, path):
path = (path,)

# Old path
old_path_dict_p = self._get_spyder_pythonpath_dict()
old_path = self.get_spyder_pythonpath()

# Change project path
self.project_path = path
self.path_manager_dialog.project_path = path

# New path
new_path_dict_p = self._get_spyder_pythonpath_dict()
new_path = self.get_spyder_pythonpath()

prioritize = self.get_conf('prioritize', default=False)

# Update path
self.set_conf('spyder_pythonpath', self.get_spyder_pythonpath())
self.sig_pythonpath_changed.emit(
old_path_dict_p, new_path_dict_p, prioritize
)
self.set_conf('spyder_pythonpath', new_path)
self.sig_pythonpath_changed.emit(old_path, new_path, prioritize)

def show_path_manager(self):
"""Show path manager dialog."""
Expand Down Expand Up @@ -248,26 +246,26 @@ def _update_python_path(self, new_path_dict=None, new_prioritize=None):
"""
Update Python path on language server and kernels.
The new_path_dict should not include the project path.
The `new_path_dict` should not include the project path.
"""
# Load existing path plus project path
old_path_dict_p = self._get_spyder_pythonpath_dict()
old_path = self.get_spyder_pythonpath()
old_prioritize = self.prioritize

# Save new path
if new_path_dict is not None or new_prioritize is not None:
self._save_paths(new_path_dict, new_prioritize)

# Load new path plus project path
new_path_dict_p = self._get_spyder_pythonpath_dict()
new_path = self.get_spyder_pythonpath()

# Do not notify observers unless necessary
if (
new_path_dict_p != old_path_dict_p
new_path != old_path
or new_prioritize != old_prioritize
):
self.sig_pythonpath_changed.emit(
old_path_dict_p, new_path_dict_p, new_prioritize
old_path, new_path, new_prioritize
)

def _migrate_to_config_options(self):
Expand Down

0 comments on commit 3c2c64d

Please sign in to comment.