Manipulate with dependency requirements using PyPI.
169417
def pypi(
    click_ctx,
    requirements,
    index=None,
    python_version=3,
    exclude_packages=None,
    output=None,
    subgraph_check_api=None,
    no_transitive=True,
    no_pretty=False,
):
    """"""
    requirements = [requirement.strip() for requirement in requirements.split("\\n") if requirement]

    if not requirements:
        _LOG.error("No requirements specified, exiting")
        sys.exit(1)

    if not subgraph_check_api:
        _LOG.info(
            "No subgraph check API provided, no queries will be done for dependency subgraphs that should be avoided"
        )  # Ignore PycodestyleBear (E501)

    result = resolve_python(
        requirements,
        index_urls=index.split(",") if index else ("https://pypi.org/simple",),
        python_version=int(python_version),
        transitive=not no_transitive,
        exclude_packages=set(map(str.strip, (exclude_packages or "").split(","))),
        subgraph_check_api=subgraph_check_api,
    )

    print_command_result(
        click_ctx,
        result,
        analyzer=analyzer_name,
        analyzer_version=analyzer_version,
        output=output or "-",
        pretty=not no_pretty,
    )
390066
def setup():
    """"""
    install_requirements = ["attrdict"]
    if sys.version_info[:2] < (3, 4):
        install_requirements.append("pathlib")
    setup_requirements = ['six', 'setuptools>=17.1', 'setuptools_scm']
    needs_sphinx = {
        'build_sphinx',
        'docs',
        'upload_docs',
    }.intersection(sys.argv)
    if needs_sphinx:
        setup_requirements.append('sphinx')
    setuptools.setup(
        author="David Gidwani",
        author_email="david.gidwani@gmail.com",
        classifiers=[
            "Development Status :: 4 - Beta",
            "Intended Audience :: Developers",
            "License :: OSI Approved :: BSD License",
            "Operating System :: OS Independent",
            "Programming Language :: Python",
            "Programming Language :: Python :: 2",
            "Programming Language :: Python :: 2.7",
            "Programming Language :: Python :: 3",
            "Programming Language :: Python :: 3.3",
            "Programming Language :: Python :: 3.4",
            "Topic :: Software Development",
            "Topic :: Software Development :: Libraries :: Python Modules",
        ],
        description="Painless access to namespaced environment variables",
        download_url="https://github.com/darvid/biome/tarball/0.1",
        install_requires=install_requirements,
        keywords="conf config configuration environment",
        license="BSD",
        long_description=readme(),
        name="biome",
        package_dir={'': 'src'},
        packages=setuptools.find_packages('./src'),
        setup_requires=setup_requirements,
        tests_require=["pytest"],
        url="https://github.com/darvid/biome",
        use_scm_version=True,
    )
348190
def dependency_tree(args = {}, &bl)
      dependencies = {}
      args = {:recursive    => true,
              :dev_deps     => true,
              :matching     => :latest,
              :dependencies => dependencies}.merge(args)

      process = []
      deps.each do |dep|
        resolved = nil
        begin
          resolved = Polisher::Gem.matching(dep, args[:matching])
        rescue
        end
        yield self, dep, resolved
        process << resolved unless resolved.nil?
      end

      process.each { |dep|
        dependencies.merge!(dep.dependency_tree(args, &bl))
      }

      dependencies
    end
