setup.py
changeset 51161 f816ca29a285
parent 51160 3c5b66d03c37
child 51559 ee132657647d
equal deleted inserted replaced
51160:3c5b66d03c37 51161:f816ca29a285
   296 
   296 
   297     if os.name != 'nt' or not os.path.exists("hg.exe"):
   297     if os.name != 'nt' or not os.path.exists("hg.exe"):
   298         if attempt(hgcmd + check_cmd, hgenv):
   298         if attempt(hgcmd + check_cmd, hgenv):
   299             return hgcommand(hgcmd, hgenv)
   299             return hgcommand(hgcmd, hgenv)
   300 
   300 
   301     # Fall back to trying the local hg installation.
   301     # Fall back to trying the local hg installation (pure python)
       
   302     repo_hg = os.path.join(os.path.dirname(__file__), 'hg')
   302     hgenv = localhgenv()
   303     hgenv = localhgenv()
   303     hgcmd = [sys.executable, 'hg']
   304     hgcmd = [sys.executable, repo_hg]
       
   305     if attempt(hgcmd + check_cmd, hgenv):
       
   306         return hgcommand(hgcmd, hgenv)
       
   307     # Fall back to trying the local hg installation (whatever we can)
       
   308     hgenv = localhgenv(pure_python=False)
       
   309     hgcmd = [sys.executable, repo_hg]
   304     if attempt(hgcmd + check_cmd, hgenv):
   310     if attempt(hgcmd + check_cmd, hgenv):
   305         return hgcommand(hgcmd, hgenv)
   311         return hgcommand(hgcmd, hgenv)
   306 
   312 
   307     eprint("/!\\")
   313     eprint("/!\\")
   308     eprint(r"/!\ Unable to find a working hg binary")
   314     eprint(r"/!\ Unable to find a working hg binary")
   320         else:
   326         else:
   321             eprint(r"/!\     exception:  ", res[1])
   327             eprint(r"/!\     exception:  ", res[1])
   322     return None
   328     return None
   323 
   329 
   324 
   330 
   325 def localhgenv():
   331 def localhgenv(pure_python=True):
   326     """Get an environment dictionary to use for invoking or importing
   332     """Get an environment dictionary to use for invoking or importing
   327     mercurial from the local repository."""
   333     mercurial from the local repository."""
   328     # Execute hg out of this directory with a custom environment which takes
   334     # Execute hg out of this directory with a custom environment which takes
   329     # care to not use any hgrc files and do no localization.
   335     # care to not use any hgrc files and do no localization.
   330     env = {
   336     env = {
   331         'HGMODULEPOLICY': 'py',
       
   332         'HGRCPATH': '',
   337         'HGRCPATH': '',
   333         'LANGUAGE': 'C',
   338         'LANGUAGE': 'C',
   334         'PATH': '',
   339         'PATH': '',
   335     }  # make pypi modules that use os.environ['PATH'] happy
   340     }  # make pypi modules that use os.environ['PATH'] happy
       
   341     if pure_python:
       
   342         env['HGMODULEPOLICY'] = 'py'
   336     if 'LD_LIBRARY_PATH' in os.environ:
   343     if 'LD_LIBRARY_PATH' in os.environ:
   337         env['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH']
   344         env['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH']
   338     if 'SystemRoot' in os.environ:
   345     if 'SystemRoot' in os.environ:
   339         # SystemRoot is required by Windows to load various DLLs.  See:
   346         # SystemRoot is required by Windows to load various DLLs.  See:
   340         # https://bugs.python.org/issue13524#msg148850
   347         # https://bugs.python.org/issue13524#msg148850