Browse Source

Merge pull request #172 from takluyver/wheels-data-lib

Merge library files from wheels data directory
Thomas Kluyver 6 years ago
parent
commit
60d487ba79
2 changed files with 31 additions and 0 deletions
  1. 16 0
      nsist/tests/test_local_wheels.py
  2. 15 0
      nsist/wheels.py

+ 16 - 0
nsist/tests/test_local_wheels.py

@@ -99,3 +99,19 @@ def test_extract_exclude_folder(tmpdir):
 
     assert_isfile(str(pkgs / 'foo' / 'bar.txt'))
     assert_not_path_exists(str(pkgs / 'foo' / 'bar'))
+
+def test_extract_data_lib_sitepkg(tmpdir):
+    whl_file = str(tmpdir / 'foo.whl')
+    pkgs = tmpdir.mkdir('pkgs')
+
+    with ZipFile(whl_file, 'w') as zf:
+        zf.writestr('osgeo/bar.txt', b'blah')
+        # The case of 'Lib/site-packages' shouldn't matter
+        zf.writestr('foo-1.0.data/data/Lib/siTE-packages/osgeo/abc.txt', b'a')
+        zf.writestr('foo-1.0.data/data/lib/site-packages/osgeo/def.txt', b'd')
+
+    extract_wheel(whl_file, str(pkgs), exclude=['pkgs/foo/bar'])
+
+    assert_isfile(str(pkgs / 'osgeo' / 'bar.txt'))
+    assert_isfile(str(pkgs / 'osgeo' / 'abc.txt'))
+    assert_isfile(str(pkgs / 'osgeo' / 'def.txt'))

+ 15 - 0
nsist/wheels.py

@@ -238,6 +238,21 @@ def extract_wheel(whl_file, target_dir, exclude=None):
             if (p / 'platlib').is_dir():
                 merge_dir_to(p / 'platlib', td)
 
+            # HACK: Some wheels from Christoph Gohlke's page have extra package
+            # files added in data/Lib/site-packages. This is a trick that relies
+            # on the default installation layout. It doesn't look like it will
+            # change, so in the best tradition of packaging, we'll work around
+            # the workaround.
+            # https://github.com/takluyver/pynsist/issues/171
+            # This is especially ugly because we do a case-insensitive match,
+            # regardless of the filesystem.
+            if (p / 'data').is_dir():
+                for sd in (p / 'data').iterdir():
+                    if sd.name.lower() == 'lib' and sd.is_dir():
+                        for sd2 in sd.iterdir():
+                            if sd2.name.lower() == 'site-packages' and sd2.is_dir():
+                                merge_dir_to(sd2, td)
+
     # Copy to target directory
     target = Path(target_dir)
     copied_something = False