Skip to content

Commit

Permalink
Merge pull request manthey#9 from manthey/version-report
Browse files Browse the repository at this point in the history
Improve version reporting.
  • Loading branch information
manthey committed Apr 22, 2018
2 parents 3dc3803 + 4abef8a commit a77cbcc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
42 changes: 31 additions & 11 deletions pyexe.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,35 @@ def alternate_raw_input(prompt=None):
return raw_input('')


def print_version(details=1):
"""
Print the current version.
Enter: details: if 2, print more details.
"""
from py_version import Version, Description

print('%s, Version %s' % (Description, Version))
if details > 1:
print('Python %s' % (sys.version))
import importlib
# pywin32
import win32api
fileinfo = win32api.GetFileVersionInfo(win32api.__file__, '\\')
print('pywin32: %s' % str(fileinfo['FileVersionLS'] >> 16))
for module_name in ('pip', 'psutil', 'setuptools', 'six'):
module = importlib.import_module(module_name)
print('%s: %s' % (module_name, module.__version__))


if hasattr(sys, 'frozen'):
delattr(sys, 'frozen')
Help = False
DirectCmd = None
ImportSite = True
Interactive = 'check'
PrintVersion = 0
RunModule = False
ShowVersion = False
SkipFirstLine = False
Start = None
Unbuffered = False
Expand Down Expand Up @@ -70,7 +91,7 @@ def alternate_raw_input(prompt=None):
elif let == 'u':
Unbuffered = True
elif let == 'V':
ShowVersion = True
PrintVersion += 1
elif let == 'x':
SkipFirstLine = True
elif let in ('B', 'E', 'O', 's'):
Expand All @@ -83,19 +104,19 @@ def alternate_raw_input(prompt=None):
elif arg == '--help' or arg == '-h' or arg == '/?':
Help = True
elif arg == '--version':
ShowVersion = True
PrintVersion += 1
elif arg.startswith('-'):
Help = True
elif not Start:
Start = i
break
if Help:
print("""Stand-Alone Python Interpreter
Syntax: py.exe [--all] [--help] [-c (cmd) | -m (module) | (python file) [arg]]
[-i] [-S] [-u] [-V] [-x]
from py_version import Version, Description
print('%s, Version %s' % (Description, Version))
print('usage: %s [option] ... [-c cmd | -m mod | file | -] [arg] ...' % sys.argv[0])
print("""Stand-alone specific options:
--all attempts to import all modules.
General Python options and arguments (and corresponding environment variables):
-c runs the remaining options as a program.
-E ignores environment variables.
-i forces a prompt even if stdin does not appear to be a terminal; also
Expand All @@ -110,9 +131,8 @@ def alternate_raw_input(prompt=None):
started.""")
print(repr(sys.argv))
sys.exit(0)
if ShowVersion:
from py_version import Version, Description
print('%s, Version %s' % (Description, Version))
if PrintVersion:
print_version(PrintVersion)
sys.exit(0)
if Interactive == 'check' and UseEnvironment:
if os.environ.get('PYTHONINSPECT'):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_pyexe.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def testVersion(exepath):
assert out.startswith('Stand-Alone Python Interpreter')
out, err = runPyExe(exepath, ['-V'])
assert out.startswith('Stand-Alone Python Interpreter')
out, err = runPyExe(exepath, ['-V', '-V'])
assert 'psutil' in out and 'pywin32' in out


def testDirectCommand(exepath):
Expand Down Expand Up @@ -114,4 +116,3 @@ def testSympyFromPip(exepath):
# with source file
# -x
# stdin
# pip install sympy and then use it

0 comments on commit a77cbcc

Please sign in to comment.