From 1e27cba64f9bed06bb37cca46d743bf1ff27998e Mon Sep 17 00:00:00 2001 From: Steven Van Ingelgem Date: Fri, 14 Aug 2026 07:57:34 +0200 Subject: [PATCH] Don't require git or MonkeyType to be installed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit get_git_root, get_commit_hash and get_branch_name catch only CalledProcessError, which is what git returns when you are outside a repository. If git is not installed at all, check_output raises FileNotFoundError instead and nothing catches it: get_git_root() raised FileNotFoundError: [WinError 2] The system cannot find the file specified get_git_root's own docstring says it returns None when not called within a repository, so a missing git binary should give the same answer. Widened to OSError, which covers FileNotFoundError and PermissionError. Verified by running with an empty PATH: all three now return None. This matters beyond tidiness because get_test_sample -> get_git_root is on the path to df.scripts.export, so exporting a model on a machine without git crashes before it starts. Separately, export.py refuses to run unless MonkeyType is importable, but only imports it (noqa: F401) and never uses it. pip install deepfilternet does not include MonkeyType, so the export exits(1) demanding a package it does not need. Removed the check. If it is there for a side effect I have missed, it should be a declared dependency rather than a runtime guard — happy to change it to that instead. --- DeepFilterNet/df/scripts/export.py | 7 ------- DeepFilterNet/df/utils.py | 12 +++++++----- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/DeepFilterNet/df/scripts/export.py b/DeepFilterNet/df/scripts/export.py index ea5afd752..a427a4a56 100644 --- a/DeepFilterNet/df/scripts/export.py +++ b/DeepFilterNet/df/scripts/export.py @@ -286,13 +286,6 @@ def export( def main(args): - try: - import monkeytype # noqa: F401 - except ImportError: - print("Failed to import monkeytype. Please install it via") - print("$ pip install MonkeyType") - exit(1) - print(args) model, df_state, _, epoch = init_df( args.model_base_dir, diff --git a/DeepFilterNet/df/utils.py b/DeepFilterNet/df/utils.py index cea7a9b3e..0f86b8201 100644 --- a/DeepFilterNet/df/utils.py +++ b/DeepFilterNet/df/utils.py @@ -142,7 +142,9 @@ def get_git_root(): git_local_dir = os.path.dirname(os.path.abspath(__file__)) args = ["git", "-C", git_local_dir, "rev-parse", "--show-toplevel"] return subprocess.check_output(args).strip().decode() - except subprocess.CalledProcessError: + except (subprocess.CalledProcessError, OSError): + # CalledProcessError: not inside a repository. + # OSError (FileNotFoundError): git is not installed at all. return None @@ -154,8 +156,8 @@ def get_commit_hash(): return None args = ["git", "-C", git_dir, "rev-parse", "--short", "--verify", "HEAD"] return subprocess.check_output(args).strip().decode() - except subprocess.CalledProcessError: - # probably not in git repo + except (subprocess.CalledProcessError, OSError): + # not in a git repo, or git is not installed return None @@ -168,8 +170,8 @@ def get_branch_name(): git_dir = os.path.dirname(os.path.abspath(__file__)) args = ["git", "-C", git_dir, "rev-parse", "--abbrev-ref", "HEAD"] branch = subprocess.check_output(args).strip().decode() - except subprocess.CalledProcessError: - # probably not in git repo + except (subprocess.CalledProcessError, OSError): + # not in a git repo, or git is not installed branch = None return branch