@@ -213,7 +213,6 @@ def patch_shebang_line(fname, pad=b" ", to_movable=True, targetdir=""):
213
213
"""Remove absolute path to python.exe in shebang lines in binary files, or re-add it."""
214
214
target_dir = targetdir if to_movable else os .path .abspath (os .path .join (os .path .dirname (fname ), r".." )) + "\\ "
215
215
executable = sys .executable
216
-
217
216
shebang_line = re .compile (rb"""(#!.*pythonw?\.exe)"?""" ) # Python3+
218
217
if "pypy3" in sys .executable :
219
218
shebang_line = re .compile (rb"""(#!.*pypy3w?\.exe)"?""" ) # Pypy3+
@@ -239,12 +238,9 @@ def patch_shebang_line(fname, pad=b" ", to_movable=True, targetdir=""):
239
238
def patch_shebang_line_py (fname , to_movable = True , targetdir = "" ):
240
239
"""Changes shebang line in '.py' file to relative or absolue path"""
241
240
import fileinput
242
- if to_movable :
243
- exec_path = r'#!.\python.exe'
244
- if 'pypy3' in sys .executable : # PyPy !
245
- exec_path = r'#!.\pypy3.exe'
246
- else :
247
- exec_path = '#!' + sys .executable
241
+ exec_path = r'#!.\python.exe' if to_movable else '#!' + sys .executable
242
+ if 'pypy3' in sys .executable :
243
+ exec_path = r'#!.\pypy3.exe' if to_movable else exec_path
248
244
for line in fileinput .input (fname , inplace = True ):
249
245
if re .match (r'^#\!.*python\.exe$' , line ) or re .match (r'^#\!.*pypy3\.exe$' , line ):
250
246
print (exec_path )
@@ -253,18 +249,16 @@ def patch_shebang_line_py(fname, to_movable=True, targetdir=""):
253
249
254
250
def guess_encoding (csv_file ):
255
251
"""guess the encoding of the given file"""
256
- # UTF_8_BOM = "\xEF\xBB\xBF"
257
252
with open (csv_file , "rb" ) as f :
258
253
data = f .read (5 )
259
254
if data .startswith (b"\xEF \xBB \xBF " ): # UTF-8 with a "BOM" (normally no BOM in utf-8)
260
255
return ["utf-8-sig" ]
261
- else : # in Windows, guessing utf-8 doesn't work, so we have to try
262
- try :
263
- with open (csv_file , encoding = "utf-8" ) as f :
264
- preview = f .read (222222 )
265
- return ["utf-8" ]
266
- except :
267
- return [locale .getdefaultlocale ()[1 ], "utf-8" ]
256
+ try :
257
+ with open (csv_file , encoding = "utf-8" ) as f :
258
+ preview = f .read (222222 )
259
+ return ["utf-8" ]
260
+ except :
261
+ return [locale .getdefaultlocale ()[1 ], "utf-8" ]
268
262
269
263
def replace_in_file (filepath : Path , replacements : list [tuple [str , str ]], filedest : Path = None , verbose = False ):
270
264
"""
@@ -290,9 +284,9 @@ def replace_in_file(filepath: Path, replacements: list[tuple[str, str]], filedes
290
284
def patch_sourcefile (fname , in_text , out_text , silent_mode = False ):
291
285
"""Replace a string in a source file."""
292
286
if not silent_mode :
293
- print (f"patching { fname } from { in_text } to { out_text } " )
294
- if Path (fname ).is_file () and not in_text = = out_text :
295
- replace_in_file (Path (fname ), [(in_text , out_text )])
287
+ print (f"patching { fname } from { in_text } to { out_text } " )
288
+ if Path (fname ).is_file () and in_text ! = out_text :
289
+ replace_in_file (Path (fname ), [(in_text , out_text )])
296
290
297
291
def _create_temp_dir ():
298
292
"""Create a temporary directory and remove it at exit"""
@@ -324,7 +318,7 @@ def get_source_package_infos(fname):
324
318
def buildflit_wininst (root , python_exe = None , copy_to = None , verbose = False ):
325
319
"""Build Wheel from Python package located in *root* with flit."""
326
320
python_exe = python_exe or sys .executable
327
- cmd = [python_exe , '-m' , 'flit' , 'build' ]
321
+ cmd = [python_exe , '-m' , 'flit' , 'build' ]
328
322
if verbose :
329
323
subprocess .call (cmd , cwd = root )
330
324
else :
@@ -362,7 +356,7 @@ def direct_pip_install(fname, python_exe=None, verbose=False, install_options=No
362
356
python_exe = python_exe or sys .executable
363
357
myroot = str (Path (python_exe ).parent )
364
358
365
- cmd = [python_exe , "-m" , "pip" , "install" ] + (install_options or []) + [fname ]
359
+ cmd = [python_exe , "-m" , "pip" , "install" ] + (install_options or []) + [fname ]
366
360
if not verbose :
367
361
process = subprocess .Popen (cmd , cwd = myroot , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
368
362
stdout , stderr = process .communicate ()
@@ -416,7 +410,7 @@ def get_package_metadata(database, name):
416
410
db = cp .ConfigParser ()
417
411
filepath = Path (database ) if Path (database ).is_absolute () else Path (DATA_PATH ) / database
418
412
db .read_file (open (str (filepath ), encoding = guess_encoding (filepath )[0 ]))
419
-
413
+
420
414
my_metadata = {
421
415
"description" : "" ,
422
416
"url" : f"https://pypi.org/project/{ name } " ,
0 commit comments