Commit c0282565 authored by Kirill Smelkov's avatar Kirill Smelkov

gpython: Reorganize main a bit

Restructure code a bit to prepare it for the next patch.
Plain code movement.

/reviewed-on !5
parent 70c4c82f
...@@ -166,14 +166,10 @@ def _version_info_str(vi): ...@@ -166,14 +166,10 @@ def _version_info_str(vi):
def main(): def main():
# set UTF-8 as default encoding. # import sys early.
# It is ok to import sys before gevent because sys is anyway always # it is ok to import sys before gevent because sys is anyway always
# imported first, e.g. to support sys.modules. # imported first, e.g. to support sys.modules.
import sys import sys
if sys.getdefaultencoding() != 'utf-8':
reload(sys)
sys.setdefaultencoding('utf-8')
delattr(sys, 'setdefaultencoding')
# safety check that we are not running from a setuptools entrypoint, where # safety check that we are not running from a setuptools entrypoint, where
# it would be too late to monkey-patch stdlib. # it would be too late to monkey-patch stdlib.
...@@ -198,6 +194,25 @@ def main(): ...@@ -198,6 +194,25 @@ def main():
raise RuntimeError('gpython: internal error: the following modules are pre-imported, but must be not:' raise RuntimeError('gpython: internal error: the following modules are pre-imported, but must be not:'
'\n\n\t%s\n\nsys.modules:\n\n\t%s' % (bad, sysmodv)) '\n\n\t%s\n\nsys.modules:\n\n\t%s' % (bad, sysmodv))
# set UTF-8 as default encoding.
if sys.getdefaultencoding() != 'utf-8':
reload(sys)
sys.setdefaultencoding('utf-8')
delattr(sys, 'setdefaultencoding')
# sys.executable
# on windows there are
# gpython-script.py
# gpython.exe
# gpython.manifest
# and argv[0] is gpython-script.py
exe = sys.argv[0]
argv = sys.argv[1:]
if exe.endswith('-script.py'):
exe = exe[:-len('-script.py')]
exe = exe + '.exe'
sys.executable = exe
# make gevent pre-available & stdlib patched # make gevent pre-available & stdlib patched
import gevent import gevent
from gevent import monkey from gevent import monkey
...@@ -219,23 +234,11 @@ def main(): ...@@ -219,23 +234,11 @@ def main():
for k in golang.__all__: for k in golang.__all__:
setattr(builtins, k, getattr(golang, k)) setattr(builtins, k, getattr(golang, k))
# sys.executable & friends # sys.version
exe = sys.argv[0]
# on windows there are
# gpython-script.py
# gpython.exe
# gpython.manifest
# and argv[0] is gpython-script.py
if exe.endswith('-script.py'):
exe = exe[:-len('-script.py')]
exe = exe + '.exe'
sys.executable = exe
sys.version += (' [GPython %s] [gevent %s]' % (golang.__version__, gevent.__version__)) sys.version += (' [GPython %s] [gevent %s]' % (golang.__version__, gevent.__version__))
# tail to pymain # tail to pymain
pymain(sys.argv[1:]) pymain(argv)
if __name__ == '__main__': if __name__ == '__main__':
main() main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment