Skip to content

Property to access venv_backend #796

@henryiii

Description

@henryiii

How would this feature be useful?

There are several ways to set the backend, like environment variable, command line, and with a fall-through list. However, it's hard to tell which backend you actually have inside the noxfile. It looks like (from #795) it might not even be possible to just check which("uv") to see if uv is present reliably. So I think being able to get the venv_backend string back out with the final selection would be useful.

Describe the solution you'd like

    @property
    def venv_backend(self) -> str:
        try:
            venv = self.virtualenv
        except ValueError:
            return "none"
        if isinstance(venv, PassthroughEnv):
            return "none"
        if isinstance(venv, CondaEnv):
            return venv.conda_cmd
        if isinstance(venv, VirtualEnv):
            return venv.venv_backend
        raise ValueError("Unsupported environment")

Or, actually, probably making it an abstract property would be better.

Describe alternatives you've considered

The .virtualenv property does give you the backend, but each backend is different and accessing the properties only defined on ProcessEnv subclasses doesn't really feel like public API.

I'm currently using:

    if getattr(session.virtualenv, "venv_backend", "") != "uv":
        session.install("uv")

Anything else?

It looks like prog @ . doesn't work for pip, so this will need to be based on the backend. :/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions