77# (see winpython/__init__.py for details)
88
99import os
10- from pathlib import Path
11- import shutil
1210import re
1311import sys
12+ import shutil
1413import subprocess
1514import json
15+ from pathlib import Path
1616from argparse import ArgumentParser , RawTextHelpFormatter
17-
18- # Local imports
1917from winpython import utils , piptree
2018
2119# Workaround for installing PyVISA on Windows from source:
@@ -66,34 +64,26 @@ def remove_directory(self, path: str):
6664
6765 def create_file (self , package , name , dstdir , contents ):
6866 """Generate data file -- path is relative to distribution root dir"""
69- dst = str ( Path (dstdir ) / name )
67+ dst = Path (dstdir ) / name
7068 if self .verbose :
7169 print (f"create: { dst } " )
72- full_dst = str ( Path (self .target ) / dst )
70+ full_dst = Path (self .target ) / dst
7371 with open (full_dst , "w" ) as fd :
7472 fd .write (contents )
75- package .files .append (dst )
73+ package .files .append (str ( dst ) )
7674
7775 def get_installed_packages (self , update : bool = False ) -> list [Package ]:
7876 """Return installed packages."""
7977
8078 # Include package installed via pip (not via WPPM)
81- wppm = []
8279 if str (Path (sys .executable ).parent ) == self .target :
8380 self .pip = piptree .PipData ()
8481 else :
8582 self .pip = piptree .PipData (utils .get_python_executable (self .target ))
8683 pip_list = self .pip .pip_list ()
8784
88- # create pip package list
89- wppm = [
90- Package (
91- f"{ i [0 ].replace ('-' , '_' ).lower ()} -{ i [1 ]} -py3-none-any.whl" , #faking wheel
92- suggested_summary = self .pip .summary (i [0 ]) if self .pip else None
93- )
94- for i in pip_list
95- ]
96- return sorted (wppm , key = lambda tup : tup .name .lower ())
85+ # return a list of package objects
86+ return [Package (f"{ utils .normalize (i [0 ])} -{ i [1 ]} -py3-none-any.whl" ) for i in pip_list ]
9787
9888 def find_package (self , name : str ) -> Package | None :
9989 """Find installed package by name."""
@@ -103,16 +93,13 @@ def find_package(self, name: str) -> Package | None:
10393
10494 def patch_all_shebang (self , to_movable : bool = True , max_exe_size : int = 999999 , targetdir : str = "" ):
10595 """Make all python launchers relative."""
106- import glob
107-
108- for ffname in glob .glob (r"%s\Scripts\*.exe" % self .target ):
109- size = os .path .getsize (ffname )
110- if size <= max_exe_size :
96+ for ffname in Path (self .target ).glob ("Scripts/*.exe" ):
97+ if ffname .stat ().st_size <= max_exe_size :
11198 utils .patch_shebang_line (ffname , to_movable = to_movable , targetdir = targetdir )
112- for ffname in glob . glob (r"%s\ Scripts\ *.py" % self . target ):
99+ for ffname in Path ( self . target ). glob (" Scripts/ *.py" ):
113100 utils .patch_shebang_line_py (ffname , to_movable = to_movable , targetdir = targetdir )
114101
115- def install (self , package : Package , install_options : list [str ] = None ): # Type hint install_options
102+ def install (self , package : Package , install_options : list [str ] = None ):
116103 """Install package in distribution."""
117104 if package .fname .endswith ((".whl" , ".tar.gz" , ".zip" )): # Check extension with tuple
118105 self .install_bdist_direct (package , install_options = install_options )
@@ -158,12 +145,10 @@ def patch_standard_packages(self, package_name="", to_movable=True):
158145 # ensure pip will create movable launchers
159146 # sheb_mov1 = classic way up to WinPython 2016-01
160147 # sheb_mov2 = tried way, but doesn't work for pip (at least)
148+ the_place = Path (self .target ) / "lib" / "site-packages" / "pip" / "_vendor" / "distlib" / "scripts.py"
161149 sheb_fix = " executable = get_executable()"
162150 sheb_mov1 = " executable = os.path.join(os.path.basename(get_executable()))"
163151 sheb_mov2 = " executable = os.path.join('..',os.path.basename(get_executable()))"
164-
165- the_place = Path (self .target ) / "lib" / "site-packages" / "pip" / "_vendor" / "distlib" / "scripts.py"
166- print (the_place )
167152 if to_movable :
168153 utils .patch_sourcefile (the_place , sheb_fix , sheb_mov1 )
169154 utils .patch_sourcefile (the_place , sheb_mov2 , sheb_mov1 )
@@ -176,7 +161,7 @@ def patch_standard_packages(self, package_name="", to_movable=True):
176161 if package_name .lower () in ("" , "spyder" ):
177162 # spyder don't goes on internet without I ask
178163 utils .patch_sourcefile (
179- Path (self .target ) / "lib" / "site-packages" / "spyder" / "config" / "main.py" ,
164+ Path (self .target ) / "lib" / "site-packages" / "spyder" / "config" / "main.py" ,
180165 "'check_updates_on_startup': True," ,
181166 "'check_updates_on_startup': False," ,
182167 )
@@ -250,7 +235,7 @@ def install_bdist_direct(self, package, install_options=None):
250235
251236def main (test = False ):
252237 if test :
253- sbdir = Path (__file__ ).parents [0 ]. parent . parent . parent / "sandbox"
238+ sbdir = Path (__file__ ).parents [3 ] / "sandbox"
254239 tmpdir = sbdir / "tobedeleted"
255240 fname = sbdir / "VTK-5.10.0-Qt-4.7.4.win32-py2.7.exe"
256241 print (Package (str (fname )))
0 commit comments