Commits

Lorenzo Gil Sánchez  committed 1cd3281

Make the Trac dependency optional by checking it at import time

  • Participants
  • Parent commits 56949f9

Comments (0)

Files changed (1)

File hghooks/trachooks.py

 
 from pkg_resources import iter_entry_points
 
-from trac.env import open_environment
-from trac.ticket import Ticket
-from trac.ticket.notification import TicketNotifyEmail
-from trac.ticket.web_ui import TicketModule
-from trac.util.datefmt import utc
+try:
+    from trac.env import open_environment
+    from trac.ticket import Ticket
+    from trac.ticket.notification import TicketNotifyEmail
+    from trac.ticket.web_ui import TicketModule
+    from trac.util.datefmt import utc
+    HAS_TRAC = True
+except ImportError:
+    HAS_TRAC = False
 
 from hghooks import CheckerManager
 
 
 
 def ticket_checker(ui, repo, hooktype, node, pending, **kwargs):
+    if not HAS_TRAC:
+        ui.warn('You need the trac python package to use the ticket_checker')
+        return True  # failure
+
     checker_manager = CheckerManager(ui, repo, node)
     trac_env = ui.config('trac', 'environment')
     if trac_env is None:
 
 
 def ticket_updater(ui, repo, hooktype, node, source, url):
+    if not HAS_TRAC:
+        ui.warn('You need the trac python package to use the ticket_updater')
+        return True  # failure
+
     trac_env = ui.config('trac', 'environment')
     if trac_env is None:
         ui.warn('You must set the environment option in the [trac] section'