[Python-checkins] bpo-37672: Switch Windows Store package to use pip.ini for user mode (GH-14939)

Steve Dower webhook-mailer at python.org
Wed Jul 24 18:13:36 EDT 2019


https://github.com/python/cpython/commit/123536fdab7b8def15c859aa70232bc55ec73096
commit: 123536fdab7b8def15c859aa70232bc55ec73096
branch: master
author: Steve Dower <steve.dower at python.org>
committer: GitHub <noreply at github.com>
date: 2019年07月24日T15:13:22-07:00
summary:
bpo-37672: Switch Windows Store package to use pip.ini for user mode (GH-14939)
files:
A Misc/NEWS.d/next/Windows/2019-07-24-14-36-28.bpo-37672.uKEVHN.rst
M PC/layout/main.py
M PC/layout/support/pip.py
M PC/python_uwp.cpp
diff --git a/Misc/NEWS.d/next/Windows/2019-07-24-14-36-28.bpo-37672.uKEVHN.rst b/Misc/NEWS.d/next/Windows/2019-07-24-14-36-28.bpo-37672.uKEVHN.rst
new file mode 100644
index 000000000000..78b51c191825
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2019-07-24-14-36-28.bpo-37672.uKEVHN.rst
@@ -0,0 +1,2 @@
+Switch Windows Store package's pip to use bundled :file:`pip.ini` instead of
+:envvar:`PIP_USER` variable.
diff --git a/PC/layout/main.py b/PC/layout/main.py
index c39aab208d35..111f8aad2561 100644
--- a/PC/layout/main.py
+++ b/PC/layout/main.py
@@ -228,7 +228,7 @@ def _c(d):
 
 if ns.include_pip:
 for dest, src in get_pip_layout(ns):
- if isinstance(src, tuple) or not (
+ if not isinstance(src, tuple) and (
 src in EXCLUDE_FROM_LIB or src in EXCLUDE_FROM_PACKAGED_LIB
 ):
 continue
diff --git a/PC/layout/support/pip.py b/PC/layout/support/pip.py
index eada456655ec..4ad3b1dd5bc0 100644
--- a/PC/layout/support/pip.py
+++ b/PC/layout/support/pip.py
@@ -33,7 +33,11 @@ def get_pip_layout(ns):
 pkg_root = "packages/{}" if ns.zip_lib else "Lib/site-packages/{}"
 for dest, src in rglob(pip_dir, "**/*"):
 yield pkg_root.format(dest), src
- yield "pip.ini", ("pip.ini", b"[global]\nuser=yes")
+ content = "\n".join(
+ "[{}]\nuser=yes".format(n)
+ for n in ["install", "uninstall", "freeze", "list"]
+ )
+ yield "pip.ini", ("pip.ini", content.encode())
 
 
 def extract_pip_files(ns):
diff --git a/PC/python_uwp.cpp b/PC/python_uwp.cpp
index 2352f45e8a3d..06c1dd353655 100644
--- a/PC/python_uwp.cpp
+++ b/PC/python_uwp.cpp
@@ -122,6 +122,12 @@ set_process_name(PyConfig *config)
 break;
 }
 }
+ size_t i = executable.find_last_of(L"/\\");
+ if (i == std::wstring::npos) {
+ executable = PROGNAME;
+ } else {
+ executable.replace(i + 1, std::wstring::npos, PROGNAME);
+ }
 }
 
 if (!home.empty()) {
@@ -163,10 +169,29 @@ wmain(int argc, wchar_t **argv)
 PyPreConfig preconfig;
 PyConfig config;
 
+ const wchar_t *moduleName = NULL;
+ const wchar_t *p = wcsrchr(argv[0], L'\\');
+ if (!p) {
+ p = argv[0];
+ }
+ if (p) {
+ if (*p == L'\\') {
+ p++;
+ }
+
+ if (wcsnicmp(p, L"pip", 3) == 0) {
+ moduleName = L"pip";
+ } else if (wcsnicmp(p, L"idle", 4) == 0) {
+ moduleName = L"idlelib";
+ }
+ }
+
 PyPreConfig_InitPythonConfig(&preconfig);
- status = Py_PreInitializeFromArgs(&preconfig, argc, argv);
- if (PyStatus_Exception(status)) {
- goto fail_without_config;
+ if (!moduleName) {
+ status = Py_PreInitializeFromArgs(&preconfig, argc, argv);
+ if (PyStatus_Exception(status)) {
+ goto fail_without_config;
+ }
 }
 
 status = PyConfig_InitPythonConfig(&config);
@@ -178,48 +203,32 @@ wmain(int argc, wchar_t **argv)
 if (PyStatus_Exception(status)) {
 goto fail;
 }
+ if (moduleName) {
+ config.parse_argv = 0;
+ }
 
 status = set_process_name(&config);
 if (PyStatus_Exception(status)) {
 goto fail;
 }
 
- const wchar_t *p = _wgetenv(L"PYTHONUSERBASE");
+ p = _wgetenv(L"PYTHONUSERBASE");
 if (!p || !*p) {
 _wputenv_s(L"PYTHONUSERBASE", get_user_base().c_str());
 }
 
- p = wcsrchr(argv[0], L'\\');
- if (!p) {
- p = argv[0];
- }
- if (p) {
- if (*p == L'\\') {
- p++;
+ if (moduleName) {
+ status = PyConfig_SetString(&config, &config.run_module, moduleName);
+ if (PyStatus_Exception(status)) {
+ goto fail;
 }
-
- const wchar_t *moduleName = NULL;
- if (wcsnicmp(p, L"pip", 3) == 0) {
- moduleName = L"pip";
- /* No longer required when pip 19.1 is added */
- _wputenv_s(L"PIP_USER", L"true");
- } else if (wcsnicmp(p, L"idle", 4) == 0) {
- moduleName = L"idlelib";
+ status = PyConfig_SetString(&config, &config.run_filename, NULL);
+ if (PyStatus_Exception(status)) {
+ goto fail;
 }
-
- if (moduleName) {
- status = PyConfig_SetString(&config, &config.run_module, moduleName);
- if (PyStatus_Exception(status)) {
- goto fail;
- }
- status = PyConfig_SetString(&config, &config.run_filename, NULL);
- if (PyStatus_Exception(status)) {
- goto fail;
- }
- status = PyConfig_SetString(&config, &config.run_command, NULL);
- if (PyStatus_Exception(status)) {
- goto fail;
- }
+ status = PyConfig_SetString(&config, &config.run_command, NULL);
+ if (PyStatus_Exception(status)) {
+ goto fail;
 }
 }
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /