def critique(ui, repo, entire=False, node=None, **kwargs): """Perform a critique of a changeset.""" demandimport.disable() from flake8.engine import get_style_guide from pycodestyle import DiffReport, parse_udiff style = get_style_guide(parse_argv=False, ignore='E128') ctx = repo[node] if not entire: diff = ''.join(ctx.diff()) style.options.selected_lines = {} for k, v in parse_udiff(diff).items(): if k.startswith('./'): k = k[2:] style.options.selected_lines[k] = v style.options.report = DiffReport(style.options) deleted = repo.status(ctx.p1().node(), ctx.node())[2] files = [f for f in ctx.files() if f.endswith('.py') and f not in deleted] for f in files: data = ctx.filectx(f).data() style.input_file(f, lines=data.splitlines()) demandimport.enable()
def critique(ui, repo, entire=False, node=None, **kwargs): """Perform a critique of a changeset.""" demandimport.disable() from flake8.engine import get_style_guide from pep8 import DiffReport, parse_udiff style = get_style_guide(parse_argv=False, ignore='E128') ctx = repo[node] if not entire: diff = ''.join(ctx.diff()) style.options.selected_lines = {} for k, v in parse_udiff(diff).items(): if k.startswith('./'): k = k[2:] style.options.selected_lines[k] = v style.options.report = DiffReport(style.options) deleted = repo.status(ctx.p1().node(), ctx.node())[2] files = [f for f in ctx.files() if f.endswith('.py') and f not in deleted] style.check_files(files) demandimport.enable()
def launch_webbrowser(ui, request_url): # not all python installations have this module, so only import it # when it's used from mercurial import demandimport demandimport.disable() import webbrowser demandimport.enable() #ui.status('browser launched\n') webbrowser.open(request_url)
def launch_browser(ui, request_url): # not all python installations have the webbrowser module from mercurial import demandimport demandimport.disable() try: import webbrowser webbrowser.open(request_url) except: ui.status('unable to launch browser - webbrowser module not available.') demandimport.enable()
def launch_browser(ui, request_url): # not all python installations have the webbrowser module from mercurial import demandimport demandimport.disable() try: import webbrowser webbrowser.open(request_url) except: ui.status( 'unable to launch browser - webbrowser module not available.') demandimport.enable()
def hgweb_handler(environ, start_response): from mercurial import demandimport; demandimport.enable() #from mercurial.hgweb.hgwebdir_mod import hgwebdir #from mercurial.hgweb.request import wsgiapplication from mercurial.hgweb import hgweb hgweb_conf = '/etc/mercurial/hgweb.conf' #make_web_app = hgwebdir(hgweb_conf) hg_webapp = hgweb(hgweb_conf) #hg_webapp = wsgiapplication(make_web_app) return hg_webapp(environ, start_response)
def hgweb_handler(environ, start_response): from mercurial import demandimport demandimport.enable() #from mercurial.hgweb.hgwebdir_mod import hgwebdir #from mercurial.hgweb.request import wsgiapplication from mercurial.hgweb import hgweb hgweb_conf = '/etc/mercurial/hgweb.conf' #make_web_app = hgwebdir(hgweb_conf) hg_webapp = hgweb(hgweb_conf) #hg_webapp = wsgiapplication(make_web_app) return hg_webapp(environ, start_response)
def direct_import_ext(module_name, blocked_modules=None): """ Like direct_import, but returns info whether module was just imported, or already loaded. >>> m1, loaded = direct_import_ext("xml.sax.handler") >>> m1.__name__, loaded ('xml.sax.handler', True) >>> m2, loaded = direct_import_ext("xml.sax.handler") >>> m2.__name__, loaded ('xml.sax.handler', False) >>> m1 == m2 True :param module_name: name of imported module :param blocked_modules: names of modules to be blocked from demandimport (list) :return: (imported module, was-it-imported-now?) """ if module_name in sys.modules: return sys.modules[module_name], False from mercurial import demandimport if blocked_modules: for blocked_module in blocked_modules: if blocked_module not in demandimport.ignore: demandimport.ignore.append(blocked_module) # Various attempts to define is_demandimport_enabled try: # Since Mercurial 2.9.1 is_demandimport_enabled = demandimport.isenabled except AttributeError: def is_demandimport_enabled(): """Checks whether demandimport is enabled at the moment""" return __import__ == demandimport._demandimport # pylint: disable=protected-access # Temporarily disable demandimport to make the need of extending # the list above less likely. if is_demandimport_enabled(): demandimport.disable() __import__(module_name) demandimport.enable() else: __import__(module_name) return sys.modules[module_name], True
import sys, textwrap # import from the live mercurial repo sys.path.insert(0, "..") from mercurial import demandimport; demandimport.enable() from mercurial.commands import table, globalopts from mercurial.i18n import gettext as _ from mercurial.help import helptable def get_desc(docstr): if not docstr: return "", "" # sanitize docstr = docstr.strip("\n") docstr = docstr.rstrip() shortdesc = docstr.splitlines()[0].strip() i = docstr.find("\n") if i != -1: desc = docstr[i+2:] else: desc = " %s" % shortdesc return (shortdesc, desc) def get_opts(opts): for shortopt, longopt, default, desc in opts: allopts = [] if shortopt: allopts.append("-%s" % shortopt) if longopt: allopts.append("--%s" % longopt) desc += default and _(" (default: %s)") % default or ""
#!/usr/bin/env python from mercurial import demandimport demandimport.enable() import re rsub = re.sub def f(obj): l = repr(obj) l = rsub("0x[0-9a-fA-F]+", "0x?", l) l = rsub("from '.*'", "from '?'", l) return l import os print "os =", f(os) print "os.system =", f(os.system) print "os =", f(os) from mercurial import util print "util =", f(util) print "util.system =", f(util.system) print "util =", f(util) print "util.system =", f(util.system) import re as fred
import sys, os.path, re from datetime import datetime import time from math import ceil sys.path.append(os.path.dirname(__file__)) demandimport.disable() from parsedatetime import parsedatetime as pdt try: import sqlite3 as sqlite except ImportError: from pysqlite2 import dbapi2 as sqlite demandimport.enable() testedwith = '3.6' cal = pdt.Calendar() PUSHES_PER_PAGE = 10 def addcommand(f, name): setattr(hgwebprotocol, name, f) hgwebprotocol.__all__.append(name) def addwebcommand(f, name): setattr(hgwebcommands, name, f) hgwebcommands.__all__.append(name) ATOM_MIMETYPE = 'application/atom+xml'
import sys # Adjust python path if this is not a system-wide install #sys.path.insert(0, r'c:\path\to\python\lib') # Enable tracing. Run 'python -m win32traceutil' to debug if getattr(sys, 'isapidllhandle', None) is not None: import win32traceutil # To serve pages in local charset instead of UTF-8, remove the two lines below import os os.environ['HGENCODING'] = 'UTF-8' import isapi_wsgi from mercurial import demandimport; demandimport.enable() from mercurial.hgweb.hgwebdir_mod import hgwebdir # Example tweak: Replace isapi_wsgi's handler to provide better error message # Other stuff could also be done here, like logging errors etc. class WsgiHandler(isapi_wsgi.IsapiWsgiHandler): error_status = '500 Internal Server Error' # less silly error message isapi_wsgi.IsapiWsgiHandler = WsgiHandler # Only create the hgwebdir instance once application = hgwebdir(hgweb_config) def handler(environ, start_response): # Translate IIS's weird URLs
def add_domain(a,b): pass hg_import_error = [] try: # The new `demandimport` mechanism doesn't play well with code relying # on the `ImportError` exception being caught. # OTOH, we can't disable `demandimport` because mercurial relies on it # (circular reference issue). So for now, we activate `demandimport` # before loading mercurial modules, and desactivate it afterwards. # # See http://www.selenic.com/mercurial/bts/issue605 try: from mercurial import demandimport demandimport.enable(); except ImportError, hg_import_error: demandimport = None from mercurial import hg from mercurial.context import filectx from mercurial.ui import ui from mercurial.node import hex, short, nullid from mercurial.util import pathto, cachefunc from mercurial import cmdutil from mercurial import extensions from mercurial.extensions import loadall # Note: due to the nature of demandimport, there will be no actual # import error until those symbols get accessed, so here we go: for sym in ("filectx ui hex short nullid pathto "