Skip to content

Commit

Permalink
Clean up current working directory manipulations
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclary committed Mar 2, 2024
1 parent 250da79 commit a76e1d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
5 changes: 0 additions & 5 deletions spyder_kernels/console/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ def __init__(self, *args, **kwargs):
# Socket to signal shell_stream locally
self.loopback_socket = None

# Re-add current working directory path into sys.path after
# removing it before kernel started
if '' not in sys.path:
sys.path.insert(0, '')

# Store original sys.path. Kernels are started with PYTHONPATH
# removed from environment variables, so this will never have
# user paths and should be clean.
Expand Down
30 changes: 15 additions & 15 deletions spyder_kernels/console/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
import sys
import site

# Remove current directory from sys.path to prevent kernel
# crashes when people name Python files or modules with
# the same name as standard library modules.
# See spyder-ide/spyder#8007
# Inject it back into sys.path after all imports in this module but
# before the kernel is initialized
while '' in sys.path:
sys.path.remove('')

# Third-party imports
from traitlets import DottedObjectName

Expand All @@ -29,14 +38,6 @@ def import_spydercustomize():
parent = osp.dirname(here)
customize_dir = osp.join(parent, 'customize')

# Remove current directory from sys.path to prevent kernel
# crashes when people name Python files or modules with
# the same name as standard library modules.
# See spyder-ide/spyder#8007
# Inject it back into sys.path after kernel starts
while '' in sys.path:
sys.path.remove('')

# Import our customizations
site.addsitedir(customize_dir)
import spydercustomize # noqa
Expand Down Expand Up @@ -177,13 +178,6 @@ def main():
# Import our customizations into the kernel
import_spydercustomize()

# Remove current directory from sys.path to prevent kernel
# crashes when people name Python files or modules with
# the same name as standard library modules.
# See spyder-ide/spyder#8007
while '' in sys.path:
sys.path.remove('')

# Main imports
from ipykernel.kernelapp import IPKernelApp
from spyder_kernels.console.kernel import SpyderKernel
Expand Down Expand Up @@ -216,6 +210,12 @@ def close(self):
kernel.config = kernel_config()
except:
pass

# Re-add current working directory path into sys.path after all of the
# import statements, but before initiializing the kernel.
if '' not in sys.path:
sys.path.insert(0, '')

kernel.initialize()

# Set our own magics
Expand Down

0 comments on commit a76e1d3

Please sign in to comment.