mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-20880 Fixed: Package requirements inspection does not support local version identifiers
Update matching EQ version spec: if both versions contain local label, check if they are equals as strings; if only passed version contains local label, then just drop it and check public parts.
This commit is contained in:
+17
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.jetbrains.python.packaging.requirement;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.intellij.webcore.packaging.PackageVersionComparator.VERSION_COMPARATOR;
|
||||
@@ -72,7 +73,13 @@ public class PyRequirementVersionSpec {
|
||||
case GTE:
|
||||
return VERSION_COMPARATOR.compare(version, myVersion) >= 0;
|
||||
case EQ:
|
||||
return VERSION_COMPARATOR.compare(version, myVersion) == 0;
|
||||
final Pair<String, String> publicAndLocalVersions = splitIntoPublicAndLocalVersions(myVersion);
|
||||
final Pair<String, String> otherPublicAndLocalVersions = splitIntoPublicAndLocalVersions(version);
|
||||
final boolean publicVersionsAreSame =
|
||||
VERSION_COMPARATOR.compare(otherPublicAndLocalVersions.first, publicAndLocalVersions.first) == 0;
|
||||
|
||||
return publicVersionsAreSame &&
|
||||
(publicAndLocalVersions.second.isEmpty() || otherPublicAndLocalVersions.second.equals(publicAndLocalVersions.second));
|
||||
case NE:
|
||||
return VERSION_COMPARATOR.compare(version, myVersion) != 0;
|
||||
case COMPATIBLE:
|
||||
@@ -83,4 +90,13 @@ public class PyRequirementVersionSpec {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static Pair<String, String> splitIntoPublicAndLocalVersions(@NotNull String version) {
|
||||
final String[] publicAndLocalVersions = version.split("\\+", 2);
|
||||
|
||||
final String publicVersion = publicAndLocalVersions[0];
|
||||
final String localVersion = publicAndLocalVersions.length == 1 ? "" : publicAndLocalVersions[1];
|
||||
|
||||
return Pair.createNonNull(publicVersion, localVersion);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2220,7 +2220,7 @@ public class PyRequirementTest extends PyTestCase {
|
||||
// PY-6355
|
||||
public void testTrailingZeroesInVersion() {
|
||||
final PyRequirement req = PyRequirement.fromLine("foo==0.8.0");
|
||||
final PyPackage pkg = new PyPackage("foo", "0.8", null, Collections.<PyRequirement>emptyList());
|
||||
final PyPackage pkg = new PyPackage("foo", "0.8", null, Collections.emptyList());
|
||||
assertNotNull(req);
|
||||
assertEquals(pkg, req.match(Collections.singletonList(pkg)));
|
||||
}
|
||||
@@ -2228,7 +2228,7 @@ public class PyRequirementTest extends PyTestCase {
|
||||
// PY-6438
|
||||
public void testUnderscoreMatchesDash() {
|
||||
final PyRequirement req = PyRequirement.fromLine("pyramid_zcml");
|
||||
final PyPackage pkg = new PyPackage("pyramid-zcml", "0.1", null, Collections.<PyRequirement>emptyList());
|
||||
final PyPackage pkg = new PyPackage("pyramid-zcml", "0.1", null, Collections.emptyList());
|
||||
assertNotNull(req);
|
||||
assertEquals(pkg, req.match(Collections.singletonList(pkg)));
|
||||
}
|
||||
@@ -2241,6 +2241,20 @@ public class PyRequirementTest extends PyTestCase {
|
||||
assertEquals(pkg, req.match(Collections.singletonList(pkg)));
|
||||
}
|
||||
|
||||
// PY-20880
|
||||
public void testMatchingLocalVersions() {
|
||||
final PyPackage firstPackageWithLocalVersion = new PyPackage("foo", "1.0+foo0100", null, Collections.emptyList());
|
||||
final PyPackage secondPackageWithLocalVersion = new PyPackage("foo", "1.0+foo0101", null, Collections.emptyList());
|
||||
|
||||
final PyRequirement requirement = PyRequirement.fromLine("foo==1.0");
|
||||
assertEquals(firstPackageWithLocalVersion, requirement.match(Collections.singletonList(firstPackageWithLocalVersion)));
|
||||
assertEquals(secondPackageWithLocalVersion, requirement.match(Collections.singletonList(secondPackageWithLocalVersion)));
|
||||
|
||||
final PyRequirement requirementWithLocalVersion = PyRequirement.fromLine("foo==1.0+foo0100");
|
||||
assertEquals(firstPackageWithLocalVersion, requirementWithLocalVersion.match(Collections.singletonList(firstPackageWithLocalVersion)));
|
||||
assertNull(requirementWithLocalVersion.match(Collections.singletonList(secondPackageWithLocalVersion)));
|
||||
}
|
||||
|
||||
// OPTIONS
|
||||
public void testOptions() {
|
||||
assertEmpty(
|
||||
|
||||
Reference in New Issue
Block a user