1
1
from distutils .command .install import install
2
2
from distutils .command .install_data import install_data
3
- from distutils .core import setup
3
+ from distutils .command . build_scripts import build_scripts
4
4
import hashlib
5
5
import os
6
6
import platform
9
9
import sys
10
10
import zipfile
11
11
12
+ try :
13
+ from setuptools import setup
14
+ except ImportError :
15
+ from distutils .core import setup
16
+
12
17
try :
13
18
from urllib import request
14
19
except ImportError :
@@ -47,7 +52,7 @@ def get_chromedriver_version():
47
52
.format (CHROMEDRIVER_INFO_URL ))
48
53
49
54
50
- class BuildScripts (install_data ):
55
+ class InstallChromeDriver (install_data ):
51
56
"""Downloads and unzips the requested chromedriver executable."""
52
57
53
58
def _download (self , zip_path , validate = False ):
@@ -98,14 +103,26 @@ def reporthoook(x, y, z):
98
103
99
104
def _unzip (self , zip_path ):
100
105
zf = zipfile .ZipFile (zip_path )
101
- print ("\t - extracting '{0}' to '{1}'."
102
- .format (zip_path , self .install_dir ))
103
- zf .extractall (self .install_dir )
106
+ out = tempfile .mkdtemp ('chromedriver_distr' )
107
+
108
+ print ("\t - extracting '{0}' to '{1}'." .format (zip_path , out ))
109
+ zf .extractall (out )
110
+
111
+ return (os .path .join (out , f ) for f in os .listdir (out ))
104
112
105
113
def _validate (self , zip_path ):
106
114
checksum = hashlib .md5 (open (zip_path , 'rb' ).read ()).hexdigest ()
107
115
return checksum in chromedriver_checksums
108
116
117
+ def initialize_options (self ):
118
+ super ().initialize_options ()
119
+ self .scripts_dir = None
120
+
121
+ def finalize_options (self ):
122
+ self .set_undefined_options ('build' , ('build_scripts' , 'scripts_dir' ))
123
+ self .data_files = []
124
+ super ().finalize_options ()
125
+
109
126
def run (self ):
110
127
global chromedriver_version , chromedriver_checksums
111
128
@@ -136,16 +153,10 @@ def run(self):
136
153
else :
137
154
self ._download (zip_path )
138
155
139
- self ._unzip (zip_path )
140
- self .data_files = [os .path .join (self .install_dir , script ) for script in
141
- os .listdir (self .install_dir )]
142
- print (self .data_files )
156
+ chromedriver_files = self ._unzip (zip_path )
157
+ self .data_files = [(self .scripts_dir , chromedriver_files )]
143
158
install_data .run (self )
144
159
145
- def finalize_options (self ):
146
- install_data .finalize_options (self )
147
- self .data_files = []
148
-
149
160
150
161
class Install (install ):
151
162
"""Used to get chromedriver version and checksums from install options"""
@@ -155,6 +166,8 @@ class Install(install):
155
166
# old setuptools version.
156
167
_svem = list (filter (lambda x : x [0 ] == 'single-version-externally-managed' ,
157
168
install .user_options ))
169
+ sub_commands = [* install .sub_commands ,
170
+ ('install_chrome_driver' , lambda self : True )]
158
171
159
172
if not _svem :
160
173
single_version_externally_managed = None
@@ -213,9 +226,8 @@ def run(self):
213
226
'Topic :: System :: Installation/Setup' ,
214
227
],
215
228
license = 'MIT' ,
216
- package_data = {'' : ['*.txt' , '*.rst' , 'chromedriver' ]},
217
- include_package_data = True ,
229
+ package_data = {'' : ['*.txt' , '*.rst' ]},
218
230
# If packages is empty, contents of ./build/lib will not be copied!
219
231
packages = ['chromedriver_installer' ],
220
- cmdclass = dict (install_data = BuildScripts , install = Install )
221
- )
232
+ cmdclass = dict (install_chrome_driver = InstallChromeDriver , install = Install )
233
+ )
0 commit comments