From 611db09fd063d9d2c9b26bdcf21513e0c1bddea3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 28 Sep 2020 14:04:51 +0100 Subject: [PATCH] Re-order imports so stdout/err redirect works for `logging` too. Else the StreamHandler gets created with old stdout/err and causes py2exe to attempt to write log file to CWD, which doesn't work when installed. --- EDMarketConnector.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 45124dc7..7f46b25f 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -15,14 +15,6 @@ from sys import platform from time import localtime, strftime, time from typing import TYPE_CHECKING -from EDMCLogging import edmclogger, logger, logging - -# See EDMCLogging.py docs. -# isort: off -if TYPE_CHECKING: - from logging import trace, TRACE # type: ignore # noqa: F401 -# isort: on - from config import applongname, appname, appversion, appversion_nobuild, config, copyright # TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup @@ -36,6 +28,15 @@ if __name__ == "__main__": # unbuffered not allowed for text in python3, so use `1 for line buffering sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='wt', buffering=1) +from EDMCLogging import edmclogger, logger, logging + +# See EDMCLogging.py docs. +# isort: off +if TYPE_CHECKING: + from logging import trace, TRACE # type: ignore # noqa: F401 +# isort: on + + if getattr(sys, 'frozen', False): # Under py2exe sys.path[0] is the executable name if platform == 'win32':