68392
def main(argv=sys.argv):
    """"""
    parser = setup_parser()

    (opts, args) = parser.parse_args(argv[1:])

    if not args:
        parser.error('A package path is required.')

    rootpath, excludes = args[0], args[1:]
    if not opts.destdir:
        parser.error('An output directory is required.')
    if opts.header is None:
        opts.header = path.normpath(rootpath).split(path.sep)[-1]
    if opts.suffix.startswith('.'):
        opts.suffix = opts.suffix[1:]
    if not path.isdir(rootpath):
        print >>sys.stderr, '%s is not a directory.' % rootpath
        sys.exit(1)
    if not path.isdir(opts.destdir):
        if not opts.dryrun:
            os.makedirs(opts.destdir)
    rootpath = path.normpath(path.abspath(rootpath))
    excludes = normalize_excludes(rootpath, excludes)
    modules = recurse_tree(rootpath, excludes, opts)
    if opts.full:
        from sphinx import quickstart as qs
        modules.sort()
        prev_module = ''
        text = ''
        for module in modules:
            if module.startswith(prev_module + '.'):
                continue
            prev_module = module
            text += '   %s\n' % module
        d = dict(
            path = opts.destdir,
            sep  = False,
            dot  = '_',
            project = opts.header,
            author = opts.author or 'Author',
            version = opts.version or '',
            release = opts.release or opts.version or '',
            suffix = '.' + opts.suffix,
            master = 'index',
            epub = True,
            ext_autodoc = True,
            ext_viewcode = True,
            makefile = True,
            batchfile = True,
            mastertocmaxdepth = opts.maxdepth,
            mastertoctree = text,
        )
        if not opts.dryrun:
            qs.generate(d, silent=True, overwrite=opts.force)
    elif not opts.notoc:
        create_modules_toc_file(modules, opts)
1149613
def copy_dependency_docs(tile):
    """"""

    env = Environment(tools=[])

    outputbase = os.path.join('build', 'output', 'doc')
    depbase = os.path.join('build', 'deps')
    for dep in tile.dependencies:
        depdir = os.path.join(depbase, dep['unique_id'], 'doc', dep['unique_id'])
        outputdir = os.path.join(outputbase, dep['unique_id'])

        if os.path.exists(depdir):
            env.Command([outputdir], [depdir], Copy("$TARGET", "$SOURCE"))
1358530
def check_requirements(dist, attr, value):
    """"""
    try:
        list(pkg_resources.parse_requirements(value))
    except (TypeError,ValueError):
        raise DistutilsSetupError(
            "%r must be a string or list of strings "
            "containing valid project/version requirement specifiers" % (attr,)
        )
1277643
def convert_requirements(requirements):
    """"""
    for req in requirements:
        parsed_requirement = pkg_resources.Requirement.parse(req)
        spec = requires_to_requires_dist(parsed_requirement)
        extras = ",".join(parsed_requirement.extras)
        if extras:
            extras = "[%s]" % extras
        yield (parsed_requirement.project_name + extras + spec)
461094
def load_dependencies(req, history=None):
    
    if history is None:
        history = set()
    dist = pkg_resources.get_distribution(req)
    spec = dict(
        requirement=str(req),
        resolved=str(dist),
    )
    if req not in history:
        # traverse into children
        history.add(req)
        extras = parse_extras(req)
        depends = [
            load_dependencies(dep, history=history)
            for dep in dist.requires(extras=extras)
        ]
        if depends:
            spec.update(depends=depends)
    return spec
