From 2975d6624c4c1d3a01de12d60f357e79a1b8c0ff Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Tue, 19 May 2026 11:56:59 +0100 Subject: [PATCH] Added minimiser config file --- pyproject.toml | 2 +- src/support/minimiser.conf | 18 ++++++++++++++++++ src/support/minimiser.py | 23 ++++++++++++++--------- 3 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 src/support/minimiser.conf diff --git a/pyproject.toml b/pyproject.toml index 2bf3acc..7e27a9b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "ti-84-python" -version = "1.68.0" +version = "1.69.0" description = "TI-84 Plus CE-T Python Edition Applications" readme = "README.md" requires-python = ">=3.13" diff --git a/src/support/minimiser.conf b/src/support/minimiser.conf new file mode 100644 index 0000000..5e7840c --- /dev/null +++ b/src/support/minimiser.conf @@ -0,0 +1,18 @@ +{ + "exclude": { + "files": [ + "__init__.py", + "turtle.py" + ], + "folders": [ + "support", + "ti_desktop" + ] + }, + "aggressive": [ + "resident.py" + ], + "preserve": [ + "run" + ] +} \ No newline at end of file diff --git a/src/support/minimiser.py b/src/support/minimiser.py index ef85443..9d4afb5 100644 --- a/src/support/minimiser.py +++ b/src/support/minimiser.py @@ -41,14 +41,12 @@ to the calculator. """ +import json from os import makedirs, environ from pathlib import Path from datetime import datetime from python_minifier import minify -EXCLUDED_FILES = ["__init__.py", "turtle.py"] -EXCLUDED_FOLDERS = ["support", "ti_desktop"] -AGGRESSIVE_MINIMISATION = ["resident.py"] PROJECT_FOLDER = Path(__file__).parent.parent.parent @@ -112,12 +110,13 @@ def print_message(message): print(f"{timestamp} : {message}") -def minify_file(file_path, aggressive, output_folder): +def minify_file(file_path, aggressive, preserve_globals, output_folder): """ Minify a Python source file :param file_path: Path to the file to minimise :param aggressive: Use aggressive minimisation options + :param preserve_globals: List of globals to preserve during aggressive minification :param output_folder: Output folder path """ @@ -136,7 +135,7 @@ def minify_file(file_path, aggressive, output_folder): remove_pass=False, rename_locals=True, rename_globals=aggressive, - preserve_globals=["run"]) + preserve_globals=preserve_globals) # Write the "minimised" file output_file_path = output_folder / Path(file_path).name @@ -153,21 +152,27 @@ def minimise_all_source_files(): """ Find all Python files and "minimise" them prior to transfer to the calculator """ + # Load the minimiser configuration + config_file = Path(__file__).parent / "minimiser.conf" + with open(config_file, "r", encoding="utf-8") as f: + config = json.load(f) + + # Set up folder paths output_folder = prepare_output_folder() source_folder = PROJECT_FOLDER / "src" # Identify Python files that are *not* in excluded folders python_files = ( p for p in Path(source_folder).rglob("*.py") - if set(EXCLUDED_FOLDERS).isdisjoint(p.parts) + if set(config["exclude"]["folders"]).isdisjoint(p.parts) ) # Sort the files and iterate over them, minifying them if they're not # explicitly excluded for file in sorted(python_files, key=lambda p: p.name.lower()): - if file.name not in EXCLUDED_FILES: - aggressive = file.name in AGGRESSIVE_MINIMISATION - minify_file(file.absolute(), aggressive, output_folder) + if file.name not in config["exclude"]["files"]: + aggressive = file.name in config["aggressive"] + minify_file(file.absolute(), aggressive, config["preserve"], output_folder) if __name__ == "__main__" and "DOCBUILD" not in environ: