cpython: 7b47c98f24da (original) (raw)

Mercurial > cpython

changeset 103888:7b47c98f24da 3.6

Issue #28137: Renames Windows path file to ._pth Issue #28138: Windows ._pth file should allow import site [#28137]

Steve Dower steve.dower@microsoft.com
date Sat, 17 Sep 2016 12:54:06 -0700
parents b0350f351752
children 5fab409f97de 2156aa4050c7
files Doc/using/windows.rst Doc/whatsnew/3.6.rst Misc/NEWS PC/getpathp.c Tools/msi/make_zip.py
diffstat 5 files changed, 119 insertions(+), 52 deletions(-)[+] [-] Doc/using/windows.rst 32 Doc/whatsnew/3.6.rst 2 Misc/NEWS 9 PC/getpathp.c 113 Tools/msi/make_zip.py 15

line wrap: on

line diff

--- a/Doc/using/windows.rst +++ b/Doc/using/windows.rst @@ -720,15 +720,24 @@ installation directory. So, if you had :file:C:\\Python\\Lib\\ and third-party modules should be stored in :file:C:\\Python\\Lib\\site-packages\\. -To completely override :data:sys.path, create a text file named 'sys.path' -containing a list of paths alongside the Python executable. This will ignore all -registry settings and environment variables, enable isolated mode, disable -importing :mod:site, and fill :data:sys.path with exactly the paths listed -in the file. Paths may be absolute or relative to the directory containing the -file. +To completely override :data:sys.path, create a ._pth file with the same +name as the DLL (python36._pth) or the executable (python._pth) and +specify one line for each path to add to :data:sys.path. The file based on the +DLL name overrides the one based on the executable, which allows paths to be +restricted for any program loading the runtime if desired. -When the 'sys.path' file is missing, this is how :data:sys.path is -populated on Windows: +When the file exists, all registry and environment variables are ignored, +isolated mode is enabled, and :mod:site is not imported unless one line in the +file specifies import site. Blank paths and lines starting with # are +ignored. Each path may be absolute or relative to the location of the file. +Import statements other than to site are not permitted, and arbitrary code +cannot be specified. + +Note that .pth files (without leading underscore) will be processed normally +by the :mod:site module. + +When no ._pth file is found, this is how :data:sys.path is populated on +Windows:

--- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -108,7 +108,7 @@ Windows improvements: which means that when the 260 character path limit may no longer apply. See :ref:removing the MAX_PATH limitation <max-path> for details. -* A sys.path file can be added to force isolated mode and fully specify +* A ._pth file can be added to force isolated mode and fully specify all search paths to avoid registry and environment lookup. See :ref:the documentation <finding_modules> for more information.

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ What's New in Python 3.6.0 beta 2 Core and Builtins ----------------- +- Issue #28192: Don't import readline in isolated mode. +

--- a/PC/getpathp.c +++ b/PC/getpathp.c @@ -6,8 +6,9 @@ PATH RULES FOR WINDOWS: This describes how sys.path is formed on Windows. It describes the functionality, not the implementation (ie, the order in which these

The end result of all this is:

---------------------------------------------------------------- */ @@ -135,6 +147,33 @@ reduce(wchar_t *dir) dir[i] = '\0'; } +static int +change_ext(wchar_t *dest, const wchar_t *src, const wchar_t *ext) +{

+

+

+

+

+

+} static int exists(wchar_t *filename) @@ -499,12 +538,17 @@ find_env_config_value(FILE * env_file, c } static int -read_sys_path_file(const wchar_t *path, const wchar_t *prefix) +read_pth_file(const wchar_t *path, wchar_t *prefix, int *isolated, int *nosite) { FILE *sp_file = _Py_wfopen(path, L"r"); if (sp_file == NULL) return -1;

+ size_t bufsiz = MAXPATHLEN; size_t prefixlen = wcslen(prefix); @@ -516,16 +560,25 @@ read_sys_path_file(const wchar_t *path, char *p = fgets(line, MAXPATHLEN + 1, sp_file); if (!p) break;

while (wn + prefixlen + 4 > bufsiz) { @@ -539,8 +592,8 @@ read_sys_path_file(const wchar_t *path, if (buf[0]) wcscat_s(buf, bufsiz, L";"); + wchar_t *b = &buf[wcslen(buf)];

@@ -586,13 +639,12 @@ calculate_path(void) { wchar_t spbuffer[MAXPATHLEN+1];

+

if (pythonhome == NULL || *pythonhome == '\0') { if (zip_path[0] && exists(zip_path)) {

--- a/Tools/msi/make_zip.py +++ b/Tools/msi/make_zip.py @@ -91,11 +91,13 @@ def include_in_tools(p): return p.suffix.lower() in {'.py', '.pyw', '.txt'} +BASE_NAME = 'python{0.major}{0.minor}'.format(sys.version_info) + FULL_LAYOUT = [ ('/', 'PCBuild/$arch', 'python.exe', is_not_debug), ('/', 'PCBuild/$arch', 'pythonw.exe', is_not_debug),

] if os.getenv('DOC_FILENAME'): @@ -209,9 +211,12 @@ def main(): print('Copied {} files'.format(copied)) if ns.embed:

if out: total = copy_to_layout(out, rglob(temp, '**/*', None))