Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFails on import with custom exception #637
Comments
(this was using version 2.1.5) |
It seems like this was introduced in 2.1.4 (2.1.3 imports flawlessly even without git on path). |
Wow, I was literally just about to make this ticket. At the moment my only option to conditionally import is something like: try:
import git
except:
pass But as @vidartf notes, that's less than ideal. |
Thanks for reporting this issue! I believe that the problem originates here, and could be solved by delaying that particular operation until that 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 The above mentioned PR introduces a |
See the following issue which explains why we can't catch a specific exception type: gitpython-developers/GitPython#637
See the following issue which explains why we can't catch a specific exception type: gitpython-developers/GitPython#637
See the following issue which explains why we can't catch a specific exception type: gitpython-developers/GitPython#637
This should be fixed with the latest, upcoming release, |
On Windows, without git available on path, the following happens on import of GitPython:
Since it fails while trying to import the exception type that it raises (
GitError
), the only way to catch the error is with atry: ... except Exception:
block, which is needlessly wide. It would be nice if a better pattern was available for conditional use of the package.