davidfoerster / aptsources-cleanup

Detects and interactively deactivates duplicate Apt source entries and deletes sources list files without valid enabled source entries (as requested in https://askubuntu.com/a/762815/175814).
MIT License
667 stars 85 forks source link

UnboundLocalError: local variable 'git' referenced before assignment #13

Closed Michael-E-Rose closed 5 years ago

Michael-E-Rose commented 5 years ago

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.

davidfoerster commented 5 years ago

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.

davidfoerster commented 5 years ago

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

Michael-E-Rose commented 5 years ago

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