Patchwork D8260: git: hide pygit2 imports from gendoc and other scripts not using demandimport

login
register
mail settings
Submitter phabricator
Date March 7, 2020, 9:45 p.m.
Message ID <differential-rev-PHID-DREV-sbnjgj3e3nz2cpcr7g53-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45610/
State Superseded
Headers show

Comments

phabricator - March 7, 2020, 9:45 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Without this, I can't seem to build a working rpm for my fedora machine.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/git/__init__.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - March 9, 2020, 9:45 a.m.
This revision now requires changes to proceed.
pulkit added a comment.
pulkit requested changes to this revision.


  `test-duplicateoptions.py` is failing with this patch. I dropped this from my push list, stripping the patch was resulting in complex state for me, so I used prune, kindly use touch locally.

REPOSITORY
  rHG Mercurial

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

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

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

Patch

diff --git a/hgext/git/__init__.py b/hgext/git/__init__.py
--- a/hgext/git/__init__.py
+++ b/hgext/git/__init__.py
@@ -8,8 +8,6 @@ 
 
 import os
 
-import pygit2
-
 from mercurial.i18n import _
 
 from mercurial import (
@@ -22,12 +20,21 @@ 
     util,
 )
 
-from . import (
-    dirstate,
-    gitlog,
-    gitutil,
-    index,
-)
+# gendoc.py ends up causing all extensions to be imported, so we need
+# to hide attempts to load pygit2 from it so that it can finish
+# generating documentation.
+try:
+    import pygit2
+except ImportError:
+    pygit2 = None
+
+if pygit2 is not None:
+    from . import (
+        dirstate,
+        gitlog,
+        gitutil,
+        index,
+    )
 
 
 # TODO: extract an interface for this in core
@@ -250,6 +257,7 @@ 
 
 
 def extsetup(ui):
+    assert pygit2 is not None, 'git extension requires pygit2'
     extensions.wrapfunction(localrepo, b'makestore', _makestore)
     extensions.wrapfunction(localrepo, b'makefilestorage', _makefilestorage)
     # Inject --git flag for `hg init`