diff --git a/rules_python/whl.py b/rules_python/whl.py index 3e9d4f88fa..b08099468e 100644 --- a/rules_python/whl.py +++ b/rules_python/whl.py @@ -18,6 +18,7 @@ import os import pkg_resources import re +import shutil import zipfile @@ -53,6 +54,12 @@ def _dist_info(self): # e.g. google_cloud-0.27.0-py2.py3-none-any.whl -> # google_cloud-0.27.0.dist-info return '{}-{}.dist-info'.format(self.distribution(), self.version()) + + def _data(self): + # Return the name of the data directory within the .whl file. + # e.g. google_cloud-0.27.0-py2.py3-none-any.whl -> + # google_cloud-0.27.0.data + return '{}-{}.data'.format(self.distribution(), self.version()) def metadata(self): # Extract the structured data from metadata.json in the WHL's dist-info @@ -105,6 +112,27 @@ def expand(self, directory): with zipfile.ZipFile(self.path(), 'r') as whl: whl.extractall(directory) + ### PURELIB HACK START + # Find any lib directories, and move them to the top level. + try: + data_contents = os.listdir(self._data()) + except: + data_contents = [] + + # TODO: This is probably wrong. These have different targets, and probably both need to be + # installed. + if 'purelib' in data_contents: + source = os.path.join(self._data(), 'purelib') + elif 'platlib' in data_contents: + source = os.path.join(self._data(), 'platlib') + else: + source = None + + if source: + for f in os.listdir(source): + shutil.move(os.path.join(source, f), directory) + ### PURELIB HACK END + # _parse_metadata parses METADATA files according to https://www.python.org/dev/peps/pep-0314/ def _parse_metadata(self, content): # TODO: handle fields other than just name diff --git a/tools/piptool.par b/tools/piptool.par index 11ec453cd7..98ff1c9d84 100755 Binary files a/tools/piptool.par and b/tools/piptool.par differ diff --git a/tools/whltool.par b/tools/whltool.par index 7cb59c0fbe..3c3c235831 100755 Binary files a/tools/whltool.par and b/tools/whltool.par differ