Ejemplo n.º 1
0
def test_iteritems():
    dict_ = dict(foo="bar")

    assert isinstance(iteritems(dict_), Iterable)

    for k, v in iteritems(dict_):
        assert dict_[k] == v
Ejemplo n.º 2
0
def _get_pip_info(*args, **kwargs):
    packages = args
    pip_exec = kwargs.get("pip_exec", None)

    _, out, _ = _pip.call("show", *packages, pip_exec=pip_exec, output=True)
    results = [strip(o) for o in out.split("---")]

    info = dict()

    for i, package in enumerate(packages):
        result = results[i]

        detail = dict((kebab_case(k), v) \
         for k, v in \
          iteritems(
           dict([(s + [""]) if len(s) == 1 else s \
            for s in [re.split(r":\s?", o, maxsplit = 1) \
             for o in result.split("\n")]]
           )
          )
        )

        info[package] = detail

    return info
Ejemplo n.º 3
0
def get_function_arguments(fn):
    # https://stackoverflow.com/a/2677263
    params = dict()
    success = False

    if _compat.PY2:
        argspec_getter = inspect.getargspec
        success = True
    if _compat.PYTHON_VERSION >= (3, 0) and _compat.PYTHON_VERSION < (3, 5):
        argspec_getter = inspect.getfullargspec
        success = True

    if success:
        argspec = argspec_getter(fn)
        params = dict_from_list(argspec.args, argspec.defaults or [])

    if _compat.PYTHON_VERSION >= (3, 5):
        signature = inspect.signature(fn)
        parameters = signature.parameters

        params = {k: v.default for k, v in _compat.iteritems(parameters)}

        success = True

    if not success:
        raise ValueError(
            "Unknown Python Version {} for fetching functional arguments.".
            format(sys.version))

    return params
Ejemplo n.º 4
0
        def foobar(*args, **kwargs):
            args = get_args()
            params = merge_dict(args, override)

            for k, v in iteritems(values):
                assert params[k] == v

            if initial:
                for k in iterkeys(initial):
                    assert initial[k] == args[k]
Ejemplo n.º 5
0
def call(*args, **kwargs):
    output = kwargs.get("output", False)
    quiet = kwargs.get("quiet", False)
    directory = kwargs.get("cwd")
    environment = kwargs.get("env")
    shell = kwargs.get("shell", True)
    raise_err = kwargs.get("raise_err", True)

    environ = os.environ.copy()
    if environment:
        environ.update(environment)

    for k, v in iteritems(environ):
        environ[k] = string_types(v)

    command = " ".join([string_types(arg) for arg in args])

    logger.info("Executing command: %s" % command)

    if quiet:
        output = True

    proc = sp.Popen(command,
                    bufsize=-1,
                    stdin=sp.PIPE if output else None,
                    stdout=sp.PIPE if output else None,
                    stderr=sp.PIPE if output else None,
                    env=environ,
                    cwd=directory,
                    shell=shell)

    code = proc.wait()

    if code and raise_err:
        raise PopenError(code, command)

    if output:
        output, error = proc.communicate()

        if output:
            output = safe_decode(output)
            output = strip(output)

        if error:
            error = safe_decode(error)
            error = strip(error)

        if quiet:
            return code
        else:
            return code, output, error
    else:
        return code
Ejemplo n.º 6
0
def _build_packages_info_dict(packages, pip_exec=None):
    details = _get_pip_info(*packages, pip_exec=pip_exec)

    requirements = []

    for name, detail in iteritems(details):
        if not name in _INFO_DICT:
            _INFO_DICT[name] = dict({
                "version":
                detail["version"],
                "dependencies":
                compact(detail["requires"].split(", "))
            })

            for requirement in _INFO_DICT[name]["dependencies"]:
                if requirement not in requirements:
                    requirements.append(requirement)

    if requirements:
        _build_packages_info_dict(requirements, pip_exec=pip_exec)
Ejemplo n.º 7
0
def call(*args, **kwargs):
    pip_exec = kwargs.pop("pip_exec", None) or _PIP_EXECUTABLE
    quiet = kwargs.pop("quiet", None) or False
    output = kwargs.pop("output", None) or False
    raise_err = kwargs.pop("raise_err", None) or True

    params = sequencify(pip_exec) + sequencify(args)

    for flag, value in iteritems(kwargs):
        if value != False:
            flag = "--%s" % kebab_case(flag, delimiter="_")
            params.append(flag)

            if not isinstance(value, bool):
                value = value_to_envval(value)
                params.append(value)

    output = output or quiet

    output = popen(*params, output=output, raise_err=raise_err)

    return output
Ejemplo n.º 8
0
 def _init(self):
     for k, v in iteritems(Settings._DEFAULTS):
         self.set(k, v)