]> jfr.im git - yt-dlp.git/blobdiff - pyinst.py
[devscripts] Create `utils` and refactor
[yt-dlp.git] / pyinst.py
index 31854e881c000115003ef0c1fc891e8b243aa7d3..9be5d896041fde0980b470cea5f29d70364744c2 100644 (file)
--- a/pyinst.py
+++ b/pyinst.py
@@ -1,11 +1,17 @@
 #!/usr/bin/env python3
 
+# Allow direct execution
 import os
-import platform
 import sys
 
+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+
+import platform
+
 from PyInstaller.__main__ import run as run_pyinstaller
 
+from devscripts.utils import read_version
+
 OS_NAME, MACHINE, ARCH = sys.platform, platform.machine(), platform.architecture()[0][:2]
 if MACHINE in ('x86_64', 'AMD64') or ('i' in MACHINE and '86' in MACHINE):
     # NB: Windows x86 has MACHINE = AMD64 irrespective of bitness
@@ -13,8 +19,7 @@
 
 
 def main():
-    opts = parse_options()
-    version = read_version('yt_dlp/version.py')
+    opts, version = parse_options(), read_version()
 
     onedir = '--onedir' in opts or '-D' in opts
     if not onedir and '-F' not in opts and '--onefile' not in opts:
@@ -53,13 +58,6 @@ def parse_options():
     return opts
 
 
-# Get the version from yt_dlp/version.py without importing the package
-def read_version(fname):
-    with open(fname, encoding='utf-8') as f:
-        exec(compile(f.read(), fname, 'exec'))
-        return locals()['__version__']
-
-
 def exe(onedir):
     """@returns (name, path)"""
     name = '_'.join(filter(None, (