OILS / bin / oil.py View on Github | oilshell.org

64 lines, 28 significant
1#!/usr/bin/env python2
2# Copyright 2016 Andy Chu. All rights reserved.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8"""
9bin/oil.py - Python wrapper for oils_for_unix.py
10
11- Used to build the OVM tarball, which we might want to get rid of.
12 - This file should be called bin/oils_py.py, but that might break
13 the deployed oil.ovm, which we we might want to get rid of anyway.
14"""
15from __future__ import print_function
16
17import posix_ as posix
18import sys
19
20# Needed for oil.ovm app bundle build, since there is an function-local import
21# to break a circular build dep in frontend/consts.py.
22from _devbuild.gen import id_kind
23
24_ = id_kind
25
26from bin import oils_for_unix
27
28from typing import List
29
30
31# Called from Python-2.7.13/Modules/main.c.
32def _cpython_main_hook():
33 # type: () -> None
34 sys.exit(oils_for_unix.main(sys.argv))
35
36
37def main(argv):
38 # type: (List[str]) -> int
39 return oils_for_unix.main(sys.argv)
40
41
42if __name__ == '__main__':
43 pyann_out = posix.environ.get('PYANN_OUT')
44
45 if pyann_out:
46 from pyannotate_runtime import collect_types
47
48 collect_types.init_types_collection()
49 with collect_types.collect():
50 status = main(sys.argv)
51 collect_types.dump_stats(pyann_out)
52 sys.exit(status)
53
54 elif posix.environ.get('RESOLVE') == '1':
55 from opy import resolve
56 resolve.Walk(dict(sys.modules))
57
58 elif posix.environ.get('CALLGRAPH') == '1':
59 # NOTE: This could end up as opy.InferTypes(), opy.GenerateCode(), etc.
60 from opy import callgraph
61 callgraph.Walk(main, sys.modules)
62
63 else:
64 sys.exit(main(sys.argv))