Skip to content

Commit e6c4885

Browse files
committed
fix pip version recognition
1 parent b990139 commit e6c4885

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/main/groovy/ru/vyarus/gradle/plugin/python/cmd/Pip.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,14 @@ class Pip {
115115
Matcher matcher = VERSION.matcher(versionLine)
116116
if (matcher.find()) {
117117
// note: this will drop beta postfix (e.g. for 10.0.0b2 version will be 10.0.0)
118-
return matcher.group(1)
118+
String ver = matcher.group(1)
119+
if (ver) {
120+
return ver
121+
}
119122
}
120123
// if can't recognize version, ask directly
121124
return python.withHiddenLog {
122125
python.readOutput('-c \"import pip; print(pip.__version__)\"')
123-
.readLines()
124126
}
125127
}
126128

src/test/groovy/ru/vyarus/gradle/plugin/python/cmd/PipCliTest.groovy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import org.gradle.api.Project
44
import org.gradle.testfixtures.ProjectBuilder
55
import ru.vyarus.gradle.plugin.python.AbstractTest
66

7+
import java.util.regex.Pattern
8+
79
/**
810
* @author Vyacheslav Rusakov
911
* @since 20.11.2017
@@ -40,4 +42,26 @@ class PipCliTest extends AbstractTest {
4042
pip.version =~ /\d+\.\d+\.\d+/
4143
pip.versionLine =~ /pip \d+\.\d+\.\d+ from/
4244
}
45+
46+
def "Check version parse fail"() {
47+
48+
when: "prepare pip"
49+
Project project = project()
50+
Pip pip = new FooPip(project)
51+
then: "ok"
52+
pip.version =~ /\d+\.\d+\.\d+/
53+
54+
}
55+
56+
class FooPip extends Pip {
57+
58+
FooPip(Project project) {
59+
super(project)
60+
}
61+
62+
@Override
63+
String getVersionLine() {
64+
return 'you will not parse it'
65+
}
66+
}
4367
}

0 commit comments

Comments
 (0)