You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since it fails while trying to import the exception type that it raises (GitError), the only way to catch the error is with a try: ... except Exception: block, which is needlessly wide. It would be nice if a better pattern was available for conditional use of the package.
Thanks for reporting this issue! I believe that the problem originates here, and could be solved by delaying that particular operation until that _flag_map is actually required. This would also decrease the time it takes to import GitPython.
It looks like a decent python exercise to do that, in case one would want to contribute a PR :).
Personally I believe at the time of import, nothing but ImportErrors should be thrown, which is clearly violated here.
A possible solution is that of #640 where import git succeeds with or without git available. This then allows the user to dynamically set their git path after import (as would be the case if a program needed to first read and parse a config file which contains the git path).
The above mentioned PR introduces a git.refresh function which allows the user to set their git path during runtime and hence refreshes both the GIT_PYTHON_GIT_EXECUTABLE in the git.cmd.Git object but also the _flag_map in the git.remote.FetchInfo object.
Activity
vidartf commentedon Jun 12, 2017
(this was using version 2.1.5)
vidartf commentedon Jun 12, 2017
It seems like this was introduced in 2.1.4 (2.1.3 imports flawlessly even without git on path).
scottbelden commentedon Jun 12, 2017
Wow, I was literally just about to make this ticket. At the moment my only option to conditionally import is something like:
But as @vidartf notes, that's less than ideal.
Byron commentedon Jun 17, 2017
Thanks for reporting this issue! I believe that the problem originates here, and could be solved by delaying that particular operation until that
_flag_mapis actually required. This would also decrease the time it takes to import GitPython.It looks like a decent python exercise to do that, in case one would want to contribute a PR :).
Personally I believe at the time of import, nothing but ImportErrors should be thrown, which is clearly violated here.
kenodegard commentedon Jul 13, 2017
A possible solution is that of #640 where
import gitsucceeds with or without git available. This then allows the user to dynamically set their git path after import (as would be the case if a program needed to first read and parse a config file which contains the git path).The above mentioned PR introduces a
git.refreshfunction which allows the user to set their git path during runtime and hence refreshes both theGIT_PYTHON_GIT_EXECUTABLEin thegit.cmd.Gitobject but also the_flag_mapin the git.remote.FetchInfo object.Swallow git import exception
Swallow git import exception
Swallow git import exception
Byron commentedon Sep 28, 2017
This should be fixed with the latest, upcoming release,
v2.1.7.version up
version up