https://github.com/python/cpython/commit/ff4ad2ea89ed4515340f66657505b6c0deb9a16e
commit: ff4ad2ea89ed4515340f66657505b6c0deb9a16e
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: Yhg1s <[email protected]>
date: 2024-09-03T01:21:40+02:00
summary:

[3.12] gh-123458: Skip SBOM generation if no git repository is detected 
(GH-123507) (#123615)

gh-123458: Skip SBOM generation if no git repository is detected (GH-123507)
(cherry picked from commit db42934270c5c23be9f6804cad98dfd8234caf6f)

Co-authored-by: Seth Michael Larson <[email protected]>

files:
M Tools/build/generate_sbom.py

diff --git a/Tools/build/generate_sbom.py b/Tools/build/generate_sbom.py
index 1b000c3b16a17a..9cc89b8caee150 100644
--- a/Tools/build/generate_sbom.py
+++ b/Tools/build/generate_sbom.py
@@ -96,6 +96,19 @@ def error_if(value: bool, error_message: str) -> None:
         sys.exit(1)
 
 
+def is_root_directory_git_index() -> bool:
+    """Checks if the root directory is a git index"""
+    try:
+        subprocess.check_call(
+            ["git", "-C", str(CPYTHON_ROOT_DIR), "rev-parse"],
+            stdout=subprocess.DEVNULL,
+            stderr=subprocess.DEVNULL,
+        )
+    except subprocess.CalledProcessError:
+        return False
+    return True
+
+
 def filter_gitignored_paths(paths: list[str]) -> list[str]:
     """
     Filter out paths excluded by the gitignore file.
@@ -341,6 +354,11 @@ def create_externals_sbom() -> None:
 
 
 def main() -> None:
+    # Don't regenerate the SBOM if we're not a git repository.
+    if not is_root_directory_git_index():
+        print("Skipping SBOM generation due to not being a git repository")
+        return
+
     create_source_sbom()
     create_externals_sbom()
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to