230 wname = dname + "/" + wfile |
230 wname = dname + "/" + wfile |
231 |
231 |
232 return wname |
232 return wname |
233 |
233 |
234 |
234 |
235 def createPyWrapper(pydir, wfile, isGuiScript=True): |
235 def createPyWrapper(pydir, wfile, marker, isGuiScript=True): |
236 """ |
236 """ |
237 Create an executable wrapper for a Python script. |
237 Create an executable wrapper for a Python script. |
238 |
238 |
239 @param pydir the name of the directory where the Python script will |
239 @param pydir the name of the directory where the Python script will |
240 eventually be installed |
240 eventually be installed (string) |
241 @param wfile the basename of the wrapper |
241 @param wfile the basename of the wrapper (string) |
|
242 @param marker marker for the Python variant (string) |
242 @param isGuiScript flag indicating a wrapper script for a GUI |
243 @param isGuiScript flag indicating a wrapper script for a GUI |
243 application (boolean) |
244 application (boolean) |
244 @return the platform specific name of the wrapper |
245 @return the platform specific name of the wrapper (string) |
245 """ |
246 """ |
246 # all kinds of Windows systems |
247 # all kinds of Windows systems |
247 if sys.platform.startswith("win"): |
248 if sys.platform.startswith("win"): |
248 wname = wfile + ".bat" |
249 wname = wfile + marker + ".bat" |
249 if isGuiScript: |
250 if isGuiScript: |
250 wrapper = \ |
251 wrapper = \ |
251 '''@echo off\n''' \ |
252 '''@echo off\n''' \ |
252 '''start "" "{2}\\pythonw.exe"''' \ |
253 '''start "" "{2}\\pythonw.exe"''' \ |
253 ''' "{0}\\{1}.pyw"''' \ |
254 ''' "{0}\\{1}.pyw"''' \ |
259 ''' %1 %2 %3 %4 %5 %6 %7 %8 %9\n'''.format( |
260 ''' %1 %2 %3 %4 %5 %6 %7 %8 %9\n'''.format( |
260 sys.exec_prefix, pydir, wfile) |
261 sys.exec_prefix, pydir, wfile) |
261 |
262 |
262 # Mac OS X |
263 # Mac OS X |
263 elif sys.platform == "darwin": |
264 elif sys.platform == "darwin": |
264 # TODO: change this to respect the Python version install is executed with |
265 major = sys.version_info.major |
265 pyexec = "{0}/bin/pythonw3".format(sys.exec_prefix) |
266 pyexec = "{0}/bin/pythonw{1}".format(sys.exec_prefix, major) |
266 if not os.path.exists(pyexec): |
267 if not os.path.exists(pyexec): |
267 pyexec = "{0}/bin/python3".format(sys.exec_prefix) |
268 pyexec = "{0}/bin/python{1}".format(sys.exec_prefix, major) |
268 wname = wfile |
269 wname = wfile + marker |
269 wrapper = ('''#!/bin/sh\n''' |
270 wrapper = ('''#!/bin/sh\n''' |
270 '''\n''' |
271 '''\n''' |
271 '''exec "{0}" "{1}/{2}.py" "$@"\n''' |
272 '''exec "{0}" "{1}/{2}.py" "$@"\n''' |
272 .format(pyexec, pydir, wfile)) |
273 .format(pyexec, pydir, wfile)) |
273 |
274 |
274 # *nix systems |
275 # *nix systems |
275 else: |
276 else: |
276 wname = wfile |
277 wname = wfile + marker |
277 wrapper = ('''#!/bin/sh\n''' |
278 wrapper = ('''#!/bin/sh\n''' |
278 '''\n''' |
279 '''\n''' |
279 '''exec "{0}" "{1}/{2}.py" "$@"\n''' |
280 '''exec "{0}" "{1}/{2}.py" "$@"\n''' |
280 .format(sys.executable, pydir, wfile)) |
281 .format(sys.executable, pydir, wfile)) |
281 |
282 |
365 if not os.path.exists(os.path.join(dirName, formName)): |
366 if not os.path.exists(os.path.join(dirName, formName)): |
366 os.remove(os.path.join(dirName, sourceName)) |
367 os.remove(os.path.join(dirName, sourceName)) |
367 if os.path.exists(os.path.join(dirName, sourceName + "c")): |
368 if os.path.exists(os.path.join(dirName, sourceName + "c")): |
368 os.remove(os.path.join(dirName, sourceName + "c")) |
369 os.remove(os.path.join(dirName, sourceName + "c")) |
369 |
370 |
370 # step 2: delete the __pycache__ directory |
371 # step 2: delete the __pycache__ directory and all *.pyc files |
371 if os.path.exists(os.path.join(dirName, "__pycache__")): |
372 if os.path.exists(os.path.join(dirName, "__pycache__")): |
372 shutil.rmtree(os.path.join(dirName, "__pycache__")) |
373 shutil.rmtree(os.path.join(dirName, "__pycache__")) |
|
374 for name in [f for f in dirListing if fnmatch.fnmatch(f, "*.pyc")]: |
|
375 os.remove(os.path.join(dirName, name)) |
373 |
376 |
374 # step 3: descent into subdirectories and delete them if empty |
377 # step 3: descent into subdirectories and delete them if empty |
375 for name in os.listdir(dirName): |
378 for name in os.listdir(dirName): |
376 name = os.path.join(dirName, name) |
379 name = os.path.join(dirName, name) |
377 if os.path.isdir(name): |
380 if os.path.isdir(name): |
530 if includePythonVariant: |
533 if includePythonVariant: |
531 marker = PythonMarkers[sys.version_info.major] |
534 marker = PythonMarkers[sys.version_info.major] |
532 else: |
535 else: |
533 marker = "" |
536 marker = "" |
534 wnames.append(createPyWrapper(cfg['ericDir'], |
537 wnames.append(createPyWrapper(cfg['ericDir'], |
535 "eric5_api" + marker, |
538 "eric5_api", marker, |
536 False)) |
539 False)) |
537 wnames.append(createPyWrapper(cfg['ericDir'], |
540 wnames.append(createPyWrapper(cfg['ericDir'], |
538 "eric5_compare" + marker)) |
541 "eric5_compare", marker)) |
539 wnames.append(createPyWrapper(cfg['ericDir'], |
542 wnames.append(createPyWrapper(cfg['ericDir'], |
540 "eric5_configure" + marker)) |
543 "eric5_configure", marker)) |
541 wnames.append(createPyWrapper(cfg['ericDir'], |
544 wnames.append(createPyWrapper(cfg['ericDir'], |
542 "eric5_diff" + marker)) |
545 "eric5_diff", marker)) |
543 wnames.append(createPyWrapper(cfg['ericDir'], |
546 wnames.append(createPyWrapper(cfg['ericDir'], |
544 "eric5_doc" + marker, |
547 "eric5_doc", marker, |
545 False)) |
548 False)) |
546 wnames.append(createPyWrapper(cfg['ericDir'], |
549 wnames.append(createPyWrapper(cfg['ericDir'], |
547 "eric5_editor" + marker)) |
550 "eric5_editor", marker)) |
548 wnames.append(createPyWrapper(cfg['ericDir'], |
551 wnames.append(createPyWrapper(cfg['ericDir'], |
549 "eric5_iconeditor" + marker)) |
552 "eric5_iconeditor", marker)) |
550 wnames.append(createPyWrapper(cfg['ericDir'], |
553 wnames.append(createPyWrapper(cfg['ericDir'], |
551 "eric5_plugininstall" + marker)) |
554 "eric5_plugininstall", marker)) |
552 wnames.append(createPyWrapper(cfg['ericDir'], |
555 wnames.append(createPyWrapper(cfg['ericDir'], |
553 "eric5_pluginrepository" + marker)) |
556 "eric5_pluginrepository", marker)) |
554 wnames.append(createPyWrapper(cfg['ericDir'], |
557 wnames.append(createPyWrapper(cfg['ericDir'], |
555 "eric5_pluginuninstall" + marker)) |
558 "eric5_pluginuninstall", marker)) |
556 wnames.append(createPyWrapper(cfg['ericDir'], |
559 wnames.append(createPyWrapper(cfg['ericDir'], |
557 "eric5_qregexp" + marker)) |
560 "eric5_qregexp", marker)) |
558 wnames.append(createPyWrapper(cfg['ericDir'], |
561 wnames.append(createPyWrapper(cfg['ericDir'], |
559 "eric5_qregularexpression" + marker)) |
562 "eric5_qregularexpression", marker)) |
560 wnames.append(createPyWrapper(cfg['ericDir'], |
563 wnames.append(createPyWrapper(cfg['ericDir'], |
561 "eric5_re" + marker)) |
564 "eric5_re", marker)) |
562 wnames.append(createPyWrapper(cfg['ericDir'], |
565 wnames.append(createPyWrapper(cfg['ericDir'], |
563 "eric5_snap" + marker)) |
566 "eric5_snap", marker)) |
564 wnames.append(createPyWrapper(cfg['ericDir'], |
567 wnames.append(createPyWrapper(cfg['ericDir'], |
565 "eric5_sqlbrowser" + marker)) |
568 "eric5_sqlbrowser", marker)) |
566 wnames.append(createPyWrapper(cfg['ericDir'], |
569 wnames.append(createPyWrapper(cfg['ericDir'], |
567 "eric5_tray" + marker)) |
570 "eric5_tray", marker)) |
568 wnames.append(createPyWrapper(cfg['ericDir'], |
571 wnames.append(createPyWrapper(cfg['ericDir'], |
569 "eric5_trpreviewer" + marker)) |
572 "eric5_trpreviewer", marker)) |
570 wnames.append(createPyWrapper(cfg['ericDir'], |
573 wnames.append(createPyWrapper(cfg['ericDir'], |
571 "eric5_uipreviewer" + marker)) |
574 "eric5_uipreviewer", marker)) |
572 wnames.append(createPyWrapper(cfg['ericDir'], |
575 wnames.append(createPyWrapper(cfg['ericDir'], |
573 "eric5_unittest" + marker)) |
576 "eric5_unittest", marker)) |
574 wnames.append(createPyWrapper(cfg['ericDir'], |
577 wnames.append(createPyWrapper(cfg['ericDir'], |
575 "eric5_webbrowser" + marker)) |
578 "eric5_webbrowser", marker)) |
576 wnames.append(createPyWrapper(cfg['ericDir'], |
579 wnames.append(createPyWrapper(cfg['ericDir'], |
577 "eric5" + marker)) |
580 "eric5", marker)) |
578 |
581 |
579 # set install prefix, if not None |
582 # set install prefix, if not None |
580 if distDir: |
583 if distDir: |
581 for key in list(cfg.keys()): |
584 for key in list(cfg.keys()): |
582 cfg[key] = os.path.normpath(distDir + os.sep + cfg[key]) |
585 cfg[key] = os.path.normpath(distDir + os.sep + cfg[key]) |