373344
def get_dependencies():
    """"""

    dependencies = []

    # Numpy
    dep_attrs = {
        "name": "numpy",
        "min_version": "1.1.0",
        "description": "required",
    }
    try:
        import numpy
        dep_attrs["version"] = numpy.version.version
    except ImportError:
        dep_attrs["version"] = None
    dependencies.append(dep_attrs)

    # wxPython
    dep_attrs = {
        "name": "wxPython",
        "min_version": "2.8.10.1",
        "description": "required",
    }
    try:
        import wx
        dep_attrs["version"] = wx.version()
    except ImportError:
        dep_attrs["version"] = None
    dependencies.append(dep_attrs)

    # Matplotlib
    dep_attrs = {
        "name": "matplotlib",
        "min_version": "1.1.1",
        "description": "required",
    }
    try:
        import matplotlib
        dep_attrs["version"] = matplotlib._version.get_versions()["version"]
    except ImportError:
        dep_attrs["version"] = None
    except AttributeError:
        # May happen in old matplotlib versions
        dep_attrs["version"] = matplotlib.__version__

    dependencies.append(dep_attrs)

    # Pycairo
    dep_attrs = {
        "name": "pycairo",
        "min_version": "1.8.8",
        "description": "required",
    }
    try:
        import cairo
        dep_attrs["version"] = cairo.version
    except ImportError:
        dep_attrs["version"] = None
    dependencies.append(dep_attrs)

    # Python GnuPG
    dep_attrs = {
        "name": "python-gnupg",
        "min_version": "0.3.0",
        "description": "for opening own files without approval",
    }
    try:
        import gnupg
        dep_attrs["version"] = gnupg.__version__
    except ImportError:
        dep_attrs["version"] = None
    dependencies.append(dep_attrs)

    # xlrd
    dep_attrs = {
        "name": "xlrd",
        "min_version": "0.9.2",
        "description": "for loading Excel files",
    }
    try:
        import xlrd
        dep_attrs["version"] = xlrd.__VERSION__
    except ImportError:
        dep_attrs["version"] = None
    dependencies.append(dep_attrs)

    # xlwt
    dep_attrs = {
        "name": "xlwt",
        "min_version": "0.7.2",
        "description": "for saving Excel files",
    }
    try:
        import xlwt
        dep_attrs["version"] = xlwt.__VERSION__
    except ImportError:
        dep_attrs["version"] = None
    dependencies.append(dep_attrs)

    # Jedi
    dep_attrs = {
        "name": "jedi",
        "min_version": "0.8.0",
        "description": "for tab completion and context help in the entry line",
    }
    try:
        import jedi
        dep_attrs["version"] = jedi.__version__
    except ImportError:
        dep_attrs["version"] = None
    dependencies.append(dep_attrs)

    # pyrsvg
    dep_attrs = {
        "name": "pyrsvg",
        "min_version": "2.32",
        "description": "for displaying SVG files in cells",
    }
    try:
        import rsvg
        dep_attrs["version"] = True
    except ImportError:
        dep_attrs["version"] = None
    dependencies.append(dep_attrs)

    # pyenchant
    dep_attrs = {
        "name": "pyenchant",
        "min_version": "1.6.6",
        "description": "for spell checking",
    }
    try:
        import enchant
        dep_attrs["version"] = enchant.__version__
    except ImportError:
        dep_attrs["version"] = None
    dependencies.append(dep_attrs)

    return dependencies
313485
def pull_dependencies(self, nodes):
        """"""
        visitor = DependencyFinderVisitor()
        for node in nodes:
            visitor.visit(node)
        for dependency in 'filters', 'tests':
            mapping = getattr(self, dependency)
            for name in getattr(visitor, dependency):
                if name not in mapping:
                    mapping[name] = self.temporary_identifier()
                self.writeline('%s = environment.%s[%r]' %
                               (mapping[name], dependency, name))
1291215
def dependencies(dist, recursive=False, info=False):
    """"""

    def case_sorted(items):
        """Return unique list sorted in case-insensitive order."""
        return sorted(set(items), key=lambda i: i.lower())

    def requires(distribution):
        """Return the requirements for a distribution."""
        if recursive:
            req = set(pkg_resources.require(distribution.project_name))
            req.remove(distribution)
            return {r.as_requirement() for r in req}
        return distribution.requires()

    def modifier(distribution):
        """Return project's name or full requirement string."""
        return str(distribution) if info else distribution.project_name

    return case_sorted(modifier(r) for r in requires(dist))
1171556
def recreate_parent_dependencies(apps, schema_editor):
    """"""
    Data = apps.get_model('flow', 'Data')
    DataDependency = apps.get_model('flow', 'DataDependency')

    def process_dependency(data, parent):
        if not Data.objects.filter(pk=parent).exists():
            DataDependency.objects.create(
                child=data, parent=None, kind='io'
            )

    for data in Data.objects.all():
        for field_schema, fields in iterate_fields(data.input, data.process.input_schema):
            name = field_schema['name']
            value = fields[name]

            if field_schema.get('type', '').startswith('data:'):
                process_dependency(data, value)

            elif field_schema.get('type', '').startswith('list:data:'):
                for parent in value:
                    process_dependency(data, parent)
