def resolvedirof(filename): try: filename = rpath.rabspath(filename) except OSError: pass dirname = rpath.rabspath(os.path.join(filename, '..')) if os.path.islink(filename): try: link = readlink_maybe(filename) except OSError: pass else: return resolvedirof(os.path.join(dirname, link)) return dirname
def find_executable(executable): """ Return the absolute path of the executable, by looking into PATH and the current directory. If it cannot be found, return ''. """ if we_are_translated() and IS_WINDOWS and not executable.lower().endswith('.exe'): executable += '.exe' if os.sep in executable or (IS_WINDOWS and ':' in executable): pass # the path is already more than just an executable name else: path = os.environ.get('PATH') if path: for dir in path.split(os.pathsep): fn = os.path.join(dir, executable) if os.path.isfile(fn): executable = fn break executable = rpath.rabspath(executable) # # 'sys.executable' should not end up being an non-existing file; # just use '' in this case. (CPython issue #7774) if not os.path.isfile(executable): executable = '' return executable
def test_rabspath_relative(tmpdir): tmpdir.chdir() assert rpath.rabspath('foo') == tmpdir.join('foo')
def test_rabspath_absolute_nt(): curdrive, _ = os.path.splitdrive(os.getcwd()) assert rpath.rabspath('\\foo') == '%s\\foo' % curdrive
def test_rabspath_absolute_posix(): assert rpath.rabspath('/foo') == '/foo'