-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.py
36 lines (25 loc) · 845 Bytes
/
mod.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
"""Module runner
A shortcut to run a module by referencing its file (for leveraging
autocomplete). For example,
python mod.py parent\\dir\\file.py [args]
becomes
python -m parent.dir.file [args]
"""
__author__ = "Omar Othman <[email protected]>"
import subprocess
import sys
def main():
if len(sys.argv) == 1:
print("Quickly run a module by referencing the python file. For example,")
print(" python mod.py parent\\dir\\file.py [args]")
print("becomes")
print(" python -m parent.dir.file [args]")
sys.exit(0)
module = sys.argv[1]
# remove ".py"
module = module[:-3]
module = module.replace("\\", ".")
args = sys.argv[2:] if len(sys.argv) > 2 else []
subprocess.run(["python", "-m", module, *args], check=False)
if __name__ == "__main__":
main()