cnpryer/huak

Use Huak to manage virtual environments for projects

cnpryer opened this issue · 3 comments

Summary

Allow for users to use Huak to manage virtual environments for projects.

Motivation

Currently Huak will resolve a Python environment to use for each command. It does this by searching for a virutal environment to use or by creating a new one. This isn't exposed well to users. Adding features for more control over this process would help make Huak easier to use.

The goal is for Huak to manage things like project virtual environments without having to burden the user, but if the user ever needs to manage their project's virtual environment there should be a way to do it.

Requirements

  • Retain Huak's default Python environment resolution behavior
  • Allow in-project and out-of-project virutal environments
  • Allow for per-project + per-package venvs if needed
  • Allow a future without virtual environments
  • Allow for persisting multiple environments to select from
  • Help make freeing up install command easier (see #850)

Details

At the workspace level a project can be given a virtual environment to use .venv. Per-project users may want to change what virtual environment Huak uses. The python subcommand is meant to be reserved for managing and interacting with Python.

(WIP; see comment)

huak python use <version> # default resolution behavior
huak python use --path <path/to/python>
huak run python -m venv ../somewhere/else/venv
huak python use --path ../somewhere/else/venv
huak python env create --path ../somewhere/else/venv  # If Huak replaces current pip-managed venvs
huak python env create --requirements <requirements-file>
huak python env create --manifest <pyproject.toml/setup.py/etc.>
huak python use <version> <version>  # If Huak supports using more than one environment per-project

Entered to a environments.toml in Huak's home directory:

[scope.python]
"path/to/scope" = "path/to/py-env"

Considering just starting with

#[derive(Subcommand)]
enum PythonEnvironment {
    /// Use a Python environment for the current project.
    Use {
        /// The path to the Python environment.
        #[arg(long)]
        path: Option<PathBuf>,
        /// The path to a project manifest file containing dependencies to install.
        #[arg(long)]
        manifest: Option<PathBuf>,
        /// Requirements files containing PEP 508 requirements to install.
        #[arg(long)]
        requirements: Option<Vec<PathBuf>>,
        /// Force the creation of the Python environment.
        #[arg(short)]
        force: bool,
    },
}

I want there to be clear need for this vs the python use command. python use provides users with a method for using a Python interpreter without regard for what kind of environment it's part of. By default Huak will prepare the selection as part of a Virtual Environment. With python env use you're explicitly interacting with an environment for Python. I'm thinking of features like:

huak py env use --manifest . -f  # Install the dependencies of a project to a Python environment for Huak to use.

Here I'm looking to replace the current huak install command with a subcommand for more options related to interfacing with an environment containing installed dependencies. huak install will be used similar to pipx install.

Thought through this some more. Im hesitant to commit time to this right now since the experience I want from Huak is one where you don't even know the virtual environment is there or is being used.

I don't want to open this door until I've thought about it some more.