Additional logging centered around sys module

Due to my struggles reproducing the official build, I felt it might be
useful to log extra information regarding the version of PyInstaller.

Unfortunately, such information is not available due to the way things
work. However, during that process I came across some other interesting
details that would likely be useful when logged.
This commit is contained in:
Jan Wester 2019-11-04 14:35:21 +01:00
parent 5117f7d476
commit 2d622792f3
2 changed files with 27 additions and 4 deletions

View file

@ -7,9 +7,11 @@
import os
import sys
import logging
import pathlib
from manuskript.functions import writablePath
from importlib import import_module
from pprint import pformat
LOGGER = logging.getLogger(__name__)
@ -223,9 +225,7 @@ def attributesFromOptionalModule(module, *attributes):
# The list is consumed as a part of the unpacking syntax.
return v
import pathlib
def logVersionInformation(logger=None):
def logRuntimeInformation(logger=None):
"""Logs all important runtime information neatly together.
Due to the generic nature, use the manuskript logger by default."""
@ -241,6 +241,29 @@ def logVersionInformation(logger=None):
logger.info("Operating System: %s", platform())
logger.info("Hardware: %s / %s", machine(), processor())
# Information about the running instance. See:
# https://pyinstaller.readthedocs.io/en/v3.3.1/runtime-information.html
# http://www.py2exe.org/index.cgi/Py2exeEnvironment
# https://cx-freeze.readthedocs.io/en/latest/faq.html#data-files
frozen = getattr(sys, 'frozen', False)
if frozen:
logger.info("Running in a frozen (packaged) state.")
logger.debug("* sys.frozen = %s", pformat(frozen))
# PyInstaller, py2exe and cx_Freeze modules are not accessible while frozen,
# so logging their version is (to my knowledge) impossible without including
# special steps into the distribution process. But some traces do exist...
logger.debug("* sys._MEIPASS = %s", getattr(sys, '_MEIPASS', "N/A")) # PyInstaller bundle
# cx_Freeze and py2exe do not appear to leave anything similar exposed.
else:
logger.info("Running from unpackaged source code.")
# File not found? These bits of information might help.
logger.debug("* sys.executable = %s", pformat(sys.executable))
logger.debug("* sys.argv = %s", pformat(sys.argv))
logger.debug("* sys.path = %s", pformat(sys.path))
logger.debug("* sys.prefix = %s", pformat(sys.prefix))
# Manuskript and Python info.
from manuskript.functions import getGitRevisionAsString, getManuskriptPath
from manuskript.version import getVersion

View file

@ -34,7 +34,7 @@ def prepare(arguments, tests=False):
manuskript.logging.integrateQtLogging()
# Log all the versions for less headaches.
manuskript.logging.logVersionInformation()
manuskript.logging.logRuntimeInformation()
icon = QIcon()
for i in [16, 32, 64, 128, 256, 512]: