From c39fe7724548cf6efae88630ad1461099e18da5e Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Tue, 19 May 2026 22:02:13 +0100 Subject: [PATCH 01/12] Update minimiser config to increase aggressive minification --- pyproject.toml | 2 +- src/support/minimiser.conf | 32 ++++++++++++++++++++++++++++---- src/support/minimiser.py | 3 ++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7e27a9b..a57c696 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "ti-84-python" -version = "1.69.0" +version = "1.70.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 index 5e7840c..0f9207a 100644 --- a/src/support/minimiser.conf +++ b/src/support/minimiser.conf @@ -9,10 +9,34 @@ "ti_desktop" ] }, - "aggressive": [ - "resident.py" - ], + "aggressive": { + "folders": [ + "examples", + "ui" + ], + "files": [ + "batphase.py", + "batpulse.py", + "odelib.py", + "resident.py", + "seasonal.py", + "tabulate.py", + "winter.py" + ] + }, "preserve": [ - "run" + "EULER", + "PREDICTOR_CORRECTOR", + "RUNGE_KUTTA_4", + "OUTPUT_TEXT", + "OUTPUT_CHART", + "OUTPUT_SILENT", + "build_table", + "chart_pulse_timings", + "classify_sequence", + "detect_feeding_buzz_phases", + "print_table", + "run", + "solve" ] } \ No newline at end of file diff --git a/src/support/minimiser.py b/src/support/minimiser.py index 9d4afb5..85b4949 100644 --- a/src/support/minimiser.py +++ b/src/support/minimiser.py @@ -171,7 +171,8 @@ def minimise_all_source_files(): # explicitly excluded for file in sorted(python_files, key=lambda p: p.name.lower()): if file.name not in config["exclude"]["files"]: - aggressive = file.name in config["aggressive"] + aggressive = file.parent in config["aggressive"]["folders"] or \ + file.name in config["aggressive"]["files"] minify_file(file.absolute(), aggressive, config["preserve"], output_folder) From 040a48f3dd5cc394046454c37bf2fe252810b9c4 Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Wed, 20 May 2026 08:18:06 +0100 Subject: [PATCH 02/12] Per-file minification settings --- src/support/minimiser.conf | 100 +++++++++++++++++++++++++------------ src/support/minimiser.py | 61 +++++++++++++++++----- 2 files changed, 116 insertions(+), 45 deletions(-) diff --git a/src/support/minimiser.conf b/src/support/minimiser.conf index 0f9207a..9b9b8af 100644 --- a/src/support/minimiser.conf +++ b/src/support/minimiser.conf @@ -1,42 +1,78 @@ { + "default": { + "aggressive": false, + "preserve": [] + }, "exclude": { - "files": [ - "__init__.py", - "turtle.py" - ], "folders": [ "support", "ti_desktop" - ] - }, - "aggressive": { - "folders": [ - "examples", - "ui" ], "files": [ - "batphase.py", - "batpulse.py", - "odelib.py", - "resident.py", - "seasonal.py", - "tabulate.py", - "winter.py" + "__init__.py", + "turtle.py" ] }, - "preserve": [ - "EULER", - "PREDICTOR_CORRECTOR", - "RUNGE_KUTTA_4", - "OUTPUT_TEXT", - "OUTPUT_CHART", - "OUTPUT_SILENT", - "build_table", - "chart_pulse_timings", - "classify_sequence", - "detect_feeding_buzz_phases", - "print_table", - "run", - "solve" - ] + "folders": { + "examples": { + "aggressive": true, + "preserve": [] + }, + "ui": { + "aggressive": true, + "preserve": [] + } + }, + "files": { + "batphase.py": { + "aggressive": true, + "preserve": [ + "classify_sequence", + "detect_feeding_buzz_phases" + ] + }, + "batpulse.py": { + "aggressive": true, + "preserve": [ + "chart_pulse_timings" + ] + }, + "odelib.py": { + "aggressive": true, + "preserve": [ + "EULER", + "PREDICTOR_CORRECTOR", + "RUNGE_KUTTA_4", + "OUTPUT_TEXT", + "OUTPUT_CHART", + "OUTPUT_SILENT", + "solve" + ] + }, + "resident.py": { + "aggressive": true, + "preserve": [ + "run" + ] + }, + "seasonal.py": { + "aggressive": true, + "preserve": [ + "run" + ] + }, + "tabulate.py": { + "aggressive": true, + "preserve": [ + "build_table", + "print_table" + ] + }, + "winter.py": { + "aggressive": true, + "preserve": [ + "run" + ] + } + } } \ No newline at end of file diff --git a/src/support/minimiser.py b/src/support/minimiser.py index 85b4949..0bf4053 100644 --- a/src/support/minimiser.py +++ b/src/support/minimiser.py @@ -50,7 +50,7 @@ PROJECT_FOLDER = Path(__file__).parent.parent.parent -def prepare_output_folder(): +def prepare_output_folder() -> str: """ Make sure the output folder exists and is empty @@ -69,7 +69,7 @@ def prepare_output_folder(): return output_folder -def remove_comments(lines): +def remove_comments(lines: list[str]) -> list[str]: """ Give the content of a source file as a list of individual lines, remove docstrings and comments @@ -100,7 +100,7 @@ def remove_comments(lines): return lines -def print_message(message): +def print_message(message: str) -> None: """ Show a timestamped message @@ -110,7 +110,12 @@ def print_message(message): print(f"{timestamp} : {message}") -def minify_file(file_path, aggressive, preserve_globals, output_folder): +def minify_file( + file_path: Path, + aggressive: bool, + preserve: list[str], + output_folder: str +) -> None: """ Minify a Python source file @@ -135,20 +140,51 @@ def minify_file(file_path, aggressive, preserve_globals, output_folder): remove_pass=False, rename_locals=True, rename_globals=aggressive, - preserve_globals=preserve_globals) + preserve_globals=preserve) # Write the "minimised" file output_file_path = output_folder / Path(file_path).name with open(output_file_path, mode="wt", encoding="UTF-8") as out_handle: out_handle.writelines(minified) + # Calculate the minification results minified_file = Path(output_file_path) minified_size = minified_file.stat().st_size reduction = 100.0 - 100.0 * minified_size / original_size - print_message(f"Minified {minified_file.name} : {original_size} bytes -> {minified_size} bytes, {round(reduction)}% reduction") + # Output the minification result message + minified_file_name = minified_file.name.ljust(11, " ") + aggressive_text = (("non-" if not aggressive else "") + "aggressive").capitalize() + print_message(f"Minified {minified_file_name} : {aggressive_text}, " + f"{original_size} bytes -> {minified_size} bytes, {round(reduction)}% reduction") -def minimise_all_source_files(): + +def get_file_config(config: dict, file: Path) -> tuple | None: + """ + Return the minification configuration for the specified file + + :param config: Dictionary of configuration values + :param file: Path for the file + :return: Tuple of the exclusion flag and the file minification settings + """ + # Check folder exclusions + parent_folder = file.parent.name + if parent_folder in config["exclude"]["folders"]: + return True, None + + # Check file exclusions + if file.name in config["exclude"]["files"]: + return True, None + + # Check for folder-level settings + if parent_folder in config["folders"].keys(): + return False, config["folders"][parent_folder] + + # Get the config for this file or, if not present, return a "safe" default + return False, config["files"].get(file.name, config["default"]) + + +def minimise_all_source_files() -> None: """ Find all Python files and "minimise" them prior to transfer to the calculator """ @@ -157,11 +193,11 @@ def minimise_all_source_files(): with open(config_file, "r", encoding="utf-8") as f: config = json.load(f) - # Set up folder paths + # # Set up folder paths output_folder = prepare_output_folder() source_folder = PROJECT_FOLDER / "src" - # Identify Python files that are *not* in excluded folders + # # Identify Python files that are *not* in excluded folders python_files = ( p for p in Path(source_folder).rglob("*.py") if set(config["exclude"]["folders"]).isdisjoint(p.parts) @@ -170,10 +206,9 @@ def minimise_all_source_files(): # 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 config["exclude"]["files"]: - aggressive = file.parent in config["aggressive"]["folders"] or \ - file.name in config["aggressive"]["files"] - minify_file(file.absolute(), aggressive, config["preserve"], output_folder) + excluded, file_config = get_file_config(config, file) + if not excluded: + minify_file(file.absolute(), file_config["aggressive"], file_config["preserve"], output_folder) if __name__ == "__main__" and "DOCBUILD" not in environ: From 2a59537575b4e5dfab0fe1d5d5d73c1db707db02 Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Wed, 20 May 2026 08:28:55 +0100 Subject: [PATCH 03/12] Specific mnification settings for barometer --- src/support/minimiser.conf | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/support/minimiser.conf b/src/support/minimiser.conf index 9b9b8af..e0dd55f 100644 --- a/src/support/minimiser.conf +++ b/src/support/minimiser.conf @@ -24,6 +24,17 @@ } }, "files": { + "barometr.py": { + "aggressive": true, + "preserve": [ + "PASCAL", + "HECTOPASCAL", + "MMHG", + "convert", + "calculate_p0_from_p", + "calculate_p_from_p0" + ] + }, "batphase.py": { "aggressive": true, "preserve": [ From 0c9d467bd7c330ebd3f4898e69bd930aecd24ec9 Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Wed, 20 May 2026 08:33:23 +0100 Subject: [PATCH 04/12] Specific mnification settings for IPv4 same network --- src/support/minimiser.conf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/support/minimiser.conf b/src/support/minimiser.conf index e0dd55f..11b4f2a 100644 --- a/src/support/minimiser.conf +++ b/src/support/minimiser.conf @@ -48,6 +48,12 @@ "chart_pulse_timings" ] }, + "ipv4snt.py": { + "aggressive": true, + "preserve": [ + "same_subnet" + ] + }, "odelib.py": { "aggressive": true, "preserve": [ From abc5c1dbaad29d82042bc98451dd53091a2c4e3f Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Wed, 20 May 2026 08:41:47 +0100 Subject: [PATCH 05/12] Specific minification settings for Julian dates --- src/support/minimiser.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/support/minimiser.conf b/src/support/minimiser.conf index 11b4f2a..ee0c062 100644 --- a/src/support/minimiser.conf +++ b/src/support/minimiser.conf @@ -48,10 +48,10 @@ "chart_pulse_timings" ] }, - "ipv4snt.py": { + "julian.py": { "aggressive": true, "preserve": [ - "same_subnet" + "julian_date" ] }, "odelib.py": { From f8246f0f23c927806fb852bd43a458cfc65368d7 Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Wed, 20 May 2026 08:46:19 +0100 Subject: [PATCH 06/12] Specific minification settings for temperature conversion --- src/support/minimiser.conf | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/support/minimiser.conf b/src/support/minimiser.conf index ee0c062..b8ad932 100644 --- a/src/support/minimiser.conf +++ b/src/support/minimiser.conf @@ -85,6 +85,16 @@ "print_table" ] }, + "tempconv.py": { + "aggressive": true, + "preserve": [ + "CENTIGRADE", + "FAHRENHEIT", + "KELVIN", + "DECIMAL_PLACES", + "convert" + ] + }, "winter.py": { "aggressive": true, "preserve": [ From 627e3654e8ced46ed9162bcefe576fb9c63a2d43 Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Wed, 20 May 2026 08:49:32 +0100 Subject: [PATCH 07/12] Specific minification settings for key codes --- src/support/minimiser.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/support/minimiser.conf b/src/support/minimiser.conf index b8ad932..b29f06e 100644 --- a/src/support/minimiser.conf +++ b/src/support/minimiser.conf @@ -66,6 +66,10 @@ "solve" ] }, + "keycodes.py": { + "aggressive": true, + "preserve": [] + }, "resident.py": { "aggressive": true, "preserve": [ From 1538328b73dc6b9c9b415cd2f35e394946bd7e9a Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Wed, 20 May 2026 08:59:52 +0100 Subject: [PATCH 08/12] Specific minification settings for date utils --- src/support/minimiser.conf | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/support/minimiser.conf b/src/support/minimiser.conf index b29f06e..986c436 100644 --- a/src/support/minimiser.conf +++ b/src/support/minimiser.conf @@ -48,6 +48,15 @@ "chart_pulse_timings" ] }, + "dateutl.py": { + "aggressive": true, + "preserve": [ + "seconds_since_epoch", + "timestamp_to_date", + "is_leap_year", + "prompt_for_date" + ] + }, "julian.py": { "aggressive": true, "preserve": [ From 092ac533a4ca2763e78760710a2824687e92713b Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Wed, 20 May 2026 09:03:40 +0100 Subject: [PATCH 09/12] Specific minification settings for input utils --- src/support/minimiser.conf | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/support/minimiser.conf b/src/support/minimiser.conf index 986c436..cd84328 100644 --- a/src/support/minimiser.conf +++ b/src/support/minimiser.conf @@ -57,6 +57,16 @@ "prompt_for_date" ] }, + "iptutils.py": { + "aggressive": true, + "preserve": [ + "prompt_for_integer", + "prompt_for_option", + "prompt_for_option_with_values", + "prompt_for_float", + "prompt_for_yes_no" + ] + }, "julian.py": { "aggressive": true, "preserve": [ From f69a3de92da1941717b5bdddbdd82a3a1f6c806c Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Wed, 20 May 2026 09:06:54 +0100 Subject: [PATCH 10/12] Specific minification settings for output utils --- src/support/minimiser.conf | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/support/minimiser.conf b/src/support/minimiser.conf index cd84328..f3634a0 100644 --- a/src/support/minimiser.conf +++ b/src/support/minimiser.conf @@ -85,6 +85,13 @@ "solve" ] }, + "oututils.py": { + "aggressive": true, + "preserve": [ + "print_title", + "print_list" + ] + }, "keycodes.py": { "aggressive": true, "preserve": [] From a23490e7e206ff0bea1ce1ffe902fd7d89e3f1b9 Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Wed, 20 May 2026 09:09:41 +0100 Subject: [PATCH 11/12] Specific minification settings for string utils --- src/support/minimiser.conf | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/support/minimiser.conf b/src/support/minimiser.conf index f3634a0..d840493 100644 --- a/src/support/minimiser.conf +++ b/src/support/minimiser.conf @@ -108,6 +108,13 @@ "run" ] }, + "strutils.py": { + "aggressive": true, + "preserve": [ + "pad_string", + "truncate_string" + ] + }, "tabulate.py": { "aggressive": true, "preserve": [ From de01228f05e71d5e30d0a9b2e6f007ddcf1be308 Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Wed, 20 May 2026 09:27:18 +0100 Subject: [PATCH 12/12] Update Python minifier options to squeeze the maximum out --- src/support/minimiser.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/support/minimiser.py b/src/support/minimiser.py index 0bf4053..c43bc56 100644 --- a/src/support/minimiser.py +++ b/src/support/minimiser.py @@ -137,10 +137,14 @@ def minify_file( source = "".join(lines) minified = minify(source, file_path, - remove_pass=False, + remove_pass=True, + remove_literal_statements=True, rename_locals=True, rename_globals=aggressive, - preserve_globals=preserve) + preserve_globals=preserve, + remove_asserts=True, + remove_debug=True, + prefer_single_line=True) # Write the "minimised" file output_file_path = output_folder / Path(file_path).name