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

Syspath #21895

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

Syspath #21895

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions external-deps/spyder-kernels/.gitrepo

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions external-deps/spyder-kernels/spyder_kernels/console/kernel.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions spyder/plugins/ipythonconsole/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def on_working_directory_available(self):
@on_plugin_available(plugin=Plugins.PythonpathManager)
def on_pythonpath_manager_available(self):
pythonpath_manager = self.get_plugin(Plugins.PythonpathManager)
pythonpath_manager.sig_pythonpath_changed.connect(self.update_path)
pythonpath_manager.sig_pythonpath_changed.connect(self.set_path)

@on_plugin_teardown(plugin=Plugins.Preferences)
def on_preferences_teardown(self):
Expand Down Expand Up @@ -464,7 +464,7 @@ def on_working_directory_teardown(self):
@on_plugin_teardown(plugin=Plugins.PythonpathManager)
def on_pythonpath_manager_teardown(self):
pythonpath_manager = self.get_plugin(Plugins.PythonpathManager)
pythonpath_manager.sig_pythonpath_changed.disconnect(self.update_path)
pythonpath_manager.sig_pythonpath_changed.disconnect(self.set_path)

def update_font(self):
"""Update font from Preferences"""
Expand Down Expand Up @@ -877,9 +877,9 @@ def save_working_directory(self, dirname):
"""
self.get_widget().save_working_directory(dirname)

def update_path(self, path_dict, new_path_dict):
def set_path(self, path_dict, new_path_dict):
"""
Update path on consoles.
Set path on consoles.

Both parameters have as keys paths and as value if the path
should be used/is active (True) or not (False)
Expand All @@ -895,7 +895,8 @@ def update_path(self, path_dict, new_path_dict):
-------
None.
"""
self.get_widget().update_path(path_dict, new_path_dict)
syspath = [path for path, active in new_path_dict.items() if active]
self.get_widget().set_syspath(syspath)

def restart(self):
"""
Expand Down
7 changes: 0 additions & 7 deletions spyder/plugins/ipythonconsole/utils/kernelspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,6 @@ def env(self):
# Do not pass PYTHONPATH to kernels directly, spyder-ide/spyder#13519
env_vars.pop('PYTHONPATH', None)

# List of paths declared by the user, plus project's path, to
# add to PYTHONPATH
pathlist = self.get_conf(
'spyder_pythonpath', default=[], section='pythonpath_manager')
pypath = os.pathsep.join(pathlist)

# List of modules to exclude from our UMR
umr_namelist = self.get_conf(
'umr/namelist', section='main_interpreter')
Expand All @@ -184,7 +178,6 @@ def env(self):
'SPY_JEDI_O': self.get_conf('jedi_completer'),
'SPY_TESTING': running_under_pytest() or get_safe_mode(),
'SPY_HIDE_CMD': self.get_conf('hide_cmd_windows'),
'SPY_PYTHONPATH': pypath,
})

# App considerations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def test_kernel_pypath(tmpdir, default_interpreter):
kernel_spec = SpyderKernelSpec()

# Check that PYTHONPATH is not in our kernelspec
# and pypath is in SPY_PYTHONPATH
assert 'PYTHONPATH' not in kernel_spec.env
assert pypath in kernel_spec.env['SPY_PYTHONPATH']

# Restore default values
CONF.set('main_interpreter', 'default', True)
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 @@ -2203,13 +2203,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):
def set_syspath(self, syspath):
"""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)
shell.set_syspath(syspath)

def get_active_project_path(self):
"""Get the active project path."""
Expand Down
13 changes: 9 additions & 4 deletions spyder/plugins/ipythonconsole/widgets/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@ def send_spyder_kernel_configuration(self):
# Set current cwd
self.set_cwd()

# Set pythonpath
self.set_syspath(self.get_conf(
'spyder_pythonpath', default=[], section='pythonpath_manager')
)

# To apply style
self.set_color_scheme(self.syntax_style, reset=False)

Expand Down Expand Up @@ -680,11 +685,11 @@ def set_color_scheme(self, color_scheme, reset=True):
"color scheme", "dark" if not dark_color else "light"
)

def update_syspath(self, path_dict, new_path_dict):
def set_syspath(self, syspath):
"""Update sys.path contents on kernel."""
self.call_kernel(
interrupt=True,
blocking=False).update_syspath(path_dict, new_path_dict)
self.set_kernel_configuration(
"syspath", syspath
)

def request_syspath(self):
"""Ask the kernel for sys.path contents."""
Expand Down