Skip to content

Commit

Permalink
Receive list of strings instead of dictionary for paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclary committed Feb 12, 2024
1 parent 46d15c2 commit 80dcc2f
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions spyder_kernels/console/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,38 +764,33 @@ def set_special_kernel(self, special):
raise NotImplementedError(f"{special}")

@comm_handler
def update_syspath(self, path_dict, new_path_dict, prioritize):
def update_syspath(self, old_path, new_path, prioritize):
"""
Update the PYTHONPATH of the kernel.
`path_dict` and `new_path_dict` have the paths as keys and the state
as values. The state is `True` for active and `False` for inactive.
`path_dict` corresponds to the previous state of the PYTHONPATH.
`new_path_dict` corresponds to the new state of the PYTHONPATH.
`newe_prioritize` determines whether to prioritize PYTHONPATH in
sys.path.
`old_path` corresponds to the previous state of the PYTHONPATH.
`new_path` corresponds to the new state of the PYTHONPATH.
`prioritize` determines whether to prioritize PYTHONPATH in sys.path.
"""
# Remove old paths
for path in path_dict:
for path in old_path:
while path in sys.path:
sys.path.remove(path)

# Add new paths
pypath = [path for path, active in new_path_dict.items() if active]
if pypath:
os.environ.update({'PYTHONPATH': os.pathsep.join(pypath)})
if new_path:
os.environ.update({'PYTHONPATH': os.pathsep.join(new_path)})

if prioritize:
pypath.reverse()
[sys.path.insert(0, path) for path in pypath]
new_path.reverse()
[sys.path.insert(0, path) for path in new_path]

# Ensure current directory is always first
if '' in sys.path:
sys.path.remove('')
sys.path.insert(0, '')
else:
sys.path.extend(pypath)
sys.path.extend(new_path)
else:
os.environ.pop('PYTHONPATH', None)

Expand Down

0 comments on commit 80dcc2f

Please sign in to comment.