import ast import textwrap from pyinstallerguiwrapper.gui.ast_transformer import SpecTransformer def run_test(orig_spec_str): gui_options = { 'analysis_scripts': ['pyucc\\__main__.py'], 'analysis_pathex': ['pyucc', '.', 'external\\python-tkinter-logger', 'external\\python-resource-monitor'], 'formatted_datas': [('PyUcc.ico', '.'), ('external\\python-tkinter-logger\\tkinter_logger.py', '.'), ('external\\python-resource-monitor\\resource_monitor.py', '.')], 'formatted_hiddenimports': ['tkinter_logger', 'resource_monitor', 'pyucc.core.differ', 'pyucc.gui.gui', 'pyucc.config.settings', 'logging', 'logging.handlers', 'logging.config'], 'formatted_binaries': [], 'app_name': 'PyUcc', 'icon_rel_path': 'PyUcc.ico', 'is_windowed': False, 'is_onefile': True, 'use_upx': True, 'pyz_cipher_var_name': 'block_cipher', 'a_var_name': 'a', 'pyz_var_name': 'pyz', 'exe_var_name': 'exe' } tree = ast.parse(orig_spec_str) transformer = SpecTransformer(gui_options, logger_func=print) new_tree = transformer.visit(tree) ast.fix_missing_locations(new_tree) try: new_src = ast.unparse(new_tree) except Exception: import astor new_src = astor.to_source(new_tree) print('--- TRANSFORMED SPEC START ---') print(new_src) print('--- TRANSFORMED SPEC END ---') if __name__ == '__main__': orig = textwrap.dedent(''' block_cipher = None a = Analysis( pathex=['pyucc', '.', 'external\\python-tkinter-logger', 'external\\python-resource-monitor'], binaries=[], datas=[ ('PyUcc.ico', '.'), ('external\\python-tkinter-logger\\tkinter_logger.py', '.'), ('external\\python-resource-monitor\\resource_monitor.py', '.') ], hiddenimports=[ 'tkinter_logger', 'resource_monitor', 'pyucc.core.differ', 'pyucc.gui.gui', 'pyucc.config.settings', 'logging', 'logging.handlers', 'logging.config', ], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False, scripts=['pyucc\\__main__.py'] ) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, [], name='PyUcc', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude=[], runtime_tmpdir=None, console=True, icon='PyUcc.ico', exclude_binaries=True) coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, upx_exclude=[], name='PyUcc') ''') run_test(orig)