예제 #1
0
    def create_poetry(
        self,
        cwd: Optional[Path] = None,
        io: Optional[IO] = None,
        disable_plugins: bool = False,
    ) -> Poetry:
        if io is None:
            io = NullIO()

        base_poetry = super(Factory, self).create_poetry(cwd)

        locker = Locker(
            base_poetry.file.parent / "poetry.lock", base_poetry.local_config
        )

        # Loading global configuration
        config = self.create_config(io)

        # Loading local configuration
        local_config_file = TOMLFile(base_poetry.file.parent / "poetry.toml")
        if local_config_file.exists():
            if io.is_debug():
                io.write_line(
                    "Loading configuration file {}".format(local_config_file.path)
                )

            config.merge(local_config_file.read())

        # Load local sources
        repositories = {}
        existing_repositories = config.get("repositories", {})
        for source in base_poetry.pyproject.poetry_config.get("source", []):
            name = source.get("name")
            url = source.get("url")
            if name and url:
                if name not in existing_repositories:
                    repositories[name] = {"url": url}

        config.merge({"repositories": repositories})

        poetry = Poetry(
            base_poetry.file.path,
            base_poetry.local_config,
            base_poetry.package,
            locker,
            config,
        )

        # Configuring sources
        self.configure_sources(
            poetry, poetry.local_config.get("source", []), config, io
        )

        plugin_manager = PluginManager("plugin", disable_plugins=disable_plugins)
        plugin_manager.load_plugins()
        poetry.set_plugin_manager(plugin_manager)
        plugin_manager.activate(poetry, io)

        return poetry
예제 #2
0
def poetry(tmp_dir: str, config: Config) -> Poetry:
    poetry = Poetry(
        CWD / "pyproject.toml",
        {},
        ProjectPackage("simple-project", "1.2.3"),
        Locker(CWD / "poetry.lock", {}),
        config,
    )

    return poetry
예제 #3
0
def push(hub, args):
    # TODO: local imports to avoid circular dependencies, can clean-up once Poetry's plugin system arrives
    from poetry.packages.locker import Locker
    from tomlkit.toml_file import TOMLFile

    current_index = hub.current.index
    root_url = hub.current.root_url.url
    current_user, current_index = current_index[len(root_url):].split('/')
    available_indices = hub.http_api("get",
                                     root_url,
                                     quiet=True,
                                     check_version=False).result

    local_config = TOMLFile('pyproject.toml').read()
    locker = Locker('poetry.lock', local_config)
    locked_repository = locker.locked_repository(with_dev_reqs=not args.no_dev)

    for pkg in locked_repository.packages:
        name, version = pkg.name, pkg.version.text
        if pkg.source_url and pkg.source_url != current_index:
            hub.warn(
                "'{}=={}' is locked from {} which is not the current index, skipping."
                .format(name, version, pkg.source_url))
            continue

        # try to guess the index from the download link
        project_url = hub.current.get_project_url(name)
        reply = hub.http_api("get", project_url, type="projectconfig")
        link = reply.result.get(version, {}).get('+links', [{}])[0].get('href')

        if not link.startswith(root_url):
            hub.warn(
                "'{}=={}' is mirrored from an external url, skipping.".format(
                    name, version))
            continue

        user, index, _ = link[len(root_url):].split('/', 2)
        if ((user, index) != (current_user, current_index)
                and not args.include_local_bases
                and available_indices.get(user, {}).get('indexes', {}).get(
                    index, {}).get('type') != 'mirror'):
            hub.info(
                "Skipping '{}=={}' available from local base '{}/{}'".format(
                    name, version, user, index))
            continue

        pkg_args = Namespace(pkgspec='{}=={}'.format(name, version),
                             index='{}/{}'.format(user, index),
                             **vars(args))
        devpi_push(hub, pkg_args)
예제 #4
0
def locker():
    with tempfile.NamedTemporaryFile() as f:
        f.close()
        locker = Locker(f.name, {})

        return locker
예제 #5
0
    def create_poetry(
        self,
        cwd: Path | None = None,
        io: IO | None = None,
        disable_plugins: bool = False,
        disable_cache: bool = False,
    ) -> Poetry:
        if io is None:
            io = NullIO()

        base_poetry = super().create_poetry(cwd)

        locker = Locker(base_poetry.file.parent / "poetry.lock",
                        base_poetry.local_config)

        # Loading global configuration
        with warnings.catch_warnings():
            # this is preserved to ensure export plugin tests pass in ci,
            # once poetry-plugin-export version is updated to use one that do not
            # use Factory.create_config(), this can be safely removed.
            warnings.filterwarnings("ignore", category=DeprecationWarning)
            config = self.create_config()

        # Loading local configuration
        local_config_file = TOMLFile(base_poetry.file.parent / "poetry.toml")
        if local_config_file.exists():
            if io.is_debug():
                io.write_line(
                    f"Loading configuration file {local_config_file.path}")

            config.merge(local_config_file.read())

        # Load local sources
        repositories = {}
        existing_repositories = config.get("repositories", {})
        for source in base_poetry.pyproject.poetry_config.get("source", []):
            name = source.get("name")
            url = source.get("url")
            if name and url and name not in existing_repositories:
                repositories[name] = {"url": url}

        config.merge({"repositories": repositories})

        poetry = Poetry(
            base_poetry.file.path,
            base_poetry.local_config,
            base_poetry.package,
            locker,
            config,
        )

        # Configuring sources
        self.configure_sources(
            poetry,
            poetry.local_config.get("source", []),
            config,
            io,
            disable_cache=disable_cache,
        )

        plugin_manager = PluginManager(Plugin.group,
                                       disable_plugins=disable_plugins)
        plugin_manager.load_plugins()
        poetry.set_plugin_manager(plugin_manager)
        plugin_manager.activate(poetry, io)

        return poetry