PY-20939 Fixed: PyCharm should not suggest to update locally patched package of the last version

Override compareVersions in PyPackageManagementService to catch equal package versions which are not handled by VERSION_COMPARATOR
This commit is contained in:
Semyon Proshev
2016-10-24 17:35:43 +03:00
parent 0ef3e04e70
commit 1b3872e12b
2 changed files with 13 additions and 2 deletions
@@ -333,7 +333,7 @@ public class PyRequirement {
}
@NotNull
private static PyRequirementVersionSpec calculateVersionSpec(@NotNull String version, @NotNull PyRequirementRelation expectedRelation) {
public static PyRequirementVersionSpec calculateVersionSpec(@NotNull String version, @NotNull PyRequirementRelation expectedRelation) {
final String normalizedVersion = PyRequirementVersionNormalizer.normalize(version);
return normalizedVersion == null ?
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@ import com.intellij.webcore.packaging.PackageManagementServiceEx;
import com.intellij.webcore.packaging.RepoPackage;
import com.jetbrains.python.packaging.*;
import com.jetbrains.python.packaging.PyPIPackageUtil.PackageDetails;
import com.jetbrains.python.packaging.requirement.PyRequirementRelation;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.sdk.PySdkUtil;
import com.jetbrains.python.sdk.PythonSdkType;
@@ -386,4 +387,14 @@ public class PyPackageManagementService extends PackageManagementServiceEx {
}
});
}
@Override
public int compareVersions(@NotNull String version1, @NotNull String version2) {
if (PyRequirement.calculateVersionSpec(version2, PyRequirementRelation.EQ).matches(version1)) {
// Here we're catching the case described in PY-20939.
// The order of 'version1' and 'version2' is important: version2 is an available version which version1 tries to match
return 0;
}
return super.compareVersions(version1, version2);
}
}