mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Partial port of r78919 from trunk: add subdir argument to the findfile helper
This commit is contained in:
parent
0a5d9a29bb
commit
3f682adcf2
1 changed files with 3 additions and 1 deletions
|
@ -387,12 +387,14 @@ if fp is not None:
|
||||||
unlink(TESTFN)
|
unlink(TESTFN)
|
||||||
del fp
|
del fp
|
||||||
|
|
||||||
def findfile(file, here=__file__):
|
def findfile(file, here=__file__, subdir=None):
|
||||||
"""Try to find a file on sys.path and the working directory. If it is not
|
"""Try to find a file on sys.path and the working directory. If it is not
|
||||||
found the argument passed to the function is returned (this does not
|
found the argument passed to the function is returned (this does not
|
||||||
necessarily signal failure; could still be the legitimate path)."""
|
necessarily signal failure; could still be the legitimate path)."""
|
||||||
if os.path.isabs(file):
|
if os.path.isabs(file):
|
||||||
return file
|
return file
|
||||||
|
if subdir is not None:
|
||||||
|
file = os.path.join(subdir, file)
|
||||||
path = sys.path
|
path = sys.path
|
||||||
path = [os.path.dirname(here)] + path
|
path = [os.path.dirname(here)] + path
|
||||||
for dn in path:
|
for dn in path:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue