|
18 | 18 | import os
|
19 | 19 | import pkg_resources
|
20 | 20 | import re
|
| 21 | +import shutil |
21 | 22 | import zipfile
|
22 | 23 |
|
23 | 24 |
|
@@ -54,6 +55,12 @@ def _dist_info(self):
|
54 | 55 | # google_cloud-0.27.0.dist-info
|
55 | 56 | return '{}-{}.dist-info'.format(self.distribution(), self.version())
|
56 | 57 |
|
| 58 | + def _data(self): |
| 59 | + # Return the name of the data directory within the .whl file. |
| 60 | + # e.g. google_cloud-0.27.0-py2.py3-none-any.whl -> |
| 61 | + # google_cloud-0.27.0.data |
| 62 | + return '{}-{}.data'.format(self.distribution(), self.version()) |
| 63 | + |
57 | 64 | def metadata(self):
|
58 | 65 | # Extract the structured data from metadata.json in the WHL's dist-info
|
59 | 66 | # directory.
|
@@ -105,6 +112,25 @@ def expand(self, directory):
|
105 | 112 | with zipfile.ZipFile(self.path(), 'r') as whl:
|
106 | 113 | whl.extractall(directory)
|
107 | 114 |
|
| 115 | + # Find any lib directories, and move them to the top level. |
| 116 | + try: |
| 117 | + data_contents = os.listdir(self._data()) |
| 118 | + except: |
| 119 | + data_contents = [] |
| 120 | + |
| 121 | + # TODO: This is probably wrong. These have different targets, and probably both need to be |
| 122 | + # installed. |
| 123 | + if 'purelib' in data_contents: |
| 124 | + source = os.path.join(self._data(), 'purelib') |
| 125 | + elif 'platlib' in data_contents: |
| 126 | + source = os.path.join(self._data(), 'platlib') |
| 127 | + else: |
| 128 | + source = None |
| 129 | + |
| 130 | + if source: |
| 131 | + for f in os.listdir(source): |
| 132 | + shutil.move(os.path.join(source, f), directory) |
| 133 | + |
108 | 134 | # _parse_metadata parses METADATA files according to https://www.python.org/dev/peps/pep-0314/
|
109 | 135 | def _parse_metadata(self, content):
|
110 | 136 | # TODO: handle fields other than just name
|
|
0 commit comments