From 665bdb16eafdd918905d5de6219ccdec0b90234d Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Mon, 8 Oct 2018 18:36:23 -0700 Subject: [PATCH] deploy-ng: Add options for using optimized wheels for panda3d This works by adding extra index urls. Optimized wheels have local version tags that should take precedence over non-optimized wheels. If no optimized wheel if found for a platform, a warning is issued and a non-optimized wheel is used instead. --- direct/src/showutil/dist.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/direct/src/showutil/dist.py b/direct/src/showutil/dist.py index 2bf6602c97..608371de14 100644 --- a/direct/src/showutil/dist.py +++ b/direct/src/showutil/dist.py @@ -7,6 +7,7 @@ import plistlib import sys import subprocess import zipfile +import re import shutil import stat import struct @@ -207,6 +208,8 @@ class build_apps(setuptools.Command): self.log_filename = None self.log_append = False self.requirements_path = './requirements.txt' + self.use_optimized_wheels = True + self.optimized_wheel_index = '' self.pypi_extra_indexes = [] self.file_handlers = {} self.exclude_dependencies = [ @@ -288,6 +291,17 @@ class build_apps(setuptools.Command): subprocess.check_call(['pipenv', 'lock', '--requirements'], stdout=reqsfile) self.requirements_path = reqspath + if self.use_optimized_wheels: + if not self.optimized_wheel_index: + # Try to find an appropriate wheel index + with open(self.requirements_path) as reqsfile: + reqsdata = reqsfile.read() + matches = re.search(r'--extra-index-url (https*://archive.panda3d.org/.*\b)', reqsdata) + if matches and matches.group(1): + self.optimized_wheel_index = matches.group(1) + '/opt' + + assert self.optimized_wheel_index, 'An index for optimized wheels must be defined if use_optimized_wheels is set' + assert os.path.exists(self.requirements_path), 'Requirements.txt path does not exist: {}'.format(self.requirements_path) assert num_gui_apps + num_console_apps != 0, 'Must specify at least one app in either gui_apps or console_apps' @@ -362,6 +376,11 @@ class build_apps(setuptools.Command): '--abi', abi_tag ] + if self.use_optimized_wheels: + pip_args += [ + '--extra-index-url', self.optimized_wheel_index + ] + for index in self.pypi_extra_indexes: pip_args += ['--extra-index-url', index] @@ -452,6 +471,15 @@ class build_apps(setuptools.Command): else: raise RuntimeError("Missing panda3d wheel for platform: {}".format(platform)) + if self.use_optimized_wheels: + # Check to see if we have an optimized wheel + localtag = p3dwhlfn.split('+')[1].split('-')[0] + if not localtag.endswith('opt'): + self.announce( + 'Could not find an optimized wheel (using index {}) for platform: {}'.format(self.optimized_wheel_index, platform), + distutils.log.WARN + ) + #whlfiles = {whl: self._get_zip_file(whl) for whl in wheelpaths} # Add whl files to the path so they are picked up by modulefinder