mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
bpo-33053: -m now adds *starting* directory to sys.path (GH-6231) (#6236)
Historically, -m added the empty string as sys.path
zero, meaning it resolved imports against the current
working directory, the same way -c and the interactive
prompt do.
This changes the sys.path initialisation to add the
*starting* working directory as sys.path[0] instead,
such that changes to the working directory while the
program is running will have no effect on imports
when using the -m switch.
(cherry picked from commit d5d9e02dd3
)
This commit is contained in:
parent
5666a55da8
commit
ee3784594b
9 changed files with 104 additions and 76 deletions
|
@ -524,13 +524,13 @@ def run_test(modules, set_list, skip=None):
|
|||
test.id = lambda : None
|
||||
test.expect_set = list(gen(repeat(()), iter(sl)))
|
||||
with create_modules(modules):
|
||||
sys.path.append(os.getcwd())
|
||||
with TracerRun(test, skip=skip) as tracer:
|
||||
tracer.runcall(tfunc_import)
|
||||
|
||||
@contextmanager
|
||||
def create_modules(modules):
|
||||
with test.support.temp_cwd():
|
||||
sys.path.append(os.getcwd())
|
||||
try:
|
||||
for m in modules:
|
||||
fname = m + '.py'
|
||||
|
@ -542,6 +542,7 @@ def create_modules(modules):
|
|||
finally:
|
||||
for m in modules:
|
||||
test.support.forget(m)
|
||||
sys.path.pop()
|
||||
|
||||
def break_in_func(funcname, fname=__file__, temporary=False, cond=None):
|
||||
return 'break', (fname, None, temporary, cond, funcname)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue