Create directories required for make_dist.py if non-existent
authorAdrian Müller <adrian.mueller@intra2net.com>
Mon, 2 Mar 2026 09:03:09 +0000 (10:03 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Tue, 3 Mar 2026 09:35:19 +0000 (10:35 +0100)
make_dist.py

index a505124..17de73b 100755 (executable)
@@ -10,7 +10,8 @@ run rpmbuild on it to create an installable rpm.
 """
 
 import sys
-from os.path import join, basename, dirname, expanduser
+from os.path import join, basename, dirname, expanduser, isdir
+from os import makedirs
 from re import compile as re_compile
 import tarfile
 from shutil import copy
@@ -81,12 +82,21 @@ def tar_add_filter(tarinfo):
     return tarinfo
 
 
+def ensure_dir_exists(dir_path):
+    """
+    Create the directory under the specified path, if it doesn't already exist.
+    """
+    if not isdir(dir_path):
+        makedirs(dir_path)
+
+
 def create_tarball():
     """Create tarball, return its full path."""
     name, version, tarball_file = get_spec_info()
     tarball_path = join(DIST_DIR, tarball_file)
     print(f'Creating {tarball_path}')
     dir_name = f'{name}-{version}'
+    ensure_dir_exists(DIST_DIR)
     with tarfile.open(tarball_path, 'w:gz') as tarball:
         for entry in DATA:
             tarball.add(entry, join(dir_name, entry), filter=tar_add_filter)
@@ -95,6 +105,7 @@ def create_tarball():
 
 def build_rpm(tarball_path):
     """Create rpm using rpmbuild with spec file and newly created tarball."""
+    ensure_dir_exists(RPM_SOURCE_DIR)
     copy(tarball_path, RPM_SOURCE_DIR)
     run(('rpmbuild', '-bb', SPEC_FILE))