Patchwork D6959: setup: switch to having setup.py generate an hg script

login
register
mail settings
Submitter phabricator
Date Oct. 4, 2019, 5:11 p.m.
Message ID <differential-rev-PHID-DREV-s4hub7jf6q3gqj6dt654-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/41950/
State New
Headers show

Comments

phabricator - Oct. 4, 2019, 5:11 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This gives us a more-standard entry_points setup and lets us skip the
  step of generating the interpreter shebang etc, easing some Python 3
  work.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6959

AFFECTED FILES
  hg
  setup.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - Oct. 4, 2019, 5:23 p.m.
durin42 added a comment.
durin42 planned changes to this revision.


  This currently breaks a bunch of stuff, I think because the installed hg isn't on $PATH?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6959/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6959

To: durin42, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -206,7 +206,7 @@ 
         with open(path, 'wb') as fh:
             fh.write(content)
 
-scripts = ['hg']
+scripts = []
 if os.name == 'nt':
     # We remove hg.bat if we are able to build hg.exe.
     scripts.append('contrib/win32/hg.bat')
@@ -1504,6 +1504,11 @@ 
       package_data=packagedata,
       cmdclass=cmdclass,
       distclass=hgdist,
+      entry_points=[
+          'console_scripts': [
+              'hg = mercurial.main:main',
+          ],
+      ],
       options={
           'py2exe': {
               'bundle_files': 3,
diff --git a/hg b/hg
--- a/hg
+++ b/hg
@@ -27,17 +27,5 @@ 
         libdir = os.path.abspath(libdir)
     sys.path.insert(0, libdir)
 
-from hgdemandimport import tracing
-with tracing.log('hg script'):
-    # enable importing on demand to reduce startup time
-    try:
-        if sys.version_info[0] < 3 or sys.version_info >= (3, 6):
-            import hgdemandimport; hgdemandimport.enable()
-    except ImportError:
-        sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" %
-                         ' '.join(sys.path))
-        sys.stderr.write("(check your install and PYTHONPATH)\n")
-        sys.exit(-1)
-
-    from mercurial import dispatch
-    dispatch.run()
+from mercurial import main
+main.main()