Enum python_launcher::cli::Action[][src]

pub enum Action {
    Help(StringPathBuf),
    List(String),
    Execute {
        launcher_path: PathBuf,
        executable: PathBuf,
        args: Vec<String>,
    },
}
Expand description

Represents the possible outcomes based on CLI arguments.

Variants

Help(StringPathBuf)

The help string for the Python Launcher along with the path to a Python executable.

The executable path is so that it can be executed with -h to append Python’s own help output.

List(String)

A string listing all found executables on PATH.

The string is formatted to be human-readable.

Execute

Details for executing a Python executable.

Fields of Execute

launcher_path: PathBuf

The Python Launcher used to find the Python executable.

executable: PathBuf

The Python executable to run.

args: Vec<String>

Arguments to the executable.

Implementations

Parses CLI arguments to determine what action should be taken.

The first argument – argv[0] – is considered the path to the Launcher itself (i.e. Action::Execute::launcher_path).

The second argument – argv.get(1) – is used to determine if/what argument has been provided for the Launcher.

Launcher Arguments

-h/--help

Returns Action::Help.

The search for the Python executable to use is done using crate::find_executable with an RequestedVersion::Any argument.

--list

Returns Action::List.

The list of executable is gathered via crate::all_executables.

Version Restriction

Returns the appropriate Action::Execute instance for the requested Python version.

crate::find_executable is used to perform the search.

No Arguments for the Launcher

Returns an Action::Execute instance.

As a first step, a check is done for an activated virtual environment via the VIRTUAL_ENV environment variable. If none is set, look for a virtual environment in a directory named by DEFAULT_VENV_DIR in the current or any parent directories.

If no virtual environment is found, a shebang line is searched for in the first argument to the Python interpreter. If one is found then it is used to (potentially) restrict the requested version searched for.

The search for an interpreter proceeds using crate::find_executable.

Errors

If -h, --help, or --list are specified as the first argument but there are other arguments, crate::Error::IllegalArgument is returned.

If no executable could be found for Action::Help or Action::List, crate::Error::NoExecutableFound is returned.

Panics

  • If a writeln! call fails.
  • If the current directory cannot be accessed.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.