Skip to content

Fails on import with custom exception #637

Description

@vidartf

On Windows, without git available on path, the following happens on import of GitPython:

[packagestack]
fromgit.excimportGitErrorFile"C:\Miniconda3\lib\site-packages\git\__init__.py", line45, in<module>fromgit.repoimportRepo# @NoMove @IgnorePep8File"C:\Miniconda3\lib\site-packages\git\repo\__init__.py", line4, in<module>from .baseimport*File"C:\Miniconda3\lib\site-packages\git\repo\base.py", line31, in<module>fromgit.remoteimportRemote, add_progress, to_progress_instanceFile"C:\Miniconda3\lib\site-packages\git\remote.py", line190, in<module>classFetchInfo(object):
File"C:\Miniconda3\lib\site-packages\git\remote.py", line219, inFetchInfov=Git().version_info[:2]
File"C:\Miniconda3\lib\site-packages\git\cmd.py", line461, inversion_inforeturnself._version_infoFile"C:\Miniconda3\lib\site-packages\git\cmd.py", line424, in__getattr__returnLazyMixin.__getattr__(self, name)
File"C:\Miniconda3\lib\site-packages\gitdb\util.py", line256, in__getattr__self._set_cache_(attr)
File"C:\Miniconda3\lib\site-packages\git\cmd.py", line444, in_set_cache_version_numbers=self._call_process('version').split(' ')[2]
File"C:\Miniconda3\lib\site-packages\git\cmd.py", line877, in_call_processreturnself.execute(call, **exec_kwargs)
File"C:\Miniconda3\lib\site-packages\git\cmd.py", line602, inexecuteraiseGitCommandNotFound(command, err)
git.exc.GitCommandNotFound: Cmd('git') notfounddueto: FileNotFoundError('[WinError 2] The system cannot find the file specified')
cmdline: gitversion

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions