mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
bpo-46015: Fixes calculation of sys.path in a venv on Windows (GH-29992)
Also ensures that pybuilddir.txt is written early enough in the build to be picked up by later steps.
This commit is contained in:
parent
3cb9731b7e
commit
7778116c2f
6 changed files with 20 additions and 12 deletions
|
@ -1362,6 +1362,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
|
||||||
if not MS_WINDOWS:
|
if not MS_WINDOWS:
|
||||||
paths[-1] = lib_dynload
|
paths[-1] = lib_dynload
|
||||||
else:
|
else:
|
||||||
|
# Include DLLs directory as well
|
||||||
|
paths.insert(1, '.\\DLLs')
|
||||||
for index, path in enumerate(paths):
|
for index, path in enumerate(paths):
|
||||||
if index == 0:
|
if index == 0:
|
||||||
# Because we copy the DLLs into tmpdir as well, the zip file
|
# Because we copy the DLLs into tmpdir as well, the zip file
|
||||||
|
|
|
@ -100,6 +100,7 @@ class MockGetPathTests(unittest.TestCase):
|
||||||
module_search_paths_set=1,
|
module_search_paths_set=1,
|
||||||
module_search_paths=[
|
module_search_paths=[
|
||||||
r"C:\Python\python98.zip",
|
r"C:\Python\python98.zip",
|
||||||
|
r"C:\Python\DLLs",
|
||||||
r"C:\Python\Lib",
|
r"C:\Python\Lib",
|
||||||
r"C:\Python",
|
r"C:\Python",
|
||||||
],
|
],
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fixed calculation of :data:`sys.path` in a venv on Windows.
|
|
@ -390,7 +390,7 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
|
||||||
while (cb && (p1[cb] == L'\n' || p1[cb] == L'\r')) {
|
while (cb && (p1[cb] == L'\n' || p1[cb] == L'\r')) {
|
||||||
--cb;
|
--cb;
|
||||||
}
|
}
|
||||||
PyObject *u = PyUnicode_FromWideChar(p1, cb + 1);
|
PyObject *u = PyUnicode_FromWideChar(p1, cb ? cb + 1 : 0);
|
||||||
if (!u || PyList_Append(r, u) < 0) {
|
if (!u || PyList_Append(r, u) < 0) {
|
||||||
Py_XDECREF(u);
|
Py_XDECREF(u);
|
||||||
Py_CLEAR(r);
|
Py_CLEAR(r);
|
||||||
|
|
|
@ -668,14 +668,17 @@ elif not pythonpath:
|
||||||
pythonpath.append(joinpath(prefix, p))
|
pythonpath.append(joinpath(prefix, p))
|
||||||
|
|
||||||
# Then add stdlib_dir and platstdlib_dir
|
# Then add stdlib_dir and platstdlib_dir
|
||||||
if stdlib_dir:
|
if os_name == 'nt' and venv_prefix:
|
||||||
pythonpath.append(stdlib_dir)
|
# QUIRK: Windows generates paths differently in a venv
|
||||||
if platstdlib_dir:
|
if platstdlib_dir:
|
||||||
if os_name == 'nt' and venv_prefix:
|
pythonpath.append(platstdlib_dir)
|
||||||
# QUIRK: Windows appends executable_dir instead of platstdlib_dir
|
if stdlib_dir:
|
||||||
# when in a venv
|
pythonpath.append(stdlib_dir)
|
||||||
pythonpath.append(executable_dir)
|
pythonpath.append(executable_dir)
|
||||||
else:
|
else:
|
||||||
|
if stdlib_dir:
|
||||||
|
pythonpath.append(stdlib_dir)
|
||||||
|
if platstdlib_dir:
|
||||||
pythonpath.append(platstdlib_dir)
|
pythonpath.append(platstdlib_dir)
|
||||||
|
|
||||||
config['module_search_paths'] = pythonpath
|
config['module_search_paths'] = pythonpath
|
||||||
|
|
|
@ -117,6 +117,10 @@
|
||||||
<Import Project="regen.targets" />
|
<Import Project="regen.targets" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<Target Name="_TriggerPostRegen" AfterTargets="Build" DependsOnTargets="PostBuildRegen" />
|
<Target Name="_TriggerPostRegen" AfterTargets="Build" DependsOnTargets="PostBuildRegen" />
|
||||||
|
<Target Name="GeneratePyBuildDirTxt" AfterTargets="Link">
|
||||||
|
<Message Text="Generating $(OutDir)pybuilddir.txt" />
|
||||||
|
<WriteLinesToFile File="$(OutDir)pybuilddir.txt" Lines="%0D%0A" Overwrite="true" />
|
||||||
|
</Target>
|
||||||
<Target Name="ValidateUcrtbase" AfterTargets="AfterBuild" Condition="$(Configuration) != 'PGInstrument' and $(Platform) != 'ARM' and $(Platform) != 'ARM64'">
|
<Target Name="ValidateUcrtbase" AfterTargets="AfterBuild" Condition="$(Configuration) != 'PGInstrument' and $(Platform) != 'ARM' and $(Platform) != 'ARM64'">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<UcrtName>ucrtbase</UcrtName>
|
<UcrtName>ucrtbase</UcrtName>
|
||||||
|
@ -147,7 +151,4 @@ $(_PGOPath)
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<WriteLinesToFile File="$(PySourcePath)python.bat" Lines="$(_Content)" Overwrite="true" Condition="'$(_Content)' != '$(_ExistingContent)'" />
|
<WriteLinesToFile File="$(PySourcePath)python.bat" Lines="$(_Content)" Overwrite="true" Condition="'$(_Content)' != '$(_ExistingContent)'" />
|
||||||
</Target>
|
</Target>
|
||||||
<Target Name="GeneratePyBuildDirTxt" BeforeTargets="AfterBuild">
|
|
||||||
<WriteLinesToFile File="$(OutDir)pybuilddir.txt" Lines="" Overwrite="true" />
|
|
||||||
</Target>
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue