diff --git a/IPython/core/magics/osm.py b/IPython/core/magics/osm.py index 553f49f..c7a0891 100644 --- a/IPython/core/magics/osm.py +++ b/IPython/core/magics/osm.py @@ -165,7 +165,6 @@ class OSMagics(Magics): path = [os.path.abspath(os.path.expanduser(p)) for p in os.environ.get('PATH','').split(os.pathsep)] - path = filter(os.path.isdir,path) syscmdlist = [] # Now define isexec in a cross platform manner. @@ -189,8 +188,12 @@ class OSMagics(Magics): # the innermost part if os.name == 'posix': for pdir in path: - os.chdir(pdir) - for ff in os.listdir(pdir): + try: + os.chdir(pdir) + dirlist = os.listdir(pdir) + except OSError: + continue + for ff in dirlist: if isexec(ff): try: # Removes dots from the name since ipython @@ -205,8 +208,12 @@ class OSMagics(Magics): else: no_alias = Alias.blacklist for pdir in path: - os.chdir(pdir) - for ff in os.listdir(pdir): + try: + os.chdir(pdir) + dirlist = os.listdir(pdir) + except OSError: + continue + for ff in dirlist: base, ext = os.path.splitext(ff) if isexec(ff) and base.lower() not in no_alias: if ext.lower() == '.exe': diff --git a/IPython/testing/iptestcontroller.py b/IPython/testing/iptestcontroller.py index fed1405..b03e144 100644 --- a/IPython/testing/iptestcontroller.py +++ b/IPython/testing/iptestcontroller.py @@ -15,6 +15,7 @@ import argparse import json import multiprocessing.pool import os +import stat import re import requests import shutil @@ -170,6 +171,18 @@ class PyTestController(TestController): # This means we won't get odd effects from our own matplotlib config self.env['MPLCONFIGDIR'] = workingdir.name + # Add a non-accessible directory to PATH (see gh-7053) + noaccess = os.path.join(self.workingdir.name, "_no_access_") + self.noaccess = noaccess + os.mkdir(noaccess, 0) + + PATH = os.environ.get('PATH', '') + if PATH: + PATH = noaccess + os.pathsep + PATH + else: + PATH = noaccess + self.env['PATH'] = PATH + # From options: if self.options.xunit: self.add_xunit() @@ -178,6 +191,14 @@ class PyTestController(TestController): self.env['IPTEST_SUBPROC_STREAMS'] = self.options.subproc_streams self.cmd.extend(self.options.extra_args) + def cleanup(self): + """ + Make the non-accessible directory created in setup() accessible + again, otherwise deleting the workingdir will fail. + """ + os.chmod(self.noaccess, stat.S_IRWXU) + TestController.cleanup(self) + @property def will_run(self): try: