29
29
30
30
def get_python_executable (path = None ):
31
31
"""Return the path to the Python executable."""
32
- python_path = sys . executable if path is None else path
33
- base_dir = Path ( python_path ). parent if not Path ( python_path ) .is_dir () else Path ( python_path )
32
+ python_path = Path ( path ) if path else Path ( sys . executable )
33
+ base_dir = python_path if python_path .is_dir () else python_path . parent
34
34
python_exe = base_dir / 'python.exe'
35
35
pypy_exe = base_dir / 'pypy3.exe' # For PyPy
36
36
return str (python_exe if python_exe .is_file () else pypy_exe )
37
37
38
38
def get_site_packages_path (path = None ):
39
39
"""Return the path to the Python site-packages directory."""
40
- python_path = sys . executable if path is None else path
41
- base_dir = Path ( python_path ). parent if not Path ( python_path ) .is_dir () else Path ( python_path )
40
+ python_path = Path ( path ) if path else Path ( sys . executable )
41
+ base_dir = python_path if python_path .is_dir () else python_path . parent
42
42
site_packages = base_dir / 'Lib' / 'site-packages'
43
43
pypy_site_packages = base_dir / 'site-packages' # For PyPy
44
44
return str (pypy_site_packages if pypy_site_packages .is_dir () else site_packages )
@@ -322,40 +322,33 @@ def buildflit_wininst(root, python_exe=None, copy_to=None, verbose=False):
322
322
if verbose :
323
323
subprocess .call (cmd , cwd = root )
324
324
else :
325
- process = subprocess .Popen (cmd , cwd = root , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
326
- process .communicate ()
327
- process .stdout .close ()
328
- process .stderr .close ()
329
- distdir = str (Path (root ) / 'dist' )
330
- if not Path (distdir ).is_dir ():
325
+ subprocess .Popen (cmd , cwd = root , stdout = subprocess .PIPE , stderr = subprocess .PIPE ).communicate ()
326
+ distdir = Path (root ) / 'dist'
327
+ if not distdir .is_dir ():
331
328
raise RuntimeError (
332
329
"Build failed: see package README file for further details regarding installation requirements.\n \n "
333
330
"For more concrete debugging infos, please try to build the package from the command line:\n "
334
331
"1. Open a WinPython command prompt\n "
335
332
"2. Change working directory to the appropriate folder\n "
336
- "3. Type `python -m filt build`"
333
+ "3. Type `python -m flit build`"
337
334
)
338
-
339
335
for distname in os .listdir (distdir ):
340
336
if re .match (SOURCE_PATTERN , distname ) or re .match (WHEELBIN_PATTERN , distname ):
341
337
break
342
338
else :
343
339
raise RuntimeError (f"Build failed: not a pure Python package? { distdir } " )
344
340
345
- src_fname = str ( Path ( distdir ) / distname )
341
+ src_fname = distdir / distname
346
342
if copy_to :
347
- dst_fname = str ( Path (copy_to ) / distname )
343
+ dst_fname = Path (copy_to ) / distname
348
344
shutil .move (src_fname , dst_fname )
349
345
if verbose :
350
346
print (f"Move: { src_fname } --> { dst_fname } " )
351
- return dst_fname
352
- return src_fname
353
347
354
348
def direct_pip_install (fname , python_exe = None , verbose = False , install_options = None ):
355
349
"""Direct install via python -m pip !"""
356
350
python_exe = python_exe or sys .executable
357
- myroot = str (Path (python_exe ).parent )
358
-
351
+ myroot = Path (python_exe ).parent
359
352
cmd = [python_exe , "-m" , "pip" , "install" ] + (install_options or []) + [fname ]
360
353
if not verbose :
361
354
process = subprocess .Popen (cmd , cwd = myroot , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
@@ -374,15 +367,12 @@ def direct_pip_install(fname, python_exe=None, verbose=False, install_options=No
374
367
def do_script (this_script , python_exe = None , copy_to = None , verbose = False , install_options = None ):
375
368
"""Execute a script (get-pip typically)."""
376
369
python_exe = python_exe or sys .executable
377
- myroot = os . path . dirname (python_exe )
370
+ myroot = Path (python_exe ). parent
378
371
# cmd = [python_exe, myroot + r'\Scripts\pip-script.py', 'install']
379
372
cmd = [python_exe ] + (install_options or []) + ([this_script ] if this_script else [])
380
373
print ("Executing " , cmd )
381
374
if not verbose :
382
- process = subprocess .Popen (cmd , cwd = myroot , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
383
- process .communicate ()
384
- process .stdout .close ()
385
- process .stderr .close ()
375
+ subprocess .Popen (cmd , cwd = myroot , stdout = subprocess .PIPE , stderr = subprocess .PIPE ).communicate ()
386
376
else :
387
377
subprocess .call (cmd , cwd = myroot )
388
378
print ("Executed " , cmd )
@@ -406,9 +396,9 @@ def normalize(this):
406
396
407
397
def get_package_metadata (database , name ):
408
398
"""Extract infos (description, url) from the local database."""
409
- DATA_PATH = str ( Path (sys .modules ['winpython' ].__file__ ).parent / 'data' )
399
+ DATA_PATH = Path (sys .modules ['winpython' ].__file__ ).parent / 'data'
410
400
db = cp .ConfigParser ()
411
- filepath = Path (database ) if Path (database ).is_absolute () else Path ( DATA_PATH ) / database
401
+ filepath = Path (database ) if Path (database ).is_absolute () else DATA_PATH / database
412
402
db .read_file (open (str (filepath ), encoding = guess_encoding (filepath )[0 ]))
413
403
414
404
my_metadata = {
0 commit comments