Beispiel #1
0
    def pex_requirements(
        self,
        *,
        extra_requirements: Iterable[str] = (),
    ) -> PexRequirements | Lockfile | LockfileContent:
        """The requirements to be used when installing the tool.

        If the tool supports lockfiles, the returned type will install from the lockfile rather than
        `all_requirements`.
        """

        requirements = (*self.all_requirements, *extra_requirements)

        if not self.uses_lockfile:
            return PexRequirements(requirements)

        hex_digest = calculate_invalidation_digest(requirements)

        if self.lockfile == DEFAULT_TOOL_LOCKFILE:
            assert self.default_lockfile_resource is not None
            return ToolDefaultLockfile(
                file_content=FileContent(
                    f"{self.options_scope}_default_lockfile.txt",
                    importlib.resources.read_binary(
                        *self.default_lockfile_resource),
                ),
                lockfile_hex_digest=hex_digest,
                req_strings=FrozenOrderedSet(requirements),
                options_scope_name=self.options_scope,
                uses_project_interpreter_constraints=(
                    not self.register_interpreter_constraints),
                uses_source_plugins=self.uses_requirements_from_source_plugins,
            )
        return ToolCustomLockfile(
            file_path=self.lockfile,
            file_path_description_of_origin=
            f"the option `[{self.options_scope}].lockfile`",
            lockfile_hex_digest=hex_digest,
            req_strings=FrozenOrderedSet(requirements),
            options_scope_name=self.options_scope,
            uses_project_interpreter_constraints=(
                not self.register_interpreter_constraints),
            uses_source_plugins=self.uses_requirements_from_source_plugins,
        )
Beispiel #2
0
 def assert_neq(left: Iterable[str], right: Iterable[str]) -> None:
     assert calculate_invalidation_digest(
         left) != calculate_invalidation_digest(right)
Beispiel #3
0
 def requirements_hex_digest(self) -> str:
     """Produces a hex digest of the requirements input for this lockfile."""
     return calculate_invalidation_digest(self.requirements)