mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-20242 Fixed: PyCharm thinks package requirement is not satisfied, but it is.
Update matching version against specs so '===' relation is supported now. Also PyRequirementVersionSpec become responsible for matching version against itself.
This commit is contained in:
@@ -22,7 +22,6 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.webcore.packaging.PackageVersionComparator;
|
||||
import com.jetbrains.python.packaging.requirement.PyRequirementRelation;
|
||||
import com.jetbrains.python.packaging.requirement.PyRequirementVersionNormalizer;
|
||||
import com.jetbrains.python.packaging.requirement.PyRequirementVersionSpec;
|
||||
@@ -293,20 +292,14 @@ public class PyRequirement {
|
||||
|
||||
@Nullable
|
||||
public PyPackage match(@NotNull List<PyPackage> packages) {
|
||||
for (PyPackage pkg : packages) {
|
||||
if (normalizeName(myName).equalsIgnoreCase(pkg.getName())) {
|
||||
for (PyRequirementVersionSpec spec : myVersionSpecs) {
|
||||
final int cmp = PackageVersionComparator.VERSION_COMPARATOR.compare(pkg.getVersion(), spec.getVersion());
|
||||
final String normalizedName = normalizeName(myName);
|
||||
|
||||
if (!spec.getRelation().isSuccessful(cmp)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return pkg;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return packages
|
||||
.stream()
|
||||
.filter(pkg -> normalizedName.equalsIgnoreCase(pkg.getName()))
|
||||
.findAny()
|
||||
.filter(pkg -> myVersionSpecs.stream().allMatch(spec -> spec.matches(pkg.getVersion())))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
-29
@@ -16,7 +16,6 @@
|
||||
package com.jetbrains.python.packaging.requirement;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum PyRequirementRelation {
|
||||
|
||||
@@ -41,32 +40,4 @@ public enum PyRequirementRelation {
|
||||
public String toString() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PyRequirementRelation fromString(@NotNull String value) {
|
||||
for (PyRequirementRelation relation : PyRequirementRelation.values()) {
|
||||
if (relation.myValue.equals(value)) {
|
||||
return relation;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isSuccessful(int comparisonResult) {
|
||||
switch (this) {
|
||||
case LT:
|
||||
return comparisonResult < 0;
|
||||
case LTE:
|
||||
return comparisonResult <= 0;
|
||||
case GT:
|
||||
return comparisonResult > 0;
|
||||
case GTE:
|
||||
return comparisonResult >= 0;
|
||||
case EQ:
|
||||
return comparisonResult == 0;
|
||||
case NE:
|
||||
return comparisonResult != 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+25
@@ -17,6 +17,8 @@ package com.jetbrains.python.packaging.requirement;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.intellij.webcore.packaging.PackageVersionComparator.VERSION_COMPARATOR;
|
||||
|
||||
public class PyRequirementVersionSpec {
|
||||
|
||||
@NotNull
|
||||
@@ -58,4 +60,27 @@ public class PyRequirementVersionSpec {
|
||||
public String getVersion() {
|
||||
return myVersion;
|
||||
}
|
||||
|
||||
public boolean matches(@NotNull String version) {
|
||||
switch (myRelation) {
|
||||
case LT:
|
||||
return VERSION_COMPARATOR.compare(version, myVersion) < 0;
|
||||
case LTE:
|
||||
return VERSION_COMPARATOR.compare(version, myVersion) <= 0;
|
||||
case GT:
|
||||
return VERSION_COMPARATOR.compare(version, myVersion) > 0;
|
||||
case GTE:
|
||||
return VERSION_COMPARATOR.compare(version, myVersion) >= 0;
|
||||
case EQ:
|
||||
return VERSION_COMPARATOR.compare(version, myVersion) == 0;
|
||||
case NE:
|
||||
return VERSION_COMPARATOR.compare(version, myVersion) != 0;
|
||||
case COMPATIBLE:
|
||||
return false; // TODO: implement matching version against compatible relation
|
||||
case STR_EQ:
|
||||
return version.equals(myVersion);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2203,10 +2203,10 @@ public class PyRequirementTest extends PyTestCase {
|
||||
|
||||
// PY-6355
|
||||
public void testTrailingZeroesInVersion() {
|
||||
final PyRequirement req080 = PyRequirement.fromLine("foo==0.8.0");
|
||||
final PyPackage pack08 = new PyPackage("foo", "0.8", null, Collections.<PyRequirement>emptyList());
|
||||
assertNotNull(req080);
|
||||
assertNotNull(req080.match(Collections.singletonList(pack08)));
|
||||
final PyRequirement req = PyRequirement.fromLine("foo==0.8.0");
|
||||
final PyPackage pkg = new PyPackage("foo", "0.8", null, Collections.<PyRequirement>emptyList());
|
||||
assertNotNull(req);
|
||||
assertEquals(pkg, req.match(Collections.singletonList(pkg)));
|
||||
}
|
||||
|
||||
// PY-6438
|
||||
@@ -2214,7 +2214,15 @@ public class PyRequirementTest extends PyTestCase {
|
||||
final PyRequirement req = PyRequirement.fromLine("pyramid_zcml");
|
||||
final PyPackage pkg = new PyPackage("pyramid-zcml", "0.1", null, Collections.<PyRequirement>emptyList());
|
||||
assertNotNull(req);
|
||||
assertNotNull(req.match(Collections.singletonList(pkg)));
|
||||
assertEquals(pkg, req.match(Collections.singletonList(pkg)));
|
||||
}
|
||||
|
||||
// PY-20242
|
||||
public void testVersionInterpretedAsString() {
|
||||
final PyRequirement req = PyRequirement.fromLine("foo===version");
|
||||
final PyPackage pkg = new PyPackage("foo", "version", null, Collections.emptyList());
|
||||
assertNotNull(req);
|
||||
assertEquals(pkg, req.match(Collections.singletonList(pkg)));
|
||||
}
|
||||
|
||||
// OPTIONS
|
||||
|
||||
Reference in New Issue
Block a user