Example #1
0
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()
Example #3
0
def shell(ui, repo, **opts):
    import mercurial
    from mercurial import demandimport
    demandimport.disable()

    objs = {
        'mercurial': mercurial,
        'repo': repo,
        'ui': ui,
    }
    banner = 'repo: %s\nsource: %s' % (repo.root, mercurial.__path__[0])
    try:
        from IPython.config.loader import Config
        from IPython.frontend.terminal.embed import InteractiveShellEmbed as Sh
    except:
        import code, traceback
        traceback.print_exc()
        return code.interact(banner=banner, local=objs)
    else:
        cfg = Config()
        cfg.TerminalInteractiveShell.confirm_exit = False
        pc = cfg.PromptManager
        pc.in_template = '[\#]> '
        pc.in2_template = '.\D.  '
        pc.out_template = '[\#]= '
        return Sh(user_ns=objs, config=cfg, banner1=banner)()
Example #4
0
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)
Example #5
0
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()
Example #6
0
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 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
Example #8
0
#                                        # inrepo:  branch = mercurial branch
#
#   branch = branchname                  # if set, branch is always branchname

import os

from mercurial.i18n import gettext as _
from mercurial.node import bin, hex, nullid
from mercurial.context import workingctx

# mercurial's on-demand-importing hacks interfere with the:
#from zope.interface import Interface
# that Twisted needs to do, so disable it.
try:
    from mercurial import demandimport
    demandimport.disable()
except ImportError:
    pass

from buildbot.clients import sendchange
from twisted.internet import defer, reactor


def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
    # read config parameters
    master = ui.config('hgbuildbot', 'master')
    if master:
        branchtype = ui.config('hgbuildbot', 'branchtype')
        branch = ui.config('hgbuildbot', 'branch')
    else:
        ui.write("* You must add a [hgbuildbot] section to .hg/hgrc in "
Example #9
0
"""Plugin built-in to Flake8 to treat pyflakes as a plugin."""
# -*- coding: utf-8 -*-
from __future__ import absolute_import

try:
    # The 'demandimport' breaks pyflakes and flake8.plugins.pyflakes
    from mercurial import demandimport
except ImportError:
    pass
else:
    demandimport.disable()
import os

import pyflakes
import pyflakes.checker

from flake8 import utils

FLAKE8_PYFLAKES_CODES = {
    'UnusedImport': 'F401',
    'ImportShadowedByLoopVar': 'F402',
    'ImportStarUsed': 'F403',
    'LateFutureImport': 'F404',
    'ImportStarUsage': 'F405',
    'ImportStarNotPermitted': 'F406',
    'FutureFeatureNotDefined': 'F407',
    'MultiValueRepeatedKeyLiteral': 'F601',
    'MultiValueRepeatedKeyVariable': 'F602',
    'TooManyExpressionsInStarredAssignment': 'F621',
    'TwoStarredExpressions': 'F622',
    'AssertTuple': 'F631',
Example #10
0
.. _SNI: https://en.wikipedia.org/wiki/Server_Name_Indication
.. _cwclientlib: https://www.cubicweb.org/project/cwclientlib

'''
from cStringIO import StringIO

from mercurial import cmdutil, scmutil, util, node, demandimport
from mercurial.i18n import _
import mercurial.revset
import mercurial.templatekw

try:
    enabled = demandimport.isenabled()
except AttributeError:
    enabled = demandimport._import is __import__
demandimport.disable()  # noqa

from .jplproxy import build_proxy
from .tasks import print_tasks
from .review import (ask_review, acknowledge, add_reviewer, show_review,
                     sudo_make_me_a_ticket, assign)
from .apycot import create_test_execution, list_tc
if enabled:
    demandimport.enable()

cmdtable = {}
command = cmdutil.command(cmdtable)
colortable = {
    'jpl.tasks.patch': 'cyan',
    'jpl.tasks.task.todo': 'red',
    'jpl.tasks.task.done': 'green',
# -*- coding: utf-8 -*-
try:
    # The 'demandimport' breaks pyflakes and flake8._pyflakes
    from mercurial import demandimport
except ImportError:
    pass
else:
    demandimport.disable()
import os
import pycodestyle as pep8
import pyflakes
import pyflakes.checker

def patch_pyflakes():
    """Add error codes to Pyflakes messages."""
    codes = dict([line.split()[::-1] for line in (
        'F401 UnusedImport',
        'F402 ImportShadowedByLoopVar',
        'F403 ImportStarUsed',
        'F404 LateFutureImport',
        'F405 ImportStarUsage',
        'F810 Redefined',               # XXX Obsolete?
        'F811 RedefinedWhileUnused',
        'F812 RedefinedInListComp',
        'F821 UndefinedName',
        'F822 UndefinedExport',
        'F823 UndefinedLocal',
        'F831 DuplicateArgument',
        'F841 UnusedVariable',
    )])