Open ReimarBauer opened 1 month ago
Catch specific exceptions instead of general ValueError and BrokenPipeError. Consider git.exc.InvalidGitRepositoryError
Can I work on this issue?
Welcome @YashaswiniTB I assigned it to you.
This looks to me currently a bit overengeenered. On github also each worker creates anyway a new tmp dir. Is there any case on local development where we need a second information about the state of the git repository?
try: import git except ImportError: SHA = "" else: path = os.path.dirname(os.path.realpath(__file__)) repo = git.Repo(path, search_parent_directories=True) logging.debug(path) try: # this is for local development important to get a fresh named tmpdir SHA = repo.head.object.hexsha[0:10] except (ValueError, BrokenPipeError) as ex: logging.debug("Unknown Problem: %s", ex) # mounted dir in docker container and owner is not root SHA = "" ROOT_FS = TempFS(identifier=f"msui{SHA}")
The SHA is being used as an identifier for the TempFS, presumably to create unique and consistent temporary filesystems during local development. However, as you pointed out, in many environments (like GitHub Actions), a new temporary directory is created for each run anyway, making this extra identifier potentially unnecessary. For local development, having the SHA in the identifier could potentially help in tracking changes across different commits or branches, but this benefit might be minimal in most cases. The current implementation has error handling for cases where the git repository information can't be retrieved, falling back to an empty string for the SHA. import os import tempfile import logging
def get_git_sha(): try: from git import Repo except ImportError: logging.debug("GitPython not installed, skipping SHA retrieval") return ""
try:
path = os.path.dirname(os.path.realpath(__file__))
repo = Repo(path, search_parent_directories=True)
sha = repo.head.object.hexsha[:10]
logging.debug(f"Git SHA: {sha}")
return sha
except Exception as ex:
logging.debug(f"Failed to get Git SHA: {ex}")
return ""
unique_id = f"msui{get_git_sha()}" ROOT_FS = tempfile.mkdtemp(prefix=unique_id)
This looks to me currently a bit overengeenered. On github also each worker creates anyway a new tmp dir. Is there any case on local development where we need a second information about the state of the git repository?