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 #482

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions spyder_kernels/console/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def __init__(self, *args, **kwargs):
# Socket to signal shell_stream locally
self.loopback_socket = None

# Save set syspath
self._syspath = []

@property
def kernel_info(self):
# Used for checking correct version by spyder
Expand Down Expand Up @@ -675,6 +678,8 @@ def set_configuration(self, conf):
self._load_wurlitzer()
elif key == "autoreload_magic":
self._autoreload_magic(value)
elif key == "syspath":
self.set_syspath(value)
return ret

def set_color_scheme(self, color_scheme):
Expand Down Expand Up @@ -764,8 +769,7 @@ def set_special_kernel(self, special):

raise NotImplementedError(f"{special}")

@comm_handler
def update_syspath(self, path_dict, new_path_dict):
def set_syspath(self, pypath):
"""
Update the PYTHONPATH of the kernel.

Expand All @@ -776,12 +780,12 @@ def update_syspath(self, path_dict, new_path_dict):
`new_path_dict` corresponds to the new state of the PYTHONPATH.
"""
# Remove old paths
for path in path_dict:
for path in self._syspath:
while path in sys.path:
sys.path.remove(path)
self._syspath = pypath

# Add new paths
pypath = [path for path, active in new_path_dict.items() if active]
if pypath:
sys.path.extend(pypath)
os.environ.update({'PYTHONPATH': os.pathsep.join(pypath)})
Expand Down
14 changes: 0 additions & 14 deletions spyder_kernels/customize/spydercustomize.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,3 @@ def _patched_get_terminal_size(fd=None):
# Pdb adjustments
# =============================================================================
pdb.Pdb = SpyderPdb

# =============================================================================
# PYTHONPATH and sys.path Adjustments
# =============================================================================
# PYTHONPATH is not passed to kernel directly, see spyder-ide/spyder#13519
# This allows the kernel to start without crashing if modules in PYTHONPATH
# shadow standard library modules.
def set_spyder_pythonpath():
pypath = os.environ.get('SPY_PYTHONPATH')
if pypath:
sys.path.extend(pypath.split(os.pathsep))
os.environ.update({'PYTHONPATH': pypath})

set_spyder_pythonpath()
Loading