Only include package versions in Manage Packages dialog if they're supported for the user's version of Python (#14584)

This commit is contained in:
Cory Rivera
2021-03-08 18:05:10 -08:00
committed by GitHub
parent bbdc324f17
commit e2a5859155
6 changed files with 245 additions and 16 deletions

View File

@@ -68,6 +68,7 @@ export interface IJupyterServerInstallation {
uninstallPipPackages(packages: PythonPkgDetails[]): Promise<void>;
pythonExecutable: string;
pythonInstallationPath: string;
installedPythonVersion: string;
}
export const requiredJupyterPkg: PythonPkgDetails = {
@@ -107,6 +108,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
private _pythonExecutable: string;
private _usingExistingPython: boolean;
private _usingConda: boolean;
private _installedPythonVersion: string;
private _installInProgress: boolean;
private _installCompletion: Deferred<void>;
@@ -356,6 +358,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
if (pythonUserDir) {
this.pythonEnvVarPath = pythonUserDir + delimiter + this.pythonEnvVarPath;
}
this._installedPythonVersion = await this.getInstalledPythonVersion(this._pythonExecutable);
}
// Store the executable options to run child processes with env var without interfering parent env var.
@@ -652,6 +655,10 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
return this._usingConda;
}
public get installedPythonVersion(): string {
return this._installedPythonVersion;
}
private isCondaInstalled(): boolean {
let condaExePath = this.getCondaExePath();
// eslint-disable-next-line no-sync
@@ -740,6 +747,12 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
return undefined;
}
private async getInstalledPythonVersion(pythonExecutable: string): Promise<string> {
let cmd = `"${pythonExecutable}" -c "import platform;print(platform.python_version())"`;
let version = await utils.executeBufferedCommand(cmd, {});
return version?.trim() ?? '';
}
public getRequiredPackagesForKernel(kernelName: string): PythonPkgDetails[] {
return this._requiredKernelPackages.get(kernelName) ?? [];
}

View File

@@ -104,7 +104,20 @@ export class LocalCondaPackageManageProvider implements IPackageManageProvider {
let packages = packageJson[packageName];
if (Array.isArray(packages)) {
let allVersions = packages.filter(pkg => pkg && pkg.version).map(pkg => pkg.version);
let allVersions = packages.filter(pkg => {
if (pkg && pkg.version) {
let dependencies = pkg.depends;
if (Array.isArray(dependencies)) {
let strDependencies = dependencies as string[];
let pythonDependency = strDependencies.find(dependency => dependency.trim().toLowerCase().startsWith('python '));
pythonDependency = pythonDependency?.replace('python ', '');
return utils.isPackageSupported(this.jupyterInstallation.installedPythonVersion, [pythonDependency]);
}
return true;
}
return false;
}).map(pkg => pkg.version);
let singletonVersions = new Set<string>(allVersions);
let sortedVersions = utils.sortPackageVersions(Array.from(singletonVersions), false);
return {

View File

@@ -18,7 +18,7 @@ export class LocalPipPackageManageProvider implements IPackageManageProvider {
constructor(
private jupyterInstallation: IJupyterServerInstallation,
private pipyClient: IPyPiClient) {
private pyPiClient: IPyPiClient) {
}
/**
@@ -89,7 +89,7 @@ export class LocalPipPackageManageProvider implements IPackageManageProvider {
}
private async fetchPypiPackage(packageName: string): Promise<IPackageOverview> {
let body = await this.pipyClient.fetchPypiPackage(packageName);
let body = await this.pyPiClient.fetchPypiPackage(packageName);
let packagesJson = JSON.parse(body);
let versionNums: string[] = [];
let packageSummary = '';
@@ -106,7 +106,11 @@ export class LocalPipPackageManageProvider implements IPackageManageProvider {
let versionKeys = Object.keys(packagesJson.releases);
versionKeys = versionKeys.filter(versionKey => {
let releaseInfo = packagesJson.releases[versionKey];
return Array.isArray(releaseInfo) && releaseInfo.length > 0;
if (Array.isArray(releaseInfo) && releaseInfo.length > 0) {
let pythonVersionConstraints = releaseInfo.map<string>(info => info.requires_python);
return utils.isPackageSupported(this.jupyterInstallation.installedPythonVersion, pythonVersionConstraints);
}
return false;
});
versionNums = utils.sortPackageVersions(versionKeys, false);