Don't require git or MonkeyType to be installed - #705
Open
svaningelgem wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two more things that stop
df.scripts.exportrunning 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.
gitis assumed to be installedget_git_root,get_commit_hashandget_branch_namecatch onlyCalledProcessError, which is what git returns when you are outside a repository. If git is not installed at all,subprocess.check_outputraisesFileNotFoundError, and nothing catches it:get_git_root's own docstring says it returnsNonewhen 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()callsget_git_root(), anddf.scripts.exportcallsget_test_sample()before it exports anything. So exporting a model on a machine without git fails before it starts — and installingdeepfilternetfrom PyPI does not install git.Widened to
OSError, which coversFileNotFoundErrorandPermissionError. Verified by running with an emptyPATH, so thegitexecutable cannot be found: all three returnNoneafter the change.2. The export refuses to run without MonkeyType, which it never uses
monkeytypeis imported and then never referenced — thenoqa: F401says as much. It is not a dependency ofdeepfilternet, so a plainpip install deepfilternetgives:and exits, for a package the export does not use.
Worth mentioning because the failure is actively misleading: on some setups
import monkeytypefails for reasons that have nothing to do with MonkeyType — it importssqlite3transitively, 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.