-
Notifications
You must be signed in to change notification settings - Fork 1
/
named_python.py
48 lines (40 loc) · 1.59 KB
/
named_python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import argparse
import os
import sys
from voussoirkit import betterhelp
from voussoirkit import pathclass
def namedpython_argparse(args):
this_python = pathclass.Path(sys.executable)
base = this_python.replace_extension('').basename.split('-', 1)[0]
name = args.name.strip()
extension = this_python.extension.with_dot
named_python = this_python.parent.with_child(f'{base}-{name}{extension}')
if named_python.exists:
return 0
os.link(this_python.absolute_path, named_python.absolute_path)
print(named_python.absolute_path)
return 0
def main(argv):
parser = argparse.ArgumentParser(
description='''
Because Python is interpreted, when you look at the task manager / process list
you'll see that every running python instance has the same name, python.exe.
This script helps you name the executables so they stand out.
For the time being this script doesn't automatically call your new exe, you
have to write a second command to actually run it. I tried using
subprocess.Popen to spawn the new python with the rest of argv but the behavior
was different on Linux and Windows and neither was really clean.
''',
)
parser.add_argument(
'name',
type=str,
help='''
If you invoke this script with python.exe, a hardlink python-{name}.exe
will be created. Also works with pythonw.
''',
)
parser.set_defaults(func=namedpython_argparse)
return betterhelp.go(parser, argv)
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))