瀏覽代碼

Merge pull request #142 from ntoll/master

Add pkgs to *._pth files.
Thomas Kluyver 7 年之前
父節點
當前提交
2fa615db1c
共有 1 個文件被更改,包括 14 次插入0 次删除
  1. 14 0
      nsist/__init__.py

+ 14 - 0
nsist/__init__.py

@@ -178,6 +178,9 @@ class InstallerBuilder(object):
         """Fetch the embeddable Windows build for the specified Python version
 
         It will be unpacked into the build directory.
+
+        In addition, any *._pth files found therein will have the pkgs path
+        appended to them.
         """
         url, filename = self._python_download_url_filename()
         cache_file = get_cache_dir(ensure_existence=True) / filename
@@ -197,6 +200,17 @@ class InstallerBuilder(object):
         with zipfile.ZipFile(str(cache_file)) as z:
             z.extractall(python_dir)
 
+        # Manipulate any *._pth files so the default paths AND pkgs directory
+        # ends up in sys.path. Please see:
+        # https://docs.python.org/3/using/windows.html#finding-modules
+        # for more information.
+        pth_files = [f for f in os.listdir(python_dir)
+                     if os.path.isfile(pjoin(python_dir, f))
+                     and f.endswith('._pth')]
+        for pth in pth_files:
+            with open(pjoin(python_dir, pth), 'a+b') as f:
+                f.write(b'\r\n..\\pkgs\r\n')
+
         self.install_dirs.append(('Python', '$INSTDIR'))
 
     def prepare_msvcrt(self):