Commit 51925488 authored by Kirill Smelkov's avatar Kirill Smelkov

gpython: Move code to handle -V to "start interpreter" phase

We'll need this in the next patch, where golang/gevent preimport will be
moved from "before call to pymain", to "in between option parsing and
interpreter start".
parent a1ac2a45
......@@ -50,41 +50,14 @@ def pymain(argv):
from six.moves import input as raw_input
run = None # function to run according to -c/-m/file/interactive
version = False # set if `-V`
warnoptions = [] # collected `-W arg`
while len(argv) > 0:
# -V / --version
if argv[0] in ('-V', '--version'):
ver = []
if 'GPython' in sys.version:
golang = sys.modules['golang'] # must be already imported
gevent = sys.modules.get('gevent', None)
gpyver = 'GPython %s' % golang.__version__
if gevent is not None:
gpyver += ' [gevent %s]' % gevent.__version__
else:
gpyver += ' [threads]'
ver.append(gpyver)
import platform
pyimpl = platform.python_implementation()
v = _version_info_str
if pyimpl == 'CPython':
ver.append('CPython %s' % v(sys.version_info))
elif pyimpl == 'PyPy':
ver.append('PyPy %s' % v(sys.pypy_version_info))
ver.append('Python %s' % v(sys.version_info))
else:
ver = [] # unknown
ver = ' / '.join(ver)
if ver == '':
# unknown implementation: just print full sys.version
ver = sys.version
print(ver, file=sys.stderr)
return
version = True
break
# -c command
elif argv[0].startswith('-c'):
......@@ -171,6 +144,42 @@ def pymain(argv):
console.interact()
# ---- options processed -> start the interpreter ----
# handle -V/--version
if version:
ver = []
if 'GPython' in sys.version:
golang = sys.modules['golang'] # must be already imported
gevent = sys.modules.get('gevent', None)
gpyver = 'GPython %s' % golang.__version__
if gevent is not None:
gpyver += ' [gevent %s]' % gevent.__version__
else:
gpyver += ' [threads]'
ver.append(gpyver)
import platform
pyimpl = platform.python_implementation()
v = _version_info_str
if pyimpl == 'CPython':
ver.append('CPython %s' % v(sys.version_info))
elif pyimpl == 'PyPy':
ver.append('PyPy %s' % v(sys.pypy_version_info))
ver.append('Python %s' % v(sys.version_info))
else:
ver = [] # unknown
ver = ' / '.join(ver)
if ver == '':
# unknown implementation: just print full sys.version
ver = sys.version
print(ver, file=sys.stderr)
return
# init warnings
if len(warnoptions) > 0:
# NOTE warnings might be already imported by code that calls pymain.
......
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