Skip to content

Commit fbf3bed

Browse files
committed
Use a version-specific pip installation script for old Python versions
Fixes #34
1 parent 8f0c2be commit fbf3bed

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/main/groovy/com/jetbrains/python/envs/PythonEnvsPlugin.groovy

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class PythonEnvsPlugin implements Plugin<Project> {
1919
private static Boolean isUnix = Os.isFamily(Os.FAMILY_UNIX)
2020
private static Boolean isMacOsX = Os.isFamily(Os.FAMILY_MAC)
2121

22+
private static final String PIP_MINIMAL_SUPPORTED_VERSION = "3.9"
23+
2224
private static URL getUrlToDownloadConda(Conda conda) {
2325
final String repository = (conda.version.toLowerCase().contains("miniconda")) ? "miniconda" : "archive"
2426
final String arch = getArch()
@@ -80,11 +82,24 @@ class PythonEnvsPlugin implements Plugin<Project> {
8082
return new File(dir ?: env.envDir, pathString)
8183
}
8284

83-
private static File getPipFile(Project project) {
84-
new File(project.buildDir, "get-pip.py").with { file ->
85+
private static File getPipFile(Project project, String versionStr) {
86+
def version = VersionNumber.parse(versionStr)
87+
String name
88+
String remoteUrl
89+
if (version < VersionNumber.parse(PIP_MINIMAL_SUPPORTED_VERSION)) {
90+
// use version-specific script
91+
def shortVersion = "${version.major}.${version.minor}"
92+
name = "get-pip-${shortVersion}.py"
93+
remoteUrl = "https://bootstrap.pypa.io/pip/3.8/get-pip.py"
94+
} else {
95+
name = "get-pip.py"
96+
remoteUrl = "https://bootstrap.pypa.io/get-pip.py"
97+
}
98+
99+
new File(project.buildDir, name).with { file ->
85100
if (!file.exists()) {
86101
project.ant.get(dest: file) {
87-
url(url: "https://bootstrap.pypa.io/get-pip.py")
102+
url(url: remoteUrl)
88103
}
89104
}
90105
return file
@@ -230,7 +245,7 @@ class PythonEnvsPlugin implements Plugin<Project> {
230245
project.logger.quiet("Downloading & installing pip and setuptools")
231246
project.exec {
232247
executable getExecutable("python", env)
233-
args getPipFile(project)
248+
args getPipFile(project, env.version)
234249
}
235250
}
236251
// It's better to save installer for good uninstall
@@ -378,7 +393,7 @@ class PythonEnvsPlugin implements Plugin<Project> {
378393
args "-m", "ensurepip"
379394
} else {
380395
executable getExecutable("python", env)
381-
args getPipFile(project)
396+
args getPipFile(project, env.version)
382397
}
383398
}
384399
}

0 commit comments

Comments
 (0)