285652
def check(path_dir, requirements_name='requirements.txt'):
    ''''''
    requirements = _load_requirements(requirements_name, path_dir)
    imported_modules = _iter_modules(path_dir)
    installed_packages = _list_installed_packages()

    imported_modules.update(_excluded_imports())

    diff = {lib for lib in installed_packages if lib not in imported_modules}
    with_dependencies, _ = _list_dependencies(diff)
    unused_dependencies = sorted([d for d in diff if d in requirements])

    for unused_dependency in unused_dependencies:
        if with_dependencies.get(unused_dependency):
            print('    - {}'.format(unused_dependency))
            for dependency in with_dependencies.get(unused_dependency):
                print('\t - {}'.format(dependency))
        else:
            print('    - {}'.format(unused_dependency))
634983
def lib(names, sources=[], requirements=[], default_build=[], usage_requirements=[]):
    """"""
    assert is_iterable_typed(names, basestring)
    assert is_iterable_typed(sources, basestring)
    assert is_iterable_typed(requirements, basestring)
    assert is_iterable_typed(default_build, basestring)
    assert is_iterable_typed(usage_requirements, basestring)
    if len(names) > 1:
        if any(r.startswith('<name>') for r in requirements):
            get_manager().errors()("When several names are given to the 'lib' rule\n" +
                                   "it is not allowed to specify the <name> feature.")

        if sources:
            get_manager().errors()("When several names are given to the 'lib' rule\n" +
                                   "it is not allowed to specify sources.")

    project = get_manager().projects().current()
    result = []

    for name in names:
        r = requirements[:]

        # Support " lib a ; " and " lib a b c ; " syntax.
        if not sources and not any(r.startswith("<name>") for r in requirements) \
           and not any(r.startswith("<file") for r in requirements):
            r.append("<name>" + name)

        result.append(targets.create_typed_metatarget(name, "LIB", sources,
                                                      r,
                                                      default_build,
                                                      usage_requirements))
    return result
447724
def dependencies(source):
    """"""
    loader = ClassLoader(source, max_cache=-1)
    all_dependencies = set()
    for klass in loader.classes:
        new_dependencies = loader.dependencies(klass) - all_dependencies
        all_dependencies.update(new_dependencies)
        for new_dep in new_dependencies:
            click.echo(new_dep)
1353935
def install(self, dependency):
        """"""
        if not self.pip_installed:
            logger.info("Need to install a dependency with pip, but no builtin, "
                        "doing it manually (just wait a little, all should go well)")
            self._brute_force_install_pip()

        # split to pass several tokens on multiword dependency (this is very specific for '-e' on
        # external requirements, but implemented generically; note that this does not apply for
        # normal reqs, because even if it originally is 'foo > 1.2', after parsing it loses the
        # internal spaces)
        str_dep = str(dependency)
        args = [self.pip_exe, "install"] + str_dep.split()

        if self.options:
            for option in self.options:
                args.extend(option.split())
        logger.info("Installing dependency: %r", str_dep)
        try:
            helpers.logged_exec(args)
        except helpers.ExecutionError as error:
            error.dump_to_log(logger)
            raise error
        except Exception as error:
            logger.exception("Error installing %s: %s", str_dep, error)
            raise error
388844
def extract_dependencies(pipe_def=None, pipe_generator=None):
    """"""
    if pipe_def:
        pydeps = gen_dependencies(pipe_def)
    elif pipe_generator:
        pydeps = pipe_generator(Context(describe_dependencies=True))
    else:
        raise Exception('Must supply at least one kwarg!')

    return sorted(set(pydeps))