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