Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[WIP] Finish sys.base_executable changes, improve alias path calculation
  • Loading branch information
zooba committed Jun 27, 2019
commit 00db87b9e70fd4f530b1ada75c47f1a99b6431c5
5 changes: 2 additions & 3 deletions Lib/multiprocessing/popen_spawn_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
def _path_eq(p1, p2):
return p1 == p2 or os.path.normcase(p1) == os.path.normcase(p2)

WINENV = (hasattr(sys, '_base_executable') and
not _path_eq(sys.executable, sys._base_executable))
WINENV = not _path_eq(sys.executable, sys.base_executable)


def _close_handles(*handles):
Expand Down Expand Up @@ -62,7 +61,7 @@ def __init__(self, process_obj):
# bpo-35797: When running in a venv, we bypass the redirect
# executor and launch our base Python.
if WINENV and _path_eq(python_exe, sys.executable):
python_exe = sys._base_executable
python_exe = sys.base_executable
env = os.environ.copy()
env["__PYVENV_LAUNCHER__"] = sys.executable
else:
Expand Down
15 changes: 2 additions & 13 deletions Lib/test/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@
except ImportError:
ctypes = None

# Platforms that set sys._base_executable can create venvs from within
# another venv, so no need to skip tests that require venv.create().
requireVenvCreate = unittest.skipUnless(
hasattr(sys, '_base_executable')
or sys.prefix == sys.base_prefix,
'cannot run venv.create from within a venv on this platform')

Comment thread
zooba marked this conversation as resolved.
def check_output(cmd, encoding=None):
p = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
Expand All @@ -57,7 +50,7 @@ def setUp(self):
self.bindir = 'bin'
self.lib = ('lib', 'python%d.%d' % sys.version_info[:2])
self.include = 'include'
executable = getattr(sys, '_base_executable', sys.executable)
executable = sys.base_executable
self.exe = os.path.split(executable)[-1]

def tearDown(self):
Expand Down Expand Up @@ -102,7 +95,7 @@ def test_defaults(self):
else:
self.assertFalse(os.path.exists(p))
data = self.get_text_file_contents('pyvenv.cfg')
executable = getattr(sys, '_base_executable', sys.executable)
executable = sys.base_executable
path = os.path.dirname(executable)
self.assertIn('home = %s' % path, data)
fn = self.get_env_file(self.bindir, self.exe)
Expand Down Expand Up @@ -153,7 +146,6 @@ def pip_cmd_checker(cmd):
with patch('venv.subprocess.check_call', pip_cmd_checker):
builder.upgrade_dependencies(fake_context)

@requireVenvCreate
def test_prefixes(self):
"""
Test that the prefix values are as expected.
Expand Down Expand Up @@ -289,7 +281,6 @@ def test_symlinking(self):
# run the test, the pyvenv.cfg in the venv created in the test will
# point to the venv being used to run the test, and we lose the link
# to the source build - so Python can't initialise properly.
@requireVenvCreate
def test_executable(self):
"""
Test that the sys.executable value is as expected.
Expand Down Expand Up @@ -333,7 +324,6 @@ def test_unicode_in_batch_file(self):
)
self.assertEqual(out.strip(), '0')

@requireVenvCreate
def test_multiprocessing(self):
"""
Test that the multiprocessing is able to spawn.
Expand All @@ -353,7 +343,6 @@ def test_multiprocessing(self):
'pool.terminate()'])
self.assertEqual(out.strip(), "python".encode())

@requireVenvCreate
class EnsurePipTest(BaseTest):
"""Test venv module installation of pip."""
def assert_pip_not_installed(self):
Expand Down
2 changes: 1 addition & 1 deletion Lib/venv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def create_if_needed(d):
prompt = self.prompt if self.prompt is not None else context.env_name
context.prompt = '(%s) ' % prompt
create_if_needed(env_dir)
executable = getattr(sys, '_base_executable', sys.executable)
executable = sys.base_executable
dirname, exename = os.path.split(os.path.abspath(executable))
context.executable = executable
context.python_dir = dirname
Expand Down
37 changes: 20 additions & 17 deletions PC/python_uwp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <shellapi.h>
#include <shlobj.h>

#include <winrt\Windows.ApplicationModel.h>
#include <winrt\Windows.Storage.h>
Expand Down Expand Up @@ -70,21 +71,23 @@ set_process_name(PyConfig *config)
wchar_t *r = NULL;

const auto family = get_package_family();
while (!family.empty() && !r) {
r = (wchar_t *)malloc(bufferLen * sizeof(wchar_t));
if (!r) {
Py_FatalError("out of memory");
return 0;
}
len = _snwprintf_s(r, bufferLen, _TRUNCATE,
L"%ls\\Microsoft\\WindowsApps\\%ls\\%ls",
_wgetenv(L"LOCALAPPDATA"),
family.c_str(),
PROGNAME);
if (len < 0) {
free((void *)r);
r = NULL;
bufferLen *= 2;

if (!family.empty()) {
PWSTR localAppData;
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0,
NULL, &localAppData))) {
bufferLen = (DWORD)(wcslen(localAppData)
+ family.size()
+ wcslen(PROGNAME)
+ 25);
r = (wchar_t *)malloc(bufferLen * sizeof(wchar_t));
swprintf_s(r, bufferLen,
L"%ls\\Microsoft\\WindowsApps\\%ls\\%ls",
localAppData,
family.c_str(),
PROGNAME);

CoTaskMemFree(localAppData);
}
}

Expand Down Expand Up @@ -131,12 +134,12 @@ wmain(int argc, wchar_t **argv)
if (PyStatus_Exception(status)) {
goto fail;
}

status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
goto fail;
}

status = PyConfig_SetArgv(&config, argc, argv);
if (PyStatus_Exception(status)) {
goto fail;
Expand Down