@@ -131,38 +131,6 @@ def extract_infos(self):
131131 return
132132 raise NotImplementedError ("Not supported package type %s" % bname )
133133
134- def logpath (self , logdir ):
135- """Return full log path"""
136- return osp .join (logdir , osp .basename (self .fname + '.log' ))
137-
138- def save_log (self , logdir ):
139- """Save log (pickle)"""
140- header = ['# WPPM package installation log' ,
141- '# ' ,
142- '# Package: %s v%s' % (self .name , self .version ),
143- '' ]
144- open (self .logpath (logdir ), 'w' ).write ('\n ' .join (header + self .files ))
145-
146- def load_log (self , logdir ):
147- """Load log (pickle)"""
148- try :
149- data = open (self .logpath (logdir ), 'U' ).readlines ()
150- except (IOError , OSError ):
151- data = [] # it can be now ()
152- self .files = []
153- for line in data :
154- relpath = line .strip ()
155- if relpath .startswith ('#' ) or len (relpath ) == 0 :
156- continue
157- self .files .append (relpath )
158-
159- def remove_log (self , logdir ):
160- """Remove log (after uninstalling package)"""
161- try :
162- os .remove (self .logpath (logdir ))
163- except WindowsError :
164- pass
165-
166134
167135class WininstPackage (BasePackage ):
168136 def __init__ (self , fname , distribution ):
@@ -204,20 +172,16 @@ def uninstall(self):
204172
205173
206174class Distribution (object ):
207- # PyQt module is now like :PyQt4-...
208- NSIS_PACKAGES = ('PyQt4' , 'PyQwt' , 'PyQt5' ) # known NSIS packages
209175
210176 def __init__ (self , target = None , verbose = False , indent = False ):
211177 self .target = target
212178 self .verbose = verbose
213179 self .indent = indent
214- self .logdir = None
215180
216181 # if no target path given, take the current python interpreter one
217182 if self .target is None :
218183 self .target = os .path .dirname (sys .executable )
219184
220- self .init_log_dir ()
221185 self .to_be_removed = [] # list of directories to be removed later
222186
223187 self .version , self .architecture = utils .get_python_infos (target )
@@ -238,13 +202,6 @@ def remove_directory(self, path):
238202 except WindowsError :
239203 self .to_be_removed .append (path )
240204
241- def init_log_dir (self ):
242- """Init log path"""
243- path = osp .join (self .target , 'Logs' )
244- if not osp .exists (path ):
245- os .mkdir (path )
246- self .logdir = path
247-
248205 def copy_files (self , package , targetdir ,
249206 srcdir , dstdir , create_bat_files = False ):
250207 """Add copy task"""
@@ -299,20 +256,9 @@ def create_file(self, package, name, dstdir, contents):
299256
300257 def get_installed_packages (self ):
301258 """Return installed packages"""
302- # Packages installed with WPPM
303- wppm = [Package (logname [:- 4 ]) for logname in os .listdir (self .logdir )
304- if '.whl.log' not in logname ]
305- # Packages installed with distutils wininst
306- wininst = []
307- for name in os .listdir (self .target ):
308- if name .startswith ('Remove' ) and name .endswith ('.exe' ):
309- try :
310- pack = WininstPackage (name , self )
311- except IOError :
312- continue
313- if pack .name is not None and pack .version is not None :
314- wininst .append (pack )
259+
315260 # Include package installed via pip (not via WPPM)
261+ wppm = []
316262 try :
317263 if os .path .dirname (sys .executable ) == self .target :
318264 # direct way: we interrogate ourself, using official API
@@ -331,16 +277,14 @@ def get_installed_packages(self):
331277 pip_list = [line .split ("@+@" )[:2 ] for line in
332278 ("%s" % stdout )[start_at :].split ("+!+" )]
333279
280+ # there are only Packages installed with pip now
334281 # create pip package list
335- wppip = [Package ('%s-%s-py2.py3-none-any.whl' %
282+ wppm = [Package ('%s-%s-py2.py3-none-any.whl' %
336283 (i [0 ].replace ('-' , '_' ).lower (), i [1 ])) for i in pip_list ]
337- # pip package version is supposed better
338- already = set (b .name .replace ('-' , '_' ) for b in wppip + wininst )
339- wppm = wppip + [i for i in wppm
340- if i .name .replace ('-' , '_' ).lower () not in already ]
284+
341285 except :
342286 pass
343- return sorted (wppm + wininst , key = lambda tup : tup .name .lower ())
287+ return sorted (wppm , key = lambda tup : tup .name .lower ())
344288
345289 def find_package (self , name ):
346290 """Find installed package"""
@@ -375,25 +319,14 @@ def patch_all_shebang(self, to_movable=True, max_exe_size=999999, targetdir=""):
375319 def install (self , package , install_options = None ):
376320 """Install package in distribution"""
377321 assert package .is_compatible_with (self )
378- tmp_fname = None
379322
380323 # wheel addition
381324 if package .fname .endswith (('.whl' , '.tar.gz' , '.zip' )):
382325 self .install_bdist_direct (package , install_options = install_options )
383326
384- bname = osp .basename (package .fname )
385- if bname .endswith ('.exe' ):
386- if re .match (r'(' + ('|' .join (self .NSIS_PACKAGES )) + r')-' , bname ):
387- self .install_nsis_package (package )
388- else :
389- self .install_bdist_wininst (package )
390327 self .handle_specific_packages (package )
391328 # minimal post-install actions
392329 self .patch_standard_packages (package .name )
393- if not package .fname .endswith (('.whl' , '.tar.gz' , '.zip' )):
394- package .save_log (self .logdir )
395- if tmp_fname is not None :
396- os .remove (tmp_fname )
397330
398331 def do_pip_action (self , actions = None , install_options = None ):
399332 """Do pip action in a distribution"""
@@ -559,51 +492,13 @@ def _print_done(self):
559492 def uninstall (self , package ):
560493 """Uninstall package from distribution"""
561494 self ._print (package , "Uninstalling" )
562- if isinstance (package , WininstPackage ):
563- package .uninstall ()
564- package .remove_log (self .logdir )
565- elif not package .name == 'pip' :
495+ if not package .name == 'pip' :
566496 # trick to get true target (if not current)
567- this_executable_path = os . path . dirname ( self .logdir )
497+ this_executable_path = self .target
568498 subprocess .call ([this_executable_path + r'\python.exe' ,
569499 '-m' , 'pip' , 'uninstall' , package .name , '-y' ],
570500 cwd = this_executable_path )
571- # legacy, if some package installed by old non-pip means
572- package .load_log (self .logdir )
573- for fname in reversed (package .files ):
574- path = osp .join (self .target , fname )
575- if osp .isfile (path ):
576- if self .verbose :
577- print ("remove: %s" % fname )
578- os .remove (path )
579- if fname .endswith ('.py' ):
580- for suffix in ('c' , 'o' ):
581- if osp .exists (path + suffix ):
582- if self .verbose :
583- print ("remove: %s" % (fname + suffix ))
584- os .remove (path + suffix )
585- elif osp .isdir (path ):
586- if self .verbose :
587- print ("rmdir: %s" % fname )
588- pycache = osp .join (path , '__pycache__' )
589- if osp .exists (pycache ):
590- try :
591- shutil .rmtree (pycache , onerror = utils .onerror )
592- if self .verbose :
593- print ("rmtree: %s" % pycache )
594- except WindowsError :
595- print ("Directory %s could not be removed"
596- % pycache , file = sys .stderr )
597- try :
598- os .rmdir (path )
599- except OSError :
600- if self .verbose :
601- print ("unable to remove directory: %s" % fname ,
602- file = sys .stderr )
603- else :
604- if self .verbose :
605- print ("file not found: %s" % fname , file = sys .stderr )
606- package .remove_log (self .logdir )
501+ # no more legacy, no package are installed by old non-pip means
607502 self ._print_done ()
608503
609504 def install_bdist_wininst (self , package ):
0 commit comments