示例#1
0
    def __init__(self,
                 targets,
                 extra_requirements=None,
                 builder=None,
                 platforms=None,
                 interpreter=None,
                 conn_timeout=None):
        self._config = Config.from_cache()
        self._targets = targets
        self._extra_requirements = list(
            extra_requirements) if extra_requirements else []
        self._platforms = platforms
        self._interpreter = interpreter or PythonInterpreter.get()
        self._builder = builder or PEXBuilder(os.path.realpath(
            tempfile.mkdtemp()),
                                              interpreter=self._interpreter)
        self._conn_timeout = conn_timeout

        # Note: unrelated to the general pants artifact cache.
        self._egg_cache_root = os.path.join(
            PythonSetup(self._config).scratch_dir('artifact_cache',
                                                  default_name='artifacts'),
            str(self._interpreter.identity))

        self._key_generator = CacheKeyGenerator()
        self._build_invalidator = BuildInvalidator(self._egg_cache_root)
示例#2
0
文件: resolver.py 项目: dbieber/pants
def resolve_multi(config,
                  requirements,
                  interpreter=None,
                  platforms=None,
                  conn_timeout=None,
                  ttl=3600):
    """Multi-platform dependency resolution for PEX files.

     Given a pants configuration and a set of requirements, return a list of distributions
     that must be included in order to satisfy them.  That may involve distributions for
     multiple platforms.

     :param config: Pants :class:`Config` object.
     :param requirements: A list of :class:`PythonRequirement` objects to resolve.
     :param interpreter: :class:`PythonInterpreter` for which requirements should be resolved.
                         If None specified, defaults to current interpreter.
     :param platforms: Optional list of platforms against requirements will be resolved. If
                         None specified, the defaults from `config` will be used.
     :param conn_timeout: Optional connection timeout for any remote fetching.
     :param ttl: Time in seconds before we consider re-resolving an open-ended requirement, e.g.
                 "flask>=0.2" if a matching distribution is available on disk.  Defaults
                 to 3600.
  """
    distributions = dict()
    interpreter = interpreter or PythonInterpreter.get()
    if not isinstance(interpreter, PythonInterpreter):
        raise TypeError(
            'Expected interpreter to be a PythonInterpreter, got %s' %
            type(interpreter))

    install_cache = PythonSetup(config).scratch_dir('install_cache',
                                                    default_name='eggs')
    platforms = get_platforms(
        platforms or config.getlist('python-setup', 'platforms', ['current']))

    for platform in platforms:
        translator = Translator.default(install_cache=install_cache,
                                        interpreter=interpreter,
                                        platform=platform,
                                        conn_timeout=conn_timeout)

        obtainer = PantsObtainer(
            install_cache=install_cache,
            crawler=crawler_from_config(config, conn_timeout=conn_timeout),
            fetchers=fetchers_from_config(config) or [PyPIFetcher()],
            translators=translator)

        distributions[platform] = resolve(requirements=requirements,
                                          obtainer=obtainer,
                                          interpreter=interpreter,
                                          platform=platform)

    return distributions
示例#3
0
def resolve_multi(config,
                  requirements,
                  interpreter=None,
                  platforms=None,
                  ttl=3600,
                  find_links=None):
    """Multi-platform dependency resolution for PEX files.

     Given a pants configuration and a set of requirements, return a list of distributions
     that must be included in order to satisfy them.  That may involve distributions for
     multiple platforms.

     :param config: Pants :class:`Config` object.
     :param requirements: A list of :class:`PythonRequirement` objects to resolve.
     :param interpreter: :class:`PythonInterpreter` for which requirements should be resolved.
                         If None specified, defaults to current interpreter.
     :param platforms: Optional list of platforms against requirements will be resolved. If
                         None specified, the defaults from `config` will be used.
     :param ttl: Time in seconds before we consider re-resolving an open-ended requirement, e.g.
                 "flask>=0.2" if a matching distribution is available on disk.  Defaults
                 to 3600.
     :param find_links: Additional paths to search for source packages during resolution.
  """
    distributions = dict()
    interpreter = interpreter or PythonInterpreter.get()
    if not isinstance(interpreter, PythonInterpreter):
        raise TypeError(
            'Expected interpreter to be a PythonInterpreter, got %s' %
            type(interpreter))

    cache = PythonSetup(config).scratch_dir('install_cache',
                                            default_name='eggs')
    platforms = get_platforms(
        platforms or config.getlist('python-setup', 'platforms', ['current']))
    fetchers = fetchers_from_config(config)
    if find_links:
        fetchers.extend(Fetcher([path]) for path in find_links)
    context = context_from_config(config)

    for platform in platforms:
        distributions[platform] = resolve(requirements=requirements,
                                          interpreter=interpreter,
                                          fetchers=fetchers,
                                          platform=platform,
                                          context=context,
                                          cache=cache,
                                          cache_ttl=ttl)

    return distributions
示例#4
0
 def _cache_dir(config):
     return PythonSetup(config).scratch_dir('interpreter_cache',
                                            default_name='interpreters')
示例#5
0
 def _interpreter_requirement(config):
     return PythonSetup(config).interpreter_requirement
示例#6
0
文件: resolver.py 项目: dbieber/pants
def crawler_from_config(config, conn_timeout=None):
    download_cache = PythonSetup(config).scratch_dir('download_cache',
                                                     default_name='downloads')
    return Crawler(cache=download_cache, conn_timeout=conn_timeout)