3962: Mercurial repositories not usable on Windows Reviewboard install when hg is installed with 'pip'

phi****@gmai***** (Google Code) (Is this you? Claim this profile.)
What version are you running?
  2.0.19

What's the URL of the page containing the problem?
  /reviewboard/r/new/

What steps will reproduce the problem?
1. Install Reviewboard on a Windows server
2. Add a Mercurial repository to Reviewboard
3. Note that the Mercurial repository does not appear in the "New Review Request" screen.

What is the expected output? What do you see instead?
  I expect that it be possible to create review requests against the repository, but the repository does not appear in the request list.

Additionally, I get this error in my Apache log:

[Wed Sep 09 15:01:14.473213 2015] [wsgi:error] [pid 1752:tid 952] ERROR:root:Error loading SCMTool for repository "Test Repository" (ID 2)
[Wed Sep 09 15:01:14.473213 2015] [wsgi:error] [pid 1752:tid 952] Traceback (most recent call last):
[Wed Sep 09 15:01:14.473213 2015] [wsgi:error] [pid 1752:tid 952]   File "c:\\reviewboard\\env\\Lib\\site-packages\\reviewboard-2.0.19-py2.7.egg\\reviewboard\\reviews\\views.py", line 249, in new_review_request
[Wed Sep 09 15:01:14.473213 2015] [wsgi:error] [pid 1752:tid 952]     scmtool = repo.get_scmtool()
[Wed Sep 09 15:01:14.473213 2015] [wsgi:error] [pid 1752:tid 952]   File "c:\\reviewboard\\env\\Lib\\site-packages\\reviewboard-2.0.19-py2.7.egg\\reviewboard\\scmtools\\models.py", line 231, in get_scmtool
[Wed Sep 09 15:01:14.473213 2015] [wsgi:error] [pid 1752:tid 952]     return cls(self)
[Wed Sep 09 15:01:14.473213 2015] [wsgi:error] [pid 1752:tid 952]   File "c:\\reviewboard\\env\\Lib\\site-packages\\reviewboard-2.0.19-py2.7.egg\\reviewboard\\scmtools\\hg.py", line 28, in __init__
[Wed Sep 09 15:01:14.473213 2015] [wsgi:error] [pid 1752:tid 952]     raise ImportError
[Wed Sep 09 15:01:14.473213 2015] [wsgi:error] [pid 1752:tid 952] ImportError


What operating system are you using? What browser?
  Windows Server 2008 RC2 server, Windows 7 client, latest Google Chrome

Please provide any additional information below.

  On my server system, Mercurial was installed in the virtualenv which hosts Reviewboard. Line 25 of scmtools/hg.py attempts to check whether Mercurial is installed:

        if not is_exe_in_path('hg'):
            # This is technically not the right kind of error, but it's the
            # pattern we use with all the other tools.
            raise ImportError

And djblets.util.filesystem.py : is_exe_in_path(name) implements this thus:

    if sys.platform == 'win32' and not name.endswith('.exe'):
        name += ".exe"

    for dir in os.environ['PATH'].split(os.pathsep):
        if os.path.exists(os.path.join(dir, name)):
            return True

    return False

Clearly this will only work on Windows if the Mercurial executable is a true Windows executable and not a batch file or similar.

The problem is that in my virtualenv (where Mercurial was installed with "pip install mercurial"), the Mercurial binary *is* a batch file (in C:\ReviewBoard\Scripts\hg.bat).

This is not an issue if a Windows Mercurial distribution e.g. TortoiseHg is installed, as this includes a compiled executable to invoke Mercurial.
chipx86
#1 chipx86
We're happy to accept patches to improve this sort of thing (please post to https://reviews.reviewboard.org/0, but we don't officially support Windows, so we aren't doing any active bug fixing there ourselves. If you can get a patch sent our way, we'll include it for the next release.

Seems like a good option would be to extend Djblets to support ".bat" extensions as well.
  • +NeedInfo
  • +Project-Djblets
    +OpSys-Windows