danvk / webdiff

Two-column web-based git difftool
Apache License 2.0
269 stars 39 forks source link

Python TypeError when calling webdiff with a pull request #number. #126

Closed nei-oliveiraneto closed 6 years ago

nei-oliveiraneto commented 6 years ago
C:\SAPDevelop\s4hana\farmers-platform (develop -> origin)
λ webdiff #80
Traceback (most recent call last):
  File "C:\Program Files\Python36\Scripts\webdiff-script.py", line 11, in <module>
    load_entry_point('webdiff==0.14.0', 'console_scripts', 'webdiff')()
  File "c:\program files\python36\lib\site-packages\webdiff\app.py", line 275, in run
    parsed_args = argparser.parse(sys.argv[1:], VERSION)
  File "c:\program files\python36\lib\site-packages\webdiff\argparser.py", line 53, in parse
    owner, repo, num = github_fetcher.get_pr_repo(num)
  File "c:\program files\python36\lib\site-packages\webdiff\github_fetcher.py", line 77, in get_pr_repo
    remotes = _get_github_remotes()
  File "c:\program files\python36\lib\site-packages\webdiff\github_fetcher.py", line 106, in _get_github_remotes
    remotes = _uniqueify([remote for remote in _get_remotes().values()
  File "c:\program files\python36\lib\site-packages\webdiff\github_fetcher.py", line 138, in _get_remotes
    return _parse_remotes(remote_lines)
  File "c:\program files\python36\lib\site-packages\webdiff\github_fetcher.py", line 131, in _parse_remotes
    for remote in map(_parse_remote, remote_lines)
  File "c:\program files\python36\lib\site-packages\webdiff\github_fetcher.py", line 130, in <dictcomp>
    return {remote.group('name'): remote
  File "c:\program files\python36\lib\site-packages\webdiff\github_fetcher.py", line 126, in _parse_remote
    return re.match(https_push_re, remote) or re.match(ssh_push_re, remote)
  File "c:\program files\python36\lib\re.py", line 172, in match
    return _compile(pattern, flags).match(string)
TypeError: cannot use a string pattern on a bytes-like object

I tried running directly from GitHub, but this is what happens:

C:\SAPDevelop\s4hana\farmers-platform (develop -> origin)
λ webdiff https://github.wdf.sap.corp/Farmer-Information-Platform/fip/pull/80
Traceback (most recent call last):
  File "c:\program files\python36\lib\site-packages\webdiff\app.py", line 275, in run
    parsed_args = argparser.parse(sys.argv[1:], VERSION)
  File "c:\program files\python36\lib\site-packages\webdiff\argparser.py", line 56, in parse
    raise UsageError('You must either specify two files, two '
webdiff.argparser.UsageError: You must either specify two files, two directories or a github pull request URL/#number

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python36\Scripts\webdiff-script.py", line 11, in <module>
    load_entry_point('webdiff==0.14.0', 'console_scripts', 'webdiff')()
  File "c:\program files\python36\lib\site-packages\webdiff\app.py", line 277, in run
    sys.stderr.write('Error: %s\n\n' % e.message)
AttributeError: 'UsageError' object has no attribute 'message'

If anyone would like anymore info, just ask.

What I've been doing is clone the repo again in a separate directory, checking-out each of the branches I want to compare and calling webdiff locally with the paths of the dirs.

daytonb commented 6 years ago

I have only used webdiff locally, so when I made it work with Python3, that's the way I tested it. That first error message is what you get when you as Python3's regex match to search for a str pattern (unicode) in a bytes object. Probably, the string we get from the github_fetcher is actually a bytes object. I'll try to take a closer look later at that. We can always just put in a bit of code to force the pattern and the string to both by str or to both be bytes.

The other error is another Python3 incompatibility. Python3's built in exception Exception doesn't have a message attribute. However our exception only has a single argument, so just doing sys.stderr.write('error: %s\n\n' % e) will work just fine and work in Python2 and Python3.

nei-oliveiraneto commented 6 years ago

Thank you for being so readily available. It ran absolutely fine with Python 2.7. Props.

daytonb commented 6 years ago

Since there was no activity in reviewing these commits I am using my privileges as a maintainer to merge the pull request which closes this issue.