PY-18543 Fixed: Package requirements.txt does not respect pip -rfilename.txt (with no spaces between -r and filename.txt)

Update regex for recursive requirement to support case when there is no spaces between -r and filename
This commit is contained in:
Semyon Proshev
2016-03-23 19:22:12 +03:00
parent d6cc35ac93
commit c83a2cf81f
5 changed files with 21 additions and 7 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 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.
@@ -40,7 +40,7 @@ public class PyRequirement {
private static final Pattern NAME = Pattern.compile("\\s*(\\w(\\w|[-.])*)\\s*(.*)");
private static final Pattern VERSION_SPEC = Pattern.compile("\\s*(<=?|>=?|==|!=)\\s*((\\w|[-.])+)");
private static final Pattern EDITABLE_EGG = Pattern.compile("\\s*(-e)?\\s*([^#]*)(#egg=(.*))?");
private static final Pattern RECURSIVE_REQUIREMENT = Pattern.compile("\\s*-r\\s+(.*)");
private static final Pattern RECURSIVE_REQUIREMENT = Pattern.compile("^-r\\s*(.*)");
private static final Pattern VCS_PATH = Pattern.compile(".*/([^/]+)/?");
public enum Relation {
@@ -253,7 +253,7 @@ public class PyRequirement {
*
* @param line requirement to parse
* @return requirement
* @throws java.lang.IllegalArgumentException if line can't be parsed
* @throws IllegalArgumentException if line can't be parsed
*/
@NotNull
public static PyRequirement fromStringGuaranteed(@NotNull final String line) {
@@ -304,7 +304,7 @@ public class PyRequirement {
}
@NotNull
public static List<PyRequirement> parse(@NotNull VirtualFile file, @NotNull Set<VirtualFile> visited) {
private static List<PyRequirement> parse(@NotNull VirtualFile file, @NotNull Set<VirtualFile> visited) {
if (!visited.contains(file)) {
visited.add(file);
final Document document = FileDocumentManager.getInstance().getDocument(file);
@@ -339,9 +339,9 @@ public class PyRequirement {
}
@NotNull
private static List<PyRequirement> parseRecursiveRequirement(@NotNull String line, @NotNull VirtualFile anchor,
private static List<PyRequirement> parseRecursiveRequirement(@NotNull String trimmedLine, @NotNull VirtualFile anchor,
@NotNull Set<VirtualFile> visited) {
final Matcher matcher = RECURSIVE_REQUIREMENT.matcher(line);
final Matcher matcher = RECURSIVE_REQUIREMENT.matcher(trimmedLine);
if (matcher.matches()) {
final String fileName = FileUtil.toSystemIndependentName(matcher.group(1));
final VirtualFile dir = anchor.getParent();
@@ -0,0 +1 @@
bitly_api
@@ -0,0 +1 @@
numpy
@@ -0,0 +1,2 @@
-r requirements.a.txt
-rrequirements.b.txt
@@ -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.
@@ -15,6 +15,7 @@
*/
package com.jetbrains.python;
import com.intellij.openapi.vfs.VirtualFile;
import com.jetbrains.python.fixtures.PyTestCase;
import com.jetbrains.python.packaging.PyPackage;
import com.jetbrains.python.packaging.PyRequirement;
@@ -100,6 +101,15 @@ public class PyRequirementTest extends PyTestCase {
PyRequirement.fromString("git+git://github.com/django/django.git@stable/1.5.x"));
}
// PY-18543
public void testRecursiveRequirement() {
final VirtualFile requirementsFile = getVirtualFileByName(getTestDataPath() + "/requirement/recursive/requirements.txt");
assertNotNull(requirementsFile);
assertEquals(list(new PyRequirement("bitly_api"), new PyRequirement("numpy")),
PyRequirement.parse(requirementsFile));
}
private static <T> List<T> list(T... xs) {
return Arrays.asList(xs);
}