7
7
# (see winpython/__init__.py for details)
8
8
9
9
import os
10
- from pathlib import Path
11
- import shutil
12
10
import re
13
11
import sys
12
+ import shutil
14
13
import subprocess
15
14
import json
15
+ from pathlib import Path
16
16
from argparse import ArgumentParser , RawTextHelpFormatter
17
-
18
- # Local imports
19
17
from winpython import utils , piptree
20
18
21
19
# Workaround for installing PyVISA on Windows from source:
@@ -66,34 +64,26 @@ def remove_directory(self, path: str):
66
64
67
65
def create_file (self , package , name , dstdir , contents ):
68
66
"""Generate data file -- path is relative to distribution root dir"""
69
- dst = str ( Path (dstdir ) / name )
67
+ dst = Path (dstdir ) / name
70
68
if self .verbose :
71
69
print (f"create: { dst } " )
72
- full_dst = str ( Path (self .target ) / dst )
70
+ full_dst = Path (self .target ) / dst
73
71
with open (full_dst , "w" ) as fd :
74
72
fd .write (contents )
75
- package .files .append (dst )
73
+ package .files .append (str ( dst ) )
76
74
77
75
def get_installed_packages (self , update : bool = False ) -> list [Package ]:
78
76
"""Return installed packages."""
79
77
80
78
# Include package installed via pip (not via WPPM)
81
- wppm = []
82
79
if str (Path (sys .executable ).parent ) == self .target :
83
80
self .pip = piptree .PipData ()
84
81
else :
85
82
self .pip = piptree .PipData (utils .get_python_executable (self .target ))
86
83
pip_list = self .pip .pip_list ()
87
84
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 ]
97
87
98
88
def find_package (self , name : str ) -> Package | None :
99
89
"""Find installed package by name."""
@@ -103,16 +93,13 @@ def find_package(self, name: str) -> Package | None:
103
93
104
94
def patch_all_shebang (self , to_movable : bool = True , max_exe_size : int = 999999 , targetdir : str = "" ):
105
95
"""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 :
111
98
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" ):
113
100
utils .patch_shebang_line_py (ffname , to_movable = to_movable , targetdir = targetdir )
114
101
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 ):
116
103
"""Install package in distribution."""
117
104
if package .fname .endswith ((".whl" , ".tar.gz" , ".zip" )): # Check extension with tuple
118
105
self .install_bdist_direct (package , install_options = install_options )
@@ -158,12 +145,10 @@ def patch_standard_packages(self, package_name="", to_movable=True):
158
145
# ensure pip will create movable launchers
159
146
# sheb_mov1 = classic way up to WinPython 2016-01
160
147
# 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"
161
149
sheb_fix = " executable = get_executable()"
162
150
sheb_mov1 = " executable = os.path.join(os.path.basename(get_executable()))"
163
151
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 )
167
152
if to_movable :
168
153
utils .patch_sourcefile (the_place , sheb_fix , sheb_mov1 )
169
154
utils .patch_sourcefile (the_place , sheb_mov2 , sheb_mov1 )
@@ -176,7 +161,7 @@ def patch_standard_packages(self, package_name="", to_movable=True):
176
161
if package_name .lower () in ("" , "spyder" ):
177
162
# spyder don't goes on internet without I ask
178
163
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" ,
180
165
"'check_updates_on_startup': True," ,
181
166
"'check_updates_on_startup': False," ,
182
167
)
@@ -250,7 +235,7 @@ def install_bdist_direct(self, package, install_options=None):
250
235
251
236
def main (test = False ):
252
237
if test :
253
- sbdir = Path (__file__ ).parents [0 ]. parent . parent . parent / "sandbox"
238
+ sbdir = Path (__file__ ).parents [3 ] / "sandbox"
254
239
tmpdir = sbdir / "tobedeleted"
255
240
fname = sbdir / "VTK-5.10.0-Qt-4.7.4.win32-py2.7.exe"
256
241
print (Package (str (fname )))
0 commit comments