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