-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Analyze design of environment management #2288
Comments
Also see #1479. |
Basically we need to know what kind of shell we use when we run subprocesses to know if we will pick up e.g. environment variables as set by folks in their |
Requirements:
|
IdeasNote that these overlap substantially. So it isn't just a matter of choosing one. :) Idea 1 (Single class for each type)Have a single interface that does everything for a type of Python environment.
IEnvironment:
Note:
Idea 2 (Composition)Instead I'm for composition. I.e. Similar to what we have today, but refactor it to make it more maintainable. Note:
Idea 3Proposal by @d3r3kk that we go with interfaces such as IInterpreter that'll have members such as:
This is similar to the first approach but each instance of returning simple data objects we return objects that have can in turn do stuff. @d3r3kk please feel free to update accordingly. Idea 4Like Option 2, but have one class per environment type that implements the granular interfaces. Idea 53 tiers of info:
Here's a rough (and incomplete) sketch the should give you a sense of where I'd put info and functionality. export interface IPythonDistribution {
readonly name: NonEmptyString;
readonly version: semver.SemVer;
readonly publisher: NonEmptyString;
readonly supportedVersions: ISupportedPythonVersions;
readonly envs: IPythonEnvironments;
/**
* Add a new virtual environment using the distro.
*/
createVenv(spec: IVenvSpec, version?: IPythonVersion): IPythonEnvironment;
}
export interface ISupportedPythonVersions {
readonly [index: number]: ISupportedPythonVersion;
}
export interface ISupportedPythonVersion extends IPythonVersion {
readonly installed: boolean;
/**
* Ensure that the Python version is installed.
*
* If that version of Python is directly usable then a new
* environment is returned. Otherwise null is returned.
*/
ensureInstalled(): IPythonEnvironment | null;
}
//================================
// Python environments
export enum PythonEnvKind {
Unknown,
Global,
Venv,
VirtualEnv,
PyEnv,
PipEnv
}
export interface IPythonEnvironment {
readonly name: NonEmptyString;
readonly kind: PythonEnvKind;
readonly distro: IPythonDistribution;
readonly interpreter: IPythonInterpreter;
readonly spec?: IVenvSpec;
readonly packages: IPythonPackages;
/**
* Add a new virtual environment based on this env.
*/
createVenv(IVenvSpec): IPythonEnvironment;
// TODO: activation
/**
* Remove this environment.
*/
destroy(): void;
}
export interface IPythonEnvironments {
readonly [index: number]: IPythonEnvironment;
}
export interface IVenvSpec {
readonly name: NonEmptyString;
readonly dirname?: NonEmptyString;
}
//================================
// Python packages
export interface IPythonPackages {
lookUp(string | IPythonPackageSpec): ISupportedPythonPackage;
listAll(): IPythonPackage[];
}
export interface IPythonPackageSpec {
readonly name: NonEmptyString;
readonly version: semver.SemVer;
}
export interface ISupportedPythonPackage extends IPythonPackageSpec {
install(): IPythonPackage[];
}
export interface IPythonPackage extends IPythonPackageSpec {
uninstall(): void;
}
//================================
// Python interpreters
/**
* A wrapper around a single Python interpreter.
*/
export interface IPythonInterpreter {
readonly filename: NonEmptyString;
readonly version: IPythonVersion;
readonly env: IPythonEnvironment;
}
export enum PythonReleaseLevel {
Alpha,
Beta,
Candidate,
Final
}
export interface IPythonRelease {
readonly releaseLevel: PythonReleaseLevel;
readonly serial: int;
toString(): string;
}
export interface IPythonVersion {
readonly major: int;
readonly minor: int;
readonly micro?: int;
readonly release?: IPythonRelease;
toString(): string;
} Idea 6
Idea 7<TBD> |
I was actually thinking option 1 because as you outlined in the requirements you really only need 4 methods, but I'm not attached to the idea. |
@d3r3kk @ericsnowcurrently |
Here's an incremental approach to solving this issue:
|
While the extension supports discovery of virtual environments in a number of cases, there are still many ways in which they can remain undiscovered. I personally ran into this the other day using the Python-distributed venv, but it applies equally to virtualenv, pyenv, pipenv, anaconda, etc.
Automatic discovery is doable if we can keep in sync with the facilities for discovering environments of the different tools. However, there are limits to that, including the following contributing factors (see #2142):
Note that this relates closely to the issues of getting info from the terminal and of running subprocesses with the right environment variables.
The text was updated successfully, but these errors were encountered: