Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property to access venv_backend #796

Closed
henryiii opened this issue Mar 5, 2024 · 1 comment · Fixed by #798
Closed

Property to access venv_backend #796

henryiii opened this issue Mar 5, 2024 · 1 comment · Fixed by #798

Comments

@henryiii
Copy link
Collaborator

henryiii commented Mar 5, 2024

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. :/

@layday
Copy link
Contributor

layday commented Mar 5, 2024

I wanted this to skip my minimum version tests if another backend is used, since the arguments are uv-specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants