Patchwork [1,of,5] setup: fail if we cannot determine the version number

login
register
mail settings
Submitter Adam Simpkins
Date June 26, 2017, 6:37 p.m.
Message ID <532781f3e93229a495ca.1498502260@devbig125.prn1.facebook.com>
Download mbox | patch
Permalink /patch/21739/
State Accepted
Headers show

Comments

Adam Simpkins - June 26, 2017, 6:37 p.m.
# HG changeset patch
# User Adam Simpkins <simpkins@fb.com>
# Date 1498501890 25200
#      Mon Jun 26 11:31:30 2017 -0700
# Node ID 532781f3e93229a495ca33d7569787d4bab88756
# Parent  a49ab7f5e7e765a94a1dfab2ee3b1da695789eb6
setup: fail if we cannot determine the version number

If running hg fails, exit the setup script unsuccessfully, rather than
proceeding to use a bogus version of "+0-".  Using an invalid version number
causes various tests to fail later.  Failing early makes it easier to identify
the source of the problem.

It is currently easy for setup.py to fail this way since it sets HGRCPTH to the
empty string before running "hg", which may often disable extensions necessary
to interact with the local repository.

Patch

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -184,6 +184,12 @@ 
     cmd = [sys.executable, 'hg', 'log', '-r', '.', '--template', '{tags}\n']
     numerictags = [t for t in runhg(cmd, env).split() if t[0].isdigit()]
     hgid = runhg([sys.executable, 'hg', 'id', '-i'], env).strip()
+    if not hgid:
+        # Bail out if hg is having problems interacting with this repository,
+        # rather than falling through and producing a bogus version number.
+        # Continuing with an invalid version number will break extensions
+        # that define minimumhgversion.
+        raise SystemExit('Unable to determine hg version from local repository')
     if numerictags: # tag(s) found
         version = numerictags[-1]
         if hgid.endswith('+'): # propagate the dirty status to the tag