Browse Source

deploy-ng: fix issue with irrelevant wheels in cache dir being used

This is still not a perfect solution, since eg. the wrong version of a package may still be used if older versions are still in the __whl_cache__ directory.  We may want to look into using pip to resolve the package versions, or do something clever such as automatically remove cached wheels if a newer version of the same package was downloaded.
rdb 7 years ago
parent
commit
ea351da50c
1 changed files with 18 additions and 5 deletions
  1. 18 5
      direct/src/showutil/dist.py

+ 18 - 5
direct/src/showutil/dist.py

@@ -185,10 +185,12 @@ class build_apps(setuptools.Command):
 
 
         #TODO find a better way to get abi tag than from internal/private pip APIs
         #TODO find a better way to get abi tag than from internal/private pip APIs
         if hasattr(pip, 'pep425tags'):
         if hasattr(pip, 'pep425tags'):
-            abi_tag = pip.pep425tags.get_abi_tag()
+            pep425tags = pip.pep425tags
+            wheel = pip.wheel
         else:
         else:
-            from pip._internal import pep425tags
-            abi_tag = pep425tags.get_abi_tag()
+            from pip._internal import pep425tags, wheel
+
+        abi_tag = pep425tags.get_abi_tag()
 
 
         if 'u' in abi_tag and (platform.startswith('win') or platform.startswith('macosx')):
         if 'u' in abi_tag and (platform.startswith('win') or platform.startswith('macosx')):
             abi_tag = abi_tag.replace('u', '')
             abi_tag = abi_tag.replace('u', '')
@@ -211,7 +213,18 @@ class build_apps(setuptools.Command):
 
 
         subprocess.check_call([sys.executable, '-m', 'pip'] + pip_args)
         subprocess.check_call([sys.executable, '-m', 'pip'] + pip_args)
 
 
-        wheelpaths = [os.path.join(whldir,i) for i in os.listdir(whldir) if platform in i]
+        # Now figure out which of the downloaded wheels are relevant to us.
+        tags = pep425tags.get_supported(platform=platform, abi=abi_tag)
+        wheelpaths = []
+        for filename in os.listdir(whldir):
+            try:
+                whl = wheel.Wheel(filename)
+            except wheel.InvalidWheelFilename:
+                continue
+
+            if whl.supported(tags):
+                wheelpaths.append(os.path.join(whldir, filename))
+
         return wheelpaths
         return wheelpaths
 
 
     def bundle_macos_app(self, builddir):
     def bundle_macos_app(self, builddir):
@@ -278,7 +291,7 @@ class build_apps(setuptools.Command):
             wheelpaths = self.download_wheels(platform)
             wheelpaths = self.download_wheels(platform)
 
 
             for whl in wheelpaths:
             for whl in wheelpaths:
-                if 'panda3d-' in whl:
+                if os.path.basename(whl).startswith('panda3d-'):
                     p3dwhlfn = whl
                     p3dwhlfn = whl
                     p3dwhl = self._get_zip_file(p3dwhlfn)
                     p3dwhl = self._get_zip_file(p3dwhlfn)
                     break
                     break