From 2e9fb211c6c8d69b2dc68c05b90a07c6eb9cc37d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 12 Mar 2021 13:39:08 +1100 Subject: Cleanup: make_source_archive.py minor changes & comments - Add notes on portability. - Use encoding argument for all file IO. - Use integer math to calculate major/minor version, while float division should be fine prefer matching Blender. --- build_files/utils/make_source_archive.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'build_files/utils') diff --git a/build_files/utils/make_source_archive.py b/build_files/utils/make_source_archive.py index 24928742a2d..271ca358f7e 100755 --- a/build_files/utils/make_source_archive.py +++ b/build_files/utils/make_source_archive.py @@ -9,6 +9,10 @@ from typing import Iterable, TextIO # This script can run from any location, # output is created in the $CWD +# +# NOTE: while the Python part of this script is portable, +# it relies on external commands typically found on GNU/Linux. +# Support for other platforms could be added by moving GNU `tar` & `md5sum` use to Python. SKIP_NAMES = { ".gitignore", @@ -52,8 +56,9 @@ class BlenderVersion: >>> str(BlenderVersion(327, 0, "release")) '3.27.0' """ - - as_string = f"{self.version/100:.2f}.{self.patch}" + version_major = self.version // 100 + version_minor = self.version % 100 + as_string = f"{version_major}.{version_minor}.{self.patch}" if self.is_release: return as_string return f"{as_string}-{self.cycle}" @@ -101,6 +106,7 @@ def submodules_to_manifest(version: BlenderVersion, outfile: TextIO) -> None: for line in git_command("submodule"): submodule = line.split()[1] + # Don't use native slashes as GIT for MS-Windows outputs forward slashes. if skip_addon_contrib and submodule == "release/scripts/addons_contrib": continue @@ -110,6 +116,7 @@ def submodules_to_manifest(version: BlenderVersion, outfile: TextIO) -> None: def create_tarball(version: BlenderVersion, tarball: Path, manifest: Path) -> None: print(f'Creating archive: "{tarball}" ...', end="", flush=True) + # Requires GNU `tar`, since `--transform` is used. command = [ "tar", "--transform", @@ -139,7 +146,7 @@ def create_checksum_file(tarball: Path) -> None: md5_cmd = subprocess.run( command, stdout=subprocess.PIPE, check=True, text=True, timeout=300 ) - with md5_path.open("w") as outfile: + with md5_path.open("w", encoding="utf-8") as outfile: outfile.write(md5_cmd.stdout) print("OK") -- cgit v1.2.3