Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 18 additions & 0 deletions src/support/minimiser.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"exclude": {
"files": [
"__init__.py",
"turtle.py"
],
"folders": [
"support",
"ti_desktop"
]
},
"aggressive": [
"resident.py"
],
"preserve": [
"run"
]
}
23 changes: 14 additions & 9 deletions src/support/minimiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
"""

Expand All @@ -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
Expand All @@ -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:
Expand Down
Loading