Skip to content

Don't require git or MonkeyType to be installed - #705

Open
svaningelgem wants to merge 1 commit into
Rikorose:mainfrom
svaningelgem:fix/no-git-and-monkeytype
Open

Don't require git or MonkeyType to be installed#705
svaningelgem wants to merge 1 commit into
Rikorose:mainfrom
svaningelgem:fix/no-git-and-monkeytype

Conversation

@svaningelgem

Copy link
Copy Markdown

Two more things that stop df.scripts.export running on a clean machine. Independent of #702, so it is a separate branch — split up so you can take them one at a time rather than review one large diff.

1. git is assumed to be installed

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, subprocess.check_output raises FileNotFoundError, and nothing catches it:

get_git_root() raised FileNotFoundError: [WinError 2] The system cannot find the file specified
get_commit_hash() raised FileNotFoundError: [WinError 2] The system cannot find the file specified
get_branch_name() 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 git repository, so a missing git binary should give the same answer rather than propagating.

This is not merely cosmetic: get_test_sample() calls get_git_root(), and df.scripts.export calls get_test_sample() before it exports anything. So exporting a model on a machine without git fails before it starts — and installing deepfilternet from PyPI does not install git.

Widened to OSError, which covers FileNotFoundError and PermissionError. Verified by running with an empty PATH, so the git executable cannot be found: all three return None after the change.

2. The export refuses to run without MonkeyType, which it never uses

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)

monkeytype is imported and then never referenced — the noqa: F401 says as much. It is not a dependency of deepfilternet, so a plain pip install deepfilternet gives:

Failed to import monkeytype. Please install it via
$ pip install MonkeyType

and exits, for a package the export does not use.

Worth mentioning because the failure is actively misleading: on some setups import monkeytype fails for reasons that have nothing to do with MonkeyType — it imports sqlite3 transitively, so an unrelated libstdc++/CXXABI mismatch in the interpreter surfaces as "Failed to import monkeytype", and installing MonkeyType does not help. That cost me a while to unpick.

I removed the guard. If it is there for a side effect I have not spotted, it should be a declared dependency instead of a runtime check — happy to switch it to that if you prefer.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant