-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy path__main__.dg
91 lines (75 loc) · 3.34 KB
/
__main__.dg
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import '/os'
import '/sys'
import '/runpy'
import '/importlib'
import '/dg'
import '/dg/core'
import '/dg/repl'
BUNDLE_TAG = 3177897669
USAGE = '''
python3 [options] -m dg -h
python3 [options] -m dg -b [tag [hexversion]]
python3 [options] -m dg [-c <command> | -m <module> | <file>] ...
VM options that make sense when used with dg:
-B don't save bytecode cache (i.e. `.pyc` and `.pyo` files);
-E ignore environment variables
-s don't add user site directory to sys.path
-S don't `import site` on startup
-u don't buffer standard output
-v trace import statements
-X implementation-specific options
Arguments:
-h show this message and exit
-b rebootstrap the compiler
tag cache tag of the target interpreter (e.g. `cpython-35`)
hexversion version of the target interpreter as 8 hex digits (e.g. `030500A0`)
-c command run a single command, then exit
-m module run a module (or a package's `__main__`) as a script
file run a script
... additional arguments accessible through `sys.argv`
Environment variables:
PYTHONSTARTUP a Python file executed on interactive startup
PYTHONSTARTUPMOD a name of the module to use instead of PYTHONSTARTUP
PYTHONPATH a `:`-separated list of directories to search for modules in
PYTHONPREFIX override the `--prefix` option of `configure`
...that have the same effect as options:
PYTHONDONTWRITEBYTECODE -B
PYTHONNOUSERSITE -s
PYTHONUNBUFFERED -u
PYTHONVERBOSE -v
'''
_arg = -> if
len sys.argv > 1 => sys.argv.pop 1
otherwise => exit $ 'error: {} requires an argument'.format mode
sys.argv.pop 0 # `-m`
sys.argv = mode, *_ = sys.argv or ['-',]
rebuild = tag version verbose ->
this = core.load dg.PY_TAG dg.BUNDLE_DIR
this = list $ core.build this tag version BUNDLE_TAG
verbose => print '[INFO] build 1 (bootstrap) ok'
if
tag != dg.PY_TAG =>
verbose => print '[WARN] building for a different VM; self-testing impossible.'
core.save_compat this tag dg.BUNDLE_DIR
otherwise =>
this = list $ core.build this tag version BUNDLE_TAG
this = list $ core.build this tag version BUNDLE_TAG
verbose => print '[INFO] builds 2 & 3 (test) ok'
core.save this tag dg.BUNDLE_DIR
if mode != '-b' and getattr dg 'BUNDLE_TAG' None != BUNDLE_TAG =>
except err => rebuild dg.PY_TAG dg.PY_VERSION verbose: False
err :: Exception => print '[WARN] dg bundle outdated, and rebuild failed; try python -m dg -b' file: sys.stderr
if mode == '-h' => print USAGE
mode == '-b' =>
tag, version = if
len sys.argv > 2 => sys.argv !! 1, int (sys.argv !! 2) 16
len sys.argv > 1 => sys.argv !! 1, dg.PY_VERSION
otherwise => dg.PY_TAG, dg.PY_VERSION
rebuild tag version verbose: True
mode == '-m' => runpy.run_module _arg! (dict __builtins__: dg.BUILTINS) '__main__' True
mode == '-c' => repl.runcode $ dg.compile _arg! '<command>'
mode != '-' => repl.runfile $ open encoding: 'utf-8' $ head sys.argv
otherwise => repl.runfile sys.stdin where if
sys.flags.ignore_environment => # `python -E`
(fn = os.environ.get 'PYTHONSTARTUPMOD') => importlib.import_module fn
(fn = os.environ.get 'PYTHONSTARTUP') => runpy.run_path fn {} '__main__'