@@ -64,43 +64,6 @@ def remove_directory(self, path: str):
64
64
except OSError :
65
65
self .to_be_removed .append (path )
66
66
67
- def copy_files (self , package : Package , targetdir : str , srcdir : str , dstdir : str , create_bat_files : bool = False ):
68
- """Copy files from srcdir to dstdir within the target distribution."""
69
- srcdir = str (Path (targetdir ) / srcdir )
70
- if not Path (srcdir ).is_dir ():
71
- return
72
- offset = len (srcdir ) + len (os .pathsep )
73
- for dirpath , dirnames , filenames in os .walk (srcdir ):
74
- for dname in dirnames :
75
- t_dname = str (Path (dirpath ) / dname )[offset :]
76
- src = str (Path (srcdir ) / t_dname )
77
- dst = str (Path (dstdir ) / t_dname )
78
- if self .verbose :
79
- print (f"mkdir: { dst } " )
80
- full_dst = str (Path (self .target ) / dst )
81
- if not Path (full_dst ).exists ():
82
- os .mkdir (full_dst )
83
- package .files .append (dst )
84
- for fname in filenames :
85
- t_fname = str (Path (dirpath ) / fname )[offset :]
86
- src = str (Path (srcdir ) / t_fname )
87
- dst = fname if dirpath .endswith ("_system32" ) else str (Path (dstdir ) / t_fname )
88
- if self .verbose :
89
- print (f"file: { dst } " )
90
- full_dst = str (Path (self .target ) / dst )
91
- shutil .move (src , full_dst )
92
- package .files .append (dst )
93
- name , ext = Path (dst ).stem , Path (dst ).suffix
94
- if create_bat_files and ext in ("" , ".py" ):
95
- dst = name + ".bat"
96
- if self .verbose :
97
- print (f"file: { dst } " )
98
- full_dst = str (Path (self .target ) / dst )
99
- fd = open (full_dst , "w" )
100
- fd .write (f"""@echo off\n python "%~dpn0{ ext } " %*""" )
101
- fd .close ()
102
- package .files .append (dst )
103
-
104
67
def create_file (self , package , name , dstdir , contents ):
105
68
"""Generate data file -- path is relative to distribution root dir"""
106
69
dst = str (Path (dstdir ) / name )
@@ -157,8 +120,8 @@ def install(self, package: Package, install_options: list[str] = None): # Type h
157
120
# minimal post-install actions
158
121
self .patch_standard_packages (package .name )
159
122
160
- def do_pip_action (self , actions = None , install_options = None ):
161
- """Do pip action in a distribution"""
123
+ def do_pip_action (self , actions : list [ str ] = None , install_options : list [ str ] = None ):
124
+ """Execute pip action in the distribution. """
162
125
my_list = install_options or []
163
126
my_actions = actions or []
164
127
executing = str (Path (self .target ).parent / "scripts" / "env.bat" )
@@ -169,10 +132,12 @@ def do_pip_action(self, actions=None, install_options=None):
169
132
complement = ["-m" , "pip" ]
170
133
try :
171
134
fname = utils .do_script (this_script = None , python_exe = executing , verbose = self .verbose , install_options = complement + my_actions + my_list )
172
- except RuntimeError :
135
+ except RuntimeError as e :
173
136
if not self .verbose :
174
137
print ("Failed!" )
175
138
raise
139
+ else :
140
+ print (f"Pip action failed with error: { e } " ) # Print error if verbose
176
141
177
142
def patch_standard_packages (self , package_name = "" , to_movable = True ):
178
143
"""patch Winpython packages in need"""
@@ -256,7 +221,6 @@ def create_pybat(self, names="", contents=r"""@echo off
256
221
):
257
222
with open (scriptpy / (name + ".bat" ), "w" ) as fd :
258
223
fd .write (contents )
259
- fd .close ()
260
224
261
225
def handle_specific_packages (self , package ):
262
226
"""Packages requiring additional configuration"""
@@ -302,7 +266,7 @@ def _print_done(self):
302
266
def uninstall (self , package ):
303
267
"""Uninstall package from distribution"""
304
268
self ._print (package , "Uninstalling" )
305
- if not package .name = = "pip" :
269
+ if package .name ! = "pip" :
306
270
# trick to get true target (if not current)
307
271
this_exec = utils .get_python_executable (self .target ) # PyPy !
308
272
subprocess .call ([this_exec , "-m" , "pip" , "uninstall" , package .name , "-y" ], cwd = self .target )
@@ -327,23 +291,6 @@ def install_bdist_direct(self, package, install_options=None):
327
291
self ._print_done ()
328
292
329
293
330
- def install_script (self , script : str , install_options : list [str ] = None ): # Type hint install_options
331
- """Install a script using pip."""
332
- try :
333
- fname = utils .do_script (
334
- script ,
335
- python_exe = utils .get_python_executable (self .target ), # PyPy3 !
336
- verbose = self .verbose ,
337
- install_options = install_options ,
338
- )
339
- except RuntimeError as e : # Catch specific RuntimeError
340
- if not self .verbose :
341
- print ("Failed!" )
342
- raise # Re-raise if not verbose
343
- else :
344
- print (f"Script installation failed: { e } " ) # Print error if verbose
345
-
346
-
347
294
def main (test = False ):
348
295
if test :
349
296
sbdir = str (Path (__file__ ).parents [0 ].parent .parent .parent / "sandbox" )
0 commit comments