瀏覽代碼

Copy package metadata from wheels and from modules

Adrien Ferrand 6 年之前
父節點
當前提交
5e624ec0f6
共有 2 個文件被更改,包括 19 次插入1 次删除
  1. 18 0
      nsist/copymodules.py
  2. 1 1
      nsist/pypi.py

+ 18 - 0
nsist/copymodules.py

@@ -7,6 +7,7 @@ import sys
 import tempfile
 import zipfile, zipimport
 import fnmatch
+import pkg_resources
 from functools import partial
 
 from .util import normalize_path
@@ -148,6 +149,23 @@ class ModuleCopier:
         elif isinstance(loader, zipimport.zipimporter):
             copy_zipmodule(loader, modname, target)
 
+        copy_distribution(modname, target)
+
+def copy_distribution(modname, target):
+    """Copy the metadata directory of the specified module 
+    to the target directory if exists.
+    """
+    try:
+        distribution = pkg_resources.get_distribution(modname)
+    except pkg_resources.DistributionNotFound:
+        # The package metadata is not available. We skip the process.
+        return
+
+    egg_info_path = distribution._provider.egg_info
+    if os.path.exists(egg_info_path):
+        dest = os.path.join(target, os.path.basename(egg_info_path))
+        shutil.copytree(egg_info_path, dest)
+
 
 def copy_modules(modnames, target, py_version, path=None, exclude=None):
     """Copy the specified importable modules to the target directory.

+ 1 - 1
nsist/pypi.py

@@ -229,7 +229,7 @@ def extract_wheel(whl_file, target_dir, exclude=None):
     target = Path(target_dir)
     copied_something = False
     for p in td.iterdir():
-        if p.suffix not in {'.data', '.dist-info'}:
+        if p.suffix not in {'.data'}:
             if p.is_dir():
                 # If the dst directory already exists, this will combine them.
                 # shutil.copytree will not combine them.