Exemple #1
0
def test_setup(node_package):
    node_package_dir = nodely.NODE_MODULES_DIR / node_package
    nodely.uninstall(node_package)
    assert not node_package_dir.exists()
    zetup.call([sys.executable, 'setup.py', 'develop'],
               cwd=os.path.dirname(os.path.realpath(__file__)))
    assert node_package_dir.isdir()
def test_moreshell(shell, args):  # pragma: no cover
    """Run the :mod:`moreshell` unit tests with ``pytest``."""
    moreshell_dir = Path(  # pylint: disable=no-value-for-parameter
        moreshell.__file__).dirname().realpath()

    call_args = [
        sys.executable, '-m', 'pytest', '--doctest-modules', moreshell_dir
    ]
    if args.coverage:
        call_args.extend(
            ['--cov', moreshell_dir, '--cov-report', 'term-missing'])
    if args.verbose:
        call_args.append('-vv')

    call(call_args)
Exemple #3
0
def scons(*args, **options):
    """Run SCons as separate sub-process through ``sys.executable``
       with the given command line `args` and process `options`.

    - All `options` starting with upper case letters
      are used as SCons variables by appendeding to `args`.
    - See :func:`zetup.call` and :func:`subprocess.call`
      for info about general `options`.
    """
    args = list(args)
    for name in list(options):
        if name[0].isupper():
            args.append('%s=%s' % (name, options.pop(name)))

    zetup.call([
        sys.executable, '-c', "import SCons.Script; SCons.Script.main()"
    ] + args, **options)
Exemple #4
0
 def call(self, cmdargs=None, **kwargs):
     """
     Call this Node.js command with optional sequence of `cmdargs` strings
     and optional `kwargs` for ``zetup.call``, including all options for
     ``subprocess.call``
     """
     command = [str(self)]
     if cmdargs is not None:
         command += cmdargs
     return zetup.call(command, **kwargs)
Exemple #5
0
def uninstall(package):
    """
    Uninstall given Node.js `package`.

    From ``node_modules/`` of current Python environment
    """
    command = [NPM, 'uninstall', package]
    with Path(sys.prefix):
        status = zetup.call(command)
    if status:  # pragma: no cover
        raise NodeCommandError(command, status, os.getcwd())
Exemple #6
0
def install(package):
    """
    Install given Node.js `package`.

    Into ``node_modules/`` of current Python environment
    """
    command = [NPM, 'install', package]
    with Path(sys.prefix):
        status = zetup.call(command)
    if status:
        raise NodeCommandError(command, status, os.getcwd())
def uninstall(package):
    """
    Uninstall given Node.js `package` from ``node_modules/`` of current Python
    environment
    """
    command = ['npm', 'uninstall', package]
    with Path(sys.prefix):
        status = zetup.call(command)
    if status:  # pragma: no cover
        raise RuntimeError("Command {!r} failed with status {}".format(
            command, status))
Exemple #8
0
    def bootstrap(self):
        """
        Run ``./bootstrap`` script in extracted Boost source release.

        Auto-selects ``./bootstrap.bat`` for VisualC++ builds and
        ``./bootstrap.sh`` for GCC
        """
        script = MSVC and ['booststrap.bat'] or ['bash', 'bootstrap.sh']
        with self.path as cwd:
            if zetup.call(script):
                raise RuntimeError("Failed to run {!r} in {}".format(
                    script, cwd))
Exemple #9
0
    def call(self, cmdargs=None, **options):
        """
        Call this Node.js command.

        :param cmdargs:
            Optional sequence of command argument strings.
        :param options:
            General options for ``zetup.call``, including all options for
            ``subprocess.call``.
        """
        command = [str(self)]
        if cmdargs is not None:
            command += cmdargs
        return zetup.call(command, **options)
Exemple #10
0
    def b2(self, args=None):
        """
        Run ``./b2`` binary in extracted Boost source release.

        Auto-adds ``link=shared`` and ``address-model=32`` or ``=64`` to
        (optionally) given `args` sequence
        """
        command = [
            Path('./b2'), 'link=shared', 'address-model={}'.format(BITS)
        ]
        if args is not None:
            command += args
        with self.path as cwd:
            if zetup.call(command):
                raise RuntimeError("Failed to run {!r} in {}".format(
                    command, cwd))
Exemple #11
0
    def check_call(self, cmdargs=None, **options):
        """
        Call this Node.js command and check its return code.

        :param cmdargs:
            Optional sequence of command argument strings.
        :param options:
            General options for ``zetup.call``, including all options for
            ``subprocess.call``.

        :raises subprocess.CalledProcessError:
            When return code is not zero.
        """
        command = [str(self)]
        if cmdargs is not None:
            command += cmdargs

        returncode = zetup.call(command, **options)
        if returncode:
            raise NodeCommandError(returncode, command, os.getcwd())
Exemple #12
0
    def b2(self, args=None):
        """
        Run ``./b2`` binary in extracted Boost source release.

        Auto-adds ``toolset=gcc`` or ``=msvc``, ``address-model=32`` or
        ``=64``, ``include=`` with Python include path, and ``link=shared``
        to (optionally) given `args` sequence
        """
        if MSVC:  # pragma: no cover
            _b2 = Path(__file__).realpath().dirname() / 'call_b2.cmd'
        else:  # pragma: no cover
            _b2 = Path('.') / 'b2'
        command = [
            str(_b2), 'toolset={}'.format(TOOLSET),
            'address-model={}'.format(BITS),
            'include={}'.format(sysconfig.get_path('include')), 'link=shared'
        ]
        if args is not None:
            command += args
        with self.path as cwd:
            print("Running {!r} in {!r}".format(command, cwd))
            if zetup.call(command):
                raise RuntimeError("Failed to run {!r} in {!r}".format(
                    command, cwd))
Exemple #13
0
def dev(shell, args):
    """
    Open the file containing the code for the given object.

    And jump to the location of its definition

    By taking the command from the ``--editor`` option or from the ``EDITOR``
    environment variable, and running it with an argument created from the
    format string ``{file}:{line}``, which can be customized using the
    ``--format`` option

    The subprocess is started with ``shell=True``

    If no line number can be determined for the given ``object``, then the
    format string is ignored, and only the file path is used
    """
    editor = args.editor or os.environ.get('EDITOR')
    if not editor:
        raise RuntimeError("No EDITOR environment variable defined")

    editor_arg_format = args.format or "{file}:{line}"
    obj = eval(args.object, shell.user_ns)

    exceptions = []
    try:
        filename = getsourcefile(obj)
    except TypeError as exc:
        exceptions.append(exc)

        obj = type(obj)
        try:
            filename = getsourcefile(obj)
        except TypeError as exc:
            exceptions.append(exc)

            def getfile(base):
                try:
                    return getsourcefile(base)

                except TypeError as exc:
                    exceptions.append(exc)
                    return None

            for obj in obj.mro()[1:]:
                filename = getfile(obj)
                if filename is not None:
                    break

            else:
                raise TypeError(
                    "Can't find any source file for given object, its "
                    "class, or base classes: {!r}".format(exceptions))

    try:
        lineno = getsourcelines(obj)[1]
    except TypeError:
        lineno = 0

    editor_arg = (
        Path(filename)  # pylint: disable=no-value-for-parameter
        .realpath().normcase())
    if lineno:
        editor_arg = editor_arg_format.format(file=editor_arg, line=lineno)
    return call('{} "{}"'.format(editor, editor_arg), shell=True)