]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: include the cephadmlib package in the binary's zipapp
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 10 Aug 2023 13:45:42 +0000 (09:45 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 30 Aug 2023 14:10:50 +0000 (10:10 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Pair-programmed-with: Adam King <adking@redhat.com>
Co-authored-by: Adam King <adking@redhat.com>
src/cephadm/build.py

index 4264b814f1ef7ccc982cf2cdad37f0f8b2de913a..0680abad21a09fc307f97d0444c06d2b984f0a48 100755 (executable)
@@ -63,12 +63,12 @@ def _build(dest, src, versioning_vars=None):
         if os.path.isfile("requirements.txt"):
             _install_deps(tempdir)
         log.info("Copying contents")
-        # TODO: currently the only file relevant to a compiled cephadm is the
-        # cephadm.py file. Once cephadm is broken up into multiple py files
-        # (and possibly other libs from python-common, etc) we'll want some
-        # sort organized structure to track what gets copied into the
-        # dir to be zipped. For now we just have a simple call to copy
-        # (and rename) the one file we care about.
+        # cephadmlib is cephadm's private library of modules
+        shutil.copytree(
+            "cephadmlib", tempdir / "cephadmlib", ignore=_ignore_cephadmlib
+        )
+        # cephadm.py is cephadm's main script for the "binary"
+        # this must be renamed to __main__.py for the zipapp
         shutil.copy("cephadm.py", tempdir / "__main__.py")
         if versioning_vars:
             generate_version_file(versioning_vars, tempdir / "_version.py")
@@ -77,6 +77,15 @@ def _build(dest, src, versioning_vars=None):
         shutil.rmtree(tempdir)
 
 
+def _ignore_cephadmlib(source_dir, names):
+    # shutil.copytree callback: return the list of names *to ignore*
+    return [
+        name
+        for name in names
+        if name.endswith(("~", ".old", ".swp", ".pyc", ".pyo", "__pycache__"))
+    ]
+
+
 def _compile(dest, tempdir):
     """Compile the zipapp."""
     log.info("Byte-compiling py to pyc")