def do_use(
        self,
        project: Project,
        python: str = "",
        first: bool = False,
        ignore_remembered: bool = False,
        ignore_requires_python: bool = False,
        save: bool = True,
        venv: str | None = None,
        auto_install_min: bool = False,
        auto_install_max: bool = False,
        version_file: bool = True,
        hooks: HookManager | None = None,
    ) -> PythonInfo:
        """Use the specified python version and save in project config.
        The python can be a version string or interpreter path.
        """
        from pdm.environments import PythonLocalEnvironment

        selected_python = self.select_python(
            project,
            python,
            ignore_remembered=ignore_remembered,
            first=first,
            venv=venv,
            ignore_requires_python=ignore_requires_python,
            auto_install_min=auto_install_min,
            auto_install_max=auto_install_max,
        )
        # NOTE: PythonInfo is cached with path as key.
        # This can lead to inconsistency when the same virtual environment is reused.
        # So the original python identifier is preserved here for logging purpose.
        selected_python_identifier = selected_python.identifier
        if python and selected_python.get_venv() is None:
            use_cache: JSONFileCache[str, str] = JSONFileCache(project.cache_dir / "use_cache.json")
            use_cache.set(python, selected_python.path.as_posix())

        if project.config["python.use_venv"] and (
            selected_python.get_venv() is None or is_conda_base_python(selected_python.path)
        ):
            venv_path = project._create_virtualenv(str(selected_python.path))
            selected_python = PythonInfo.from_path(get_venv_python(venv_path))
        if not save:
            return selected_python

        saved_python = project._saved_python
        old_python = PythonInfo.from_path(saved_python) if saved_python else None
        project.core.ui.echo(
            f"Using {'[bold]Global[/] ' if project.is_global else ''}Python interpreter: [success]{selected_python.path!s}[/] ({selected_python_identifier})"
        )
        project.python = selected_python
        if version_file and project.config["python.use_python_version"]:
            with project.root.joinpath(".python-version").open("w") as f:
                f.write(f"{selected_python.major}.{selected_python.minor}\n")
        if project.environment.is_local:
            assert isinstance(project.environment, PythonLocalEnvironment)
            project.core.ui.echo(
                "Using __pypackages__ because non-venv Python is used.",
                style="primary",
                err=True,
            )
            if old_python and old_python.executable != selected_python.executable:
                project.core.ui.echo("Updating executable scripts...", style="primary")
                project.environment.update_shebangs(selected_python.executable.as_posix())

        hooks = hooks or HookManager(project)
        hooks.try_emit("post_use", python=selected_python)
        return selected_python
Use the specified python version and save in project config.
        The python can be a version string or interpreter path.
        
src/pdm/cli/commands/use.py