|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import { Uri } from 'vscode'; |
| 5 | +import { Architecture } from '../../../common/utils/platform'; |
| 6 | +import { BasicVersionInfo, VersionInfo } from '../../../common/utils/version'; |
| 7 | + |
| 8 | +/** |
| 9 | + * IDs for the various supported Python environments. |
| 10 | + */ |
| 11 | +export enum PythonEnvKind { |
| 12 | + Unknown = 'unknown', |
| 13 | + // "global" |
| 14 | + System = 'global-system', |
| 15 | + MacDefault = 'global-mac-default', |
| 16 | + WindowsStore = 'global-windows-store', |
| 17 | + Pyenv = 'global-pyenv', |
| 18 | + CondaBase = 'global-conda-base', |
| 19 | + Custom = 'global-custom', |
| 20 | + OtherGlobal = 'global-other', |
| 21 | + // "virtual" |
| 22 | + Venv = 'virt-venv', |
| 23 | + VirtualEnv = 'virt-virtualenv', |
| 24 | + Pipenv = 'virt-pipenv', |
| 25 | + Conda = 'virt-conda', |
| 26 | + OtherVirtual = 'virt-other' |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * Information about a Python binary/executable. |
| 31 | + */ |
| 32 | +export type PythonExecutableInfo = { |
| 33 | + filename: string; |
| 34 | + sysPrefix: string; |
| 35 | + ctime: number; |
| 36 | + mtime: number; |
| 37 | +}; |
| 38 | + |
| 39 | +/** |
| 40 | + * A (system-global) unique ID for a single Python environment. |
| 41 | + */ |
| 42 | +export type PythonEnvID = string; |
| 43 | + |
| 44 | +/** |
| 45 | + * The most fundamental information about a Python environment. |
| 46 | + * |
| 47 | + * You should expect these objects to be complete (no empty props). |
| 48 | + * Note that either `name` or `location` must be non-empty, though |
| 49 | + * the other *can* be empty. |
| 50 | + * |
| 51 | + * @prop id - the env's unique ID |
| 52 | + * @prop kind - the env's kind |
| 53 | + * @prop executable - info about the env's Python binary |
| 54 | + * @prop name - the env's distro-specific name, if any |
| 55 | + * @prop location - the env's location (on disk), if relevant |
| 56 | + */ |
| 57 | +export type PythonEnvBaseInfo = { |
| 58 | + id: PythonEnvID; |
| 59 | + kind: PythonEnvKind; |
| 60 | + executable: PythonExecutableInfo; |
| 61 | + // One of (name, location) must be non-empty. |
| 62 | + name: string; |
| 63 | + location: string; |
| 64 | + // Other possible fields: |
| 65 | + // * managed: boolean (if the env is "managed") |
| 66 | + // * parent: PythonEnvBaseInfo (the env from which this one was created) |
| 67 | + // * binDir: string (where env-installed executables are found) |
| 68 | +}; |
| 69 | + |
| 70 | +/** |
| 71 | + * The possible Python release levels. |
| 72 | + */ |
| 73 | +export enum PythonReleaseLevel { |
| 74 | + Alpha = 'alpha', |
| 75 | + Beta = 'beta', |
| 76 | + Candidate = 'candidate', |
| 77 | + Final = 'final' |
| 78 | +} |
| 79 | + |
| 80 | +/** |
| 81 | + * Release information for a Python version. |
| 82 | + */ |
| 83 | +export type PythonVersionRelease = { |
| 84 | + level: PythonReleaseLevel; |
| 85 | + serial: number; |
| 86 | +}; |
| 87 | + |
| 88 | +/** |
| 89 | + * Version information for a Python build/installation. |
| 90 | + * |
| 91 | + * @prop sysVersion - the raw text from `sys.version` |
| 92 | + */ |
| 93 | +export type PythonVersion = BasicVersionInfo & { |
| 94 | + release: PythonVersionRelease; |
| 95 | + sysVersion?: string; |
| 96 | +}; |
| 97 | + |
| 98 | +/** |
| 99 | + * Information for a Python build/installation. |
| 100 | + */ |
| 101 | +export type PythonBuildInfo = { |
| 102 | + version: PythonVersion; // incl. raw, AKA sys.version |
| 103 | + arch: Architecture; |
| 104 | +}; |
| 105 | + |
| 106 | +/** |
| 107 | + * Meta information about a Python distribution. |
| 108 | + * |
| 109 | + * @prop org - the name of the distro's creator/publisher |
| 110 | + * @prop defaultDisplayName - the text to use when showing the distro to users |
| 111 | + */ |
| 112 | +export type PythonDistroMetaInfo = { |
| 113 | + org: string; |
| 114 | + defaultDisplayName?: string; |
| 115 | +}; |
| 116 | + |
| 117 | +/** |
| 118 | + * Information about an installed Python distribution. |
| 119 | + * |
| 120 | + * @prop version - the installed *distro* version (not the Python version) |
| 121 | + * @prop binDir - where to look for the distro's executables (i.e. tools) |
| 122 | + */ |
| 123 | +export type PythonDistroInfo = PythonDistroMetaInfo & { |
| 124 | + version?: VersionInfo; |
| 125 | + binDir?: string; |
| 126 | +}; |
| 127 | + |
| 128 | +type _PythonEnvInfo = PythonEnvBaseInfo & PythonBuildInfo; |
| 129 | + |
| 130 | +/** |
| 131 | + * All the available information about a Python environment. |
| 132 | + * |
| 133 | + * Note that not all the information will necessarily be filled in. |
| 134 | + * Locators are only required to fill in the "base" info, though |
| 135 | + * they will usually be able to provide the version as well. |
| 136 | + * |
| 137 | + * @prop distro - the installed Python distro that this env is using or belongs to |
| 138 | + * @prop defaultDisplayName - the text to use when showing the env to users |
| 139 | + * @prop searchLocation - the root under which a locator found this env, if any |
| 140 | + */ |
| 141 | +export type PythonEnvInfo = _PythonEnvInfo & { |
| 142 | + distro: PythonDistroInfo; |
| 143 | + defaultDisplayName?: string; |
| 144 | + searchLocation?: Uri; |
| 145 | +}; |
0 commit comments