From 74fcd90dafd44108c7efeb09dc691f1b09a9821b Mon Sep 17 00:00:00 2001
From: timoxa0 <tima012007@gmail.com>
Date: Fri, 10 May 2024 13:27:51 +0500
Subject: [PATCH] Improved build system

---
 lon_deployer/builder.py     | 32 ++++++++++++++++++++++++++++++++
 lon_deployer/pyinstaller.py | 17 -----------------
 2 files changed, 32 insertions(+), 17 deletions(-)
 create mode 100644 lon_deployer/builder.py
 delete mode 100644 lon_deployer/pyinstaller.py

diff --git a/lon_deployer/builder.py b/lon_deployer/builder.py
new file mode 100644
index 0000000..0a53952
--- /dev/null
+++ b/lon_deployer/builder.py
@@ -0,0 +1,32 @@
+import PyInstaller.__main__
+from pathlib import Path
+
+PROJECT_DIR = Path(__file__).parent.parent.absolute()
+
+
+def get_git_revision(base_path):
+    git_dir = Path(base_path) / '.git'
+    with (git_dir / 'HEAD').open('r') as head:
+        ref = head.readline().split(' ')[-1].strip()
+
+    with (git_dir / ref).open('r') as git_hash:
+        return git_hash.readline().strip()
+
+
+def create_version():
+    with open(Path(__file__).parent/"_version.py", "w") as vf:
+        vf.write(f"VERSION=\"{get_git_revision(PROJECT_DIR)[:7]}\"")
+
+
+def build():
+    create_version()
+    PyInstaller.__main__.run([
+        str(PROJECT_DIR / "run.py"),
+        '--onefile',
+        '--collect-submodules',
+        '--name',
+        'LoN-Deployer',
+        "-i",
+        "NONE",
+        # other pyinstaller options...
+    ])
diff --git a/lon_deployer/pyinstaller.py b/lon_deployer/pyinstaller.py
deleted file mode 100644
index f882cd1..0000000
--- a/lon_deployer/pyinstaller.py
+++ /dev/null
@@ -1,17 +0,0 @@
-import PyInstaller.__main__
-from pathlib import Path
-
-HERE = Path(__file__).parent.parent.absolute()
-path_to_main = str(HERE / "run.py")
-
-
-def install():
-    PyInstaller.__main__.run([
-        path_to_main,
-        '--onefile',
-        '--collect-submodules',
-        '--name LoN Deployer',
-        "-i",
-        "NONE",
-        # other pyinstaller options...
-    ])