Skip to content

Commit

Permalink
Mac app: Make our PYTHONPATH manager work for it
Browse files Browse the repository at this point in the history
Fixes #1321
  • Loading branch information
ccordoba12 committed Mar 6, 2015
1 parent 7603a79 commit 2d075c1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
4 changes: 2 additions & 2 deletions spyderlib/widgets/externalshell/baseshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
from spyderlib.py3compat import is_text_string, to_text_string


def add_pathlist_to_PYTHONPATH(env, pathlist):
def add_pathlist_to_PYTHONPATH(env, pathlist, drop_env=False):
# PyQt API 1/2 compatibility-related tests:
assert isinstance(env, list)
assert all([is_text_string(path) for path in env])

pypath = "PYTHONPATH"
pathstr = os.pathsep.join(pathlist)
if os.environ.get(pypath) is not None:
if os.environ.get(pypath) is not None and not drop_env:
for index, var in enumerate(env[:]):
if var.startswith(pypath+'='):
env[index] = var.replace(pypath+'=',
Expand Down
12 changes: 5 additions & 7 deletions spyderlib/widgets/externalshell/pythonshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,9 @@ def create_process(self):

# IPython kernel
env.append('IPYTHON_KERNEL=%r' % self.is_ipykernel)

pathlist = []

# Fix encoding with custom "sitecustomize.py"
# Add sitecustomize path to path list
pathlist = []
scpath = osp.dirname(osp.abspath(__file__))
pathlist.append(scpath)

Expand Down Expand Up @@ -510,8 +509,8 @@ def create_process(self):
# 1. PYTHONPATH and PYTHONHOME are set while bootstrapping the app,
# but their values are messing sys.path for external interpreters
# (e.g. EPD) so we need to remove them from the environment.
# 2. Add this file's dir to PYTHONPATH. This will make every external
# interpreter to use our sitecustomize script.
# 2. Set PYTHONPATH again but without grabbing entries defined in the
# environment (Fixes Issue 1321)
# 3. Remove PYTHONOPTIMIZE from env so that we can have assert
# statements working with our interpreters (See Issue 1281)
if running_in_mac_app():
Expand All @@ -520,8 +519,7 @@ def create_process(self):
env = [p for p in env if not (p.startswith('PYTHONPATH') or \
p.startswith('PYTHONHOME'))] # 1.

env.append('PYTHONPATH=%s' % osp.dirname(__file__)) # 2.

add_pathlist_to_PYTHONPATH(env, pathlist, drop_env=True) # 2.
env = [p for p in env if not p.startswith('PYTHONOPTIMIZE')] # 3.

self.process.setEnvironment(env)
Expand Down
5 changes: 0 additions & 5 deletions spyderlib/widgets/externalshell/sitecustomize.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ def write(self, text):
if MAC_APP_NAME in __file__:
interpreter = os.environ.get('SPYDER_INTERPRETER')
if MAC_APP_NAME not in interpreter:
# We added this file's dir to PYTHONPATH (in pythonshell.py)
# so that external interpreters can import this script, and
# now we are removing it
del os.environ['PYTHONPATH']

# Add a minimal library (with spyderlib) at the end of sys.path to
# be able to connect our monitor to the external console
py_ver = '%s.%s' % (sys.version_info[0], sys.version_info[1])
Expand Down

0 comments on commit 2d075c1

Please sign in to comment.