davidfoerster/aptsources-cleanup

UnboundLocalError: local variable 'git' referenced before assignment

Michael-E-Rose opened this issue · 3 comments

Trying to make the code run with Python 3.6.7 on Ubuntu 16.04:

Traceback (most recent call last):
  File "/home/michaelerose/Downloads/aptsources-cleanup-0.1.5/src/aptsources_cleanup/util/version/__init__.py", line 109, in from_repo
    import git
ModuleNotFoundError: No module named 'git'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./__main__.py", line 9, in <module>
    runpy.run_module('aptsources_cleanup', run_name='__main__')
  File "/usr/lib/python3.6/runpy.py", line 201, in run_module
    mod_name, mod_spec, code = _get_module_details(mod_name)
  File "/usr/lib/python3.6/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/home/michaelerose/Downloads/aptsources-cleanup-0.1.5/src/aptsources_cleanup/__init__.py", line 33, in <module>
    __version__ = str(__version__())
  File "/home/michaelerose/Downloads/aptsources-cleanup-0.1.5/src/aptsources_cleanup/util/version/__init__.py", line 154, in get_version
    _version = version_info.load()
  File "/home/michaelerose/Downloads/aptsources-cleanup-0.1.5/src/aptsources_cleanup/util/version/__init__.py", line 101, in load
    return cls.from_repo(version)
  File "/home/michaelerose/Downloads/aptsources-cleanup-0.1.5/src/aptsources_cleanup/util/version/__init__.py", line 111, in from_repo
    except (ImportError, git.exc.InvalidGitRepositoryError):
UnboundLocalError: local variable 'git' referenced before assignment

It seems git.exc.InvalidGitRepositoryError can't be used when git cannot be loaded.

BTW: If you use the git package only to get version information, I'd recommend using pbr instead. Much easier.

Thanks for your report. I understand the issue and found and fixed the logical flaw in the code. I’ll release a fix in the next hours.

The issue was due an incomplete fix of #10. All should be fixed now in bbd62b8. Please try the most recent release v0.1.5.1.

It's fixed and works very well, thanks a lot!