Skip to content

Commit 123536f

Browse files
authored
bpo-37672: Switch Windows Store package to use pip.ini for user mode (GH-14939)
1 parent e018dc5 commit 123536f

File tree

4 files changed

+50
-35
lines changed

4 files changed

+50
-35
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Switch Windows Store package's pip to use bundled :file:`pip.ini` instead of
2+
:envvar:`PIP_USER` variable.

PC/layout/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def _c(d):
228228

229229
if ns.include_pip:
230230
for dest, src in get_pip_layout(ns):
231-
if isinstance(src, tuple) or not (
231+
if not isinstance(src, tuple) and (
232232
src in EXCLUDE_FROM_LIB or src in EXCLUDE_FROM_PACKAGED_LIB
233233
):
234234
continue

PC/layout/support/pip.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ def get_pip_layout(ns):
3333
pkg_root = "packages/{}" if ns.zip_lib else "Lib/site-packages/{}"
3434
for dest, src in rglob(pip_dir, "**/*"):
3535
yield pkg_root.format(dest), src
36-
yield "pip.ini", ("pip.ini", b"[global]\nuser=yes")
36+
content = "\n".join(
37+
"[{}]\nuser=yes".format(n)
38+
for n in ["install", "uninstall", "freeze", "list"]
39+
)
40+
yield "pip.ini", ("pip.ini", content.encode())
3741

3842

3943
def extract_pip_files(ns):

PC/python_uwp.cpp

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ set_process_name(PyConfig *config)
122122
break;
123123
}
124124
}
125+
size_t i = executable.find_last_of(L"/\\");
126+
if (i == std::wstring::npos) {
127+
executable = PROGNAME;
128+
} else {
129+
executable.replace(i + 1, std::wstring::npos, PROGNAME);
130+
}
125131
}
126132

127133
if (!home.empty()) {
@@ -163,10 +169,29 @@ wmain(int argc, wchar_t **argv)
163169
PyPreConfig preconfig;
164170
PyConfig config;
165171

172+
const wchar_t *moduleName = NULL;
173+
const wchar_t *p = wcsrchr(argv[0], L'\\');
174+
if (!p) {
175+
p = argv[0];
176+
}
177+
if (p) {
178+
if (*p == L'\\') {
179+
p++;
180+
}
181+
182+
if (wcsnicmp(p, L"pip", 3) == 0) {
183+
moduleName = L"pip";
184+
} else if (wcsnicmp(p, L"idle", 4) == 0) {
185+
moduleName = L"idlelib";
186+
}
187+
}
188+
166189
PyPreConfig_InitPythonConfig(&preconfig);
167-
status = Py_PreInitializeFromArgs(&preconfig, argc, argv);
168-
if (PyStatus_Exception(status)) {
169-
goto fail_without_config;
190+
if (!moduleName) {
191+
status = Py_PreInitializeFromArgs(&preconfig, argc, argv);
192+
if (PyStatus_Exception(status)) {
193+
goto fail_without_config;
194+
}
170195
}
171196

172197
status = PyConfig_InitPythonConfig(&config);
@@ -178,48 +203,32 @@ wmain(int argc, wchar_t **argv)
178203
if (PyStatus_Exception(status)) {
179204
goto fail;
180205
}
206+
if (moduleName) {
207+
config.parse_argv = 0;
208+
}
181209

182210
status = set_process_name(&config);
183211
if (PyStatus_Exception(status)) {
184212
goto fail;
185213
}
186214

187-
const wchar_t *p = _wgetenv(L"PYTHONUSERBASE");
215+
p = _wgetenv(L"PYTHONUSERBASE");
188216
if (!p || !*p) {
189217
_wputenv_s(L"PYTHONUSERBASE", get_user_base().c_str());
190218
}
191219

192-
p = wcsrchr(argv[0], L'\\');
193-
if (!p) {
194-
p = argv[0];
195-
}
196-
if (p) {
197-
if (*p == L'\\') {
198-
p++;
220+
if (moduleName) {
221+
status = PyConfig_SetString(&config, &config.run_module, moduleName);
222+
if (PyStatus_Exception(status)) {
223+
goto fail;
199224
}
200-
201-
const wchar_t *moduleName = NULL;
202-
if (wcsnicmp(p, L"pip", 3) == 0) {
203-
moduleName = L"pip";
204-
/* No longer required when pip 19.1 is added */
205-
_wputenv_s(L"PIP_USER", L"true");
206-
} else if (wcsnicmp(p, L"idle", 4) == 0) {
207-
moduleName = L"idlelib";
225+
status = PyConfig_SetString(&config, &config.run_filename, NULL);
226+
if (PyStatus_Exception(status)) {
227+
goto fail;
208228
}
209-
210-
if (moduleName) {
211-
status = PyConfig_SetString(&config, &config.run_module, moduleName);
212-
if (PyStatus_Exception(status)) {
213-
goto fail;
214-
}
215-
status = PyConfig_SetString(&config, &config.run_filename, NULL);
216-
if (PyStatus_Exception(status)) {
217-
goto fail;
218-
}
219-
status = PyConfig_SetString(&config, &config.run_command, NULL);
220-
if (PyStatus_Exception(status)) {
221-
goto fail;
222-
}
229+
status = PyConfig_SetString(&config, &config.run_command, NULL);
230+
if (PyStatus_Exception(status)) {
231+
goto fail;
223232
}
224233
}
225234

0 commit comments

Comments
 (0)