Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1df0752

Browse files
authored
gh-99370: fix test_zippath_from_non_installed_posix (GH-99483)
When build with shared enabled, we need to set `LD_LIBRARY_PATH`for the non-installed python environment intest_zippath_from_non_installed_posix so that the python binaryand find and link the libpython.so.
1 parentdc3e435 commit1df0752

File tree

1 file changed

+60
-51
lines changed

1 file changed

+60
-51
lines changed

‎Lib/test/test_venv.py

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -547,58 +547,67 @@ def test_zippath_from_non_installed_posix(self):
547547
rmtree(self.env_dir)
548548
# First try to create a non-installed python. It's not a real full
549549
# functional non-installed python, but enough for this test.
550+
platlibdir=sys.platlibdir
550551
non_installed_dir=os.path.realpath(tempfile.mkdtemp())
551-
try:
552-
bindir=os.path.join(non_installed_dir,self.bindir)
553-
os.mkdir(bindir)
554-
shutil.copy2(sys.executable,bindir)
555-
libdir=os.path.join(non_installed_dir,*self.lib)
556-
os.makedirs(libdir)
557-
landmark=os.path.join(libdir,"os.py")
558-
stdlib_zip="python%d%d.zip"%sys.version_info[:2]
559-
zip_landmark=os.path.join(non_installed_dir,
560-
self.lib[0],
561-
stdlib_zip)
562-
additional_pythonpath_for_non_installed= []
563-
# Copy stdlib files to the non-installed python so venv can
564-
# correctly calculate the prefix.
565-
foreachpathinsys.path:
566-
ifeachpath.endswith(".zip"):
567-
ifos.path.isfile(eachpath):
568-
shutil.copyfile(
569-
eachpath,
570-
os.path.join(non_installed_dir,self.lib[0]))
571-
elifos.path.isfile(os.path.join(eachpath,"os.py")):
572-
fornameinos.listdir(eachpath):
573-
ifname=="site-packages":
574-
continue
575-
fn=os.path.join(eachpath,name)
576-
ifos.path.isfile(fn):
577-
shutil.copy(fn,libdir)
578-
elifos.path.isdir(fn):
579-
shutil.copytree(fn,os.path.join(libdir,name))
580-
else:
581-
additional_pythonpath_for_non_installed.append(
582-
eachpath)
583-
cmd= [os.path.join(non_installed_dir,self.bindir,self.exe),
584-
"-m",
585-
"venv",
586-
"--without-pip",
587-
self.env_dir]
588-
# Our fake non-installed python is not fully functional because
589-
# it cannot find the extensions. Set PYTHONPATH so it can run the
590-
# venv module correctly.
591-
pythonpath=os.pathsep.join(
592-
additional_pythonpath_for_non_installed)
593-
subprocess.check_call(cmd,env={"PYTHONPATH":pythonpath})
594-
envpy=os.path.join(self.env_dir,self.bindir,self.exe)
595-
# Now check the venv created from the non-installed python has
596-
# correct zip path in pythonpath.
597-
cmd= [envpy,'-S','-c','import sys; print(sys.path)']
598-
out,err=check_output(cmd)
599-
self.assertTrue(zip_landmark.encode()inout)
600-
finally:
601-
rmtree(non_installed_dir)
552+
self.addCleanup(rmtree,non_installed_dir)
553+
bindir=os.path.join(non_installed_dir,self.bindir)
554+
os.mkdir(bindir)
555+
shutil.copy2(sys.executable,bindir)
556+
libdir=os.path.join(non_installed_dir,platlibdir,self.lib[1])
557+
os.makedirs(libdir)
558+
landmark=os.path.join(libdir,"os.py")
559+
stdlib_zip="python%d%d.zip"%sys.version_info[:2]
560+
zip_landmark=os.path.join(non_installed_dir,
561+
platlibdir,
562+
stdlib_zip)
563+
additional_pythonpath_for_non_installed= []
564+
# Copy stdlib files to the non-installed python so venv can
565+
# correctly calculate the prefix.
566+
foreachpathinsys.path:
567+
ifeachpath.endswith(".zip"):
568+
ifos.path.isfile(eachpath):
569+
shutil.copyfile(
570+
eachpath,
571+
os.path.join(non_installed_dir,platlibdir))
572+
elifos.path.isfile(os.path.join(eachpath,"os.py")):
573+
fornameinos.listdir(eachpath):
574+
ifname=="site-packages":
575+
continue
576+
fn=os.path.join(eachpath,name)
577+
ifos.path.isfile(fn):
578+
shutil.copy(fn,libdir)
579+
elifos.path.isdir(fn):
580+
shutil.copytree(fn,os.path.join(libdir,name))
581+
else:
582+
additional_pythonpath_for_non_installed.append(
583+
eachpath)
584+
cmd= [os.path.join(non_installed_dir,self.bindir,self.exe),
585+
"-m",
586+
"venv",
587+
"--without-pip",
588+
self.env_dir]
589+
# Our fake non-installed python is not fully functional because
590+
# it cannot find the extensions. Set PYTHONPATH so it can run the
591+
# venv module correctly.
592+
pythonpath=os.pathsep.join(
593+
additional_pythonpath_for_non_installed)
594+
# For python built with shared enabled. We need to set
595+
# LD_LIBRARY_PATH so the non-installed python can find and link
596+
# libpython.so
597+
ld_library_path=os.path.abspath(os.path.dirname(sys.executable))
598+
ifsys.platform=='darwin':
599+
ld_library_path_env="DYLD_LIBRARY_PATH"
600+
else:
601+
ld_library_path_env="LD_LIBRARY_PATH"
602+
subprocess.check_call(cmd,
603+
env={"PYTHONPATH":pythonpath,
604+
ld_library_path_env:ld_library_path})
605+
envpy=os.path.join(self.env_dir,self.bindir,self.exe)
606+
# Now check the venv created from the non-installed python has
607+
# correct zip path in pythonpath.
608+
cmd= [envpy,'-S','-c','import sys; print(sys.path)']
609+
out,err=check_output(cmd)
610+
self.assertTrue(zip_landmark.encode()inout)
602611

603612
@requireVenvCreate
604613
classEnsurePipTest(BaseTest):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp