diff --git a/.github/workflows/ci-test-run.yml b/.github/workflows/ci-test-run.yml index 1a82b07f..a49446de 100644 --- a/.github/workflows/ci-test-run.yml +++ b/.github/workflows/ci-test-run.yml @@ -19,7 +19,7 @@ jobs: container: 'alpine:3.15.0' artifact: 'alpine' - - os: windows-latest + - os: windows-2019 artifact: 'windows' - os: windows-latest diff --git a/_AutoinstallCreator/io_tools.py b/_AutoinstallCreator/io_tools.py index 8e880b0c..48c0b1bb 100644 --- a/_AutoinstallCreator/io_tools.py +++ b/_AutoinstallCreator/io_tools.py @@ -99,58 +99,5 @@ def write_text(file_path: Union[str, pathlib.Path], data: str, encoding: str = ' return pathlib.Path(file_path).write_text(data=data, encoding=encoding) -def import_package_modules(package_file_path: str, package_name: str) -> list[ModuleType]: - extension = '.py' - imported_modules = [] - for p in sorted(pathlib.Path(os.path.dirname(package_file_path)).iterdir()): - if p.name.endswith(extension) and p.is_file(): - module = p.name[:-len(extension)] - if module != '__init__': - imported_modules.append(importlib.import_module(f".{module}", package_name)) - return imported_modules - - -def byte_to_humanreadable_format(num: Union[int, float], metric: bool = False, precision: int = 1) -> str: - """ - Human-readable formatting of bytes, using binary (powers of 1024) - or metric (powers of 1000) representation. - """ - metric_labels: list[str] = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] - binary_labels: list[str] = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"] - precision_offsets: list[float] = [0.5, 0.05, 0.005, 0.0005] # PREDEFINED FOR SPEED. - precision_formats: list[str] = ["{}{:.0f} {}", "{}{:.1f} {}", "{}{:.2f} {}", "{}{:.3f} {}"] # PREDEFINED FOR SPEED. - - assert isinstance(num, (int, float)), "num must be an int or float" - assert isinstance(metric, bool), "metric must be a bool" - assert isinstance(precision, int) and 0 <= precision <= 3, "precision must be an int (range 0-3)" - - unit_labels = metric_labels if metric else binary_labels - last_label = unit_labels[-1] - unit_step = 1000 if metric else 1024 - unit_step_thresh = unit_step - precision_offsets[precision] - - is_negative = num < 0 - if is_negative: # Faster than ternary assignment or always running abs(). - num = abs(num) - - for unit in unit_labels: - if num < unit_step_thresh: - # VERY IMPORTANT: - # Only accepts the CURRENT unit if we're BELOW the threshold where - # float rounding behavior would place us into the NEXT unit: F.ex. - # when rounding a float to 1 decimal, any number ">= 1023.95" will - # be rounded to "1024.0". Obviously we don't want ugly output such - # as "1024.0 KiB", since the proper term for that is "1.0 MiB". - break - if unit != last_label: - # We only shrink the number if we HAVEN'T reached the last unit. - # NOTE: These looped divisions accumulate floating point rounding - # errors, but each new division pushes the rounding errors further - # and further down in the decimals, so it doesn't matter at all. - num /= unit_step - - return precision_formats[precision].format("-" if is_negative else "", num, unit) - - def get_name_without_extensions(file_path: str) -> str: return pathlib.Path(pathlib.Path(file_path).stem).stem diff --git a/_AutoinstallCreator/test_update.py b/_AutoinstallCreator/test_update.py index 5019c21b..12c3d969 100644 --- a/_AutoinstallCreator/test_update.py +++ b/_AutoinstallCreator/test_update.py @@ -11,7 +11,7 @@ _root_path: str = os.path.dirname(_self_path) _tools_path: str = os.path.join(_root_path, '.tools') -busybox_exe_path_arg: list[str] = [] +busybox_exe_path_arg = [] update_script_name: str = 'update.sh' package_name = 'AutoinstallCreator.sh' if sys.platform.startswith('win'):