Exemple #1
0
    def handle(self, project: Project, options: argparse.Namespace) -> None:
        groups: list[str] = list(options.groups)
        if options.pyproject:
            options.hashes = False
        groups = translate_groups(
            project,
            options.default,
            options.dev,
            options.groups or (),
        )
        requirements: dict[str, Requirement] = {}
        packages: Iterable[Requirement] | Iterable[Candidate]
        for group in groups:
            requirements.update(project.get_dependencies(group))
        if options.pyproject:
            packages = requirements.values()
        else:
            project.core.ui.echo(
                "The exported requirements file is no longer cross-platform. "
                "Using it on other platforms may cause unexpected result.",
                fg="yellow",
                err=True,
            )
            candidates = resolve_candidates_from_lockfile(
                project, requirements.values()
            )
            packages = candidates.values()

        content = FORMATS[options.format].export(
            project, packages, options
        )  # type: ignore
        if options.output:
            Path(options.output).write_text(content)
        else:
            project.core.ui.echo(content)
Exemple #2
0
    def handle(self, project: Project, options: argparse.Namespace) -> None:
        candidates = {}
        sections = list(options.sections)
        if options.pyproject:
            options.hashes = False
        if not sections and options.dev:
            sections.append(":all")
        if ":all" in sections:
            if options.dev:
                sections = list(
                    project.tool_settings.get("dev-dependencies", []))
            else:
                sections = list(project.meta.optional_dependencies or [])
        if options.default:
            sections.append("default")
        for section in sections:
            if options.pyproject:
                candidates.update(project.get_dependencies(section))
            else:
                candidates.update(project.get_locked_candidates(section))
        candidates.pop(project.meta.name and project.meta.project_name, None)

        content = FORMATS[options.format].export(project, candidates.values(),
                                                 options)
        if options.output:
            Path(options.output).write_text(content)
        else:
            project.core.ui.echo(content)
Exemple #3
0
 def handle(self, project: Project, options: argparse.Namespace) -> None:
     candidates = []
     if options.pyproject:
         options.hashes = False
     if options.default:
         # Don't include self candidate
         if options.pyproject:
             temp = project.dependencies
         else:
             temp = project.get_locked_candidates()
             temp.pop(project.meta.name, None)
         candidates.extend(temp.values())
     if options.dev:
         if options.pyproject:
             candidates.extend(project.dev_dependencies.values())
         else:
             candidates.extend(project.get_locked_candidates("dev").values())
     for section in options.sections:
         if options.pyproject:
             candidates.extend(project.get_dependencies(section).values())
         else:
             candidates.extend(project.get_locked_candidates(section).values())
     content = FORMATS[options.format].export(project, candidates, options)
     if options.output:
         Path(options.output).write_text(content)
     else:
         stream.echo(content)
Exemple #4
0
def do_sync(
    project: Project,
    *,
    groups: Sequence[str] = (),
    dev: bool = True,
    default: bool = True,
    dry_run: bool = False,
    clean: bool = False,
    requirements: list[Requirement] | None = None,
    tracked_names: Sequence[str] | None = None,
    no_editable: bool = False,
    no_self: bool = False,
    reinstall: bool = False,
) -> None:
    """Synchronize project"""
    if requirements is None:
        if not project.lockfile_file.exists():
            raise ProjectError("Lock file does not exist, nothing to sync")
        elif not project.is_lockfile_compatible():
            project.core.ui.echo(
                "Lock file version is not compatible with PDM, "
                "install may fail, please regenerate the pdm.lock",
                err=True,
            )
        elif not project.is_lockfile_hash_match():
            project.core.ui.echo(
                "Lock file hash doesn't match pyproject.toml, packages may be outdated",
                err=True,
            )
        groups = translate_groups(project, default, dev, groups or ())
        requirements = []
        for group in groups:
            requirements.extend(project.get_dependencies(group).values())
    candidates = resolve_candidates_from_lockfile(project, requirements)
    if tracked_names and dry_run:
        candidates = {
            name: c
            for name, c in candidates.items() if name in tracked_names
        }

    handler = project.core.synchronizer_class(
        candidates,
        project.environment,
        clean,
        dry_run,
        no_editable=no_editable,
        install_self=not no_self and "default" in groups
        and bool(project.meta.name),
        use_install_cache=project.config["feature.install_cache"],
        reinstall=reinstall,
    )
    handler.synchronize()
Exemple #5
0
def do_sync(
    project: Project,
    *,
    groups: Collection[str] = (),
    dev: bool = True,
    default: bool = True,
    dry_run: bool = False,
    clean: bool = False,
    requirements: list[Requirement] | None = None,
    tracked_names: Collection[str] | None = None,
    no_editable: bool | Collection[str] = False,
    no_self: bool = False,
    reinstall: bool = False,
) -> None:
    """Synchronize project"""
    if requirements is None:
        groups = translate_groups(project, default, dev, groups or ())
        requirements = []
        for group in groups:
            requirements.extend(project.get_dependencies(group).values())
    candidates = resolve_candidates_from_lockfile(project, requirements)
    if tracked_names and dry_run:
        candidates = {
            name: c for name, c in candidates.items() if name in tracked_names
        }
    handler = project.core.synchronizer_class(
        candidates,
        project.environment,
        clean,
        dry_run,
        no_editable=no_editable,
        install_self=not no_self and "default" in groups and bool(project.name),
        use_install_cache=project.config["install.cache"],
        reinstall=reinstall,
    )
    signals.pre_install.send(project, candidates=candidates, dry_run=dry_run)
    handler.synchronize()
    signals.post_install.send(project, candidates=candidates, dry_run=dry_run)
Exemple #6
0
    def handle(self, project: Project, options: argparse.Namespace) -> None:
        candidates = {}
        sections = list(options.sections)
        if options.pyproject:
            options.hashes = False
        sections = translate_sections(
            project,
            options.default,
            compatible_dev_flag(project, options.dev),
            options.sections or (),
        )
        for section in sections:
            if options.pyproject:
                candidates.update(project.get_dependencies(section))
            else:
                candidates.update(project.get_locked_candidates(section))
        candidates.pop(project.meta.name and project.meta.project_name, None)

        content = FORMATS[options.format].export(project, candidates.values(), options)
        if options.output:
            Path(options.output).write_text(content)
        else:
            project.core.ui.echo(content)