@@ -120,6 +120,10 @@ private const val OPTION_OPERATING_SYSTEM = "operatingSystem"
120
120
private const val OPTION_OPERATING_SYSTEM_DEFAULT = " linux"
121
121
private val OPERATING_SYSTEMS = listOf (" linux" , " mac" , " windows" )
122
122
123
+ private const val OPTION_PYTHON_VERSION = " pythonVersion"
124
+ private const val OPTION_PYTHON_VERSION_DEFAULT = " 3.10"
125
+ private val PYTHON_VERSIONS = listOf (" 2.7" , " 3.6" , " 3.7" , " 3.8" , " 3.9" , " 3.10" )
126
+
123
127
/* *
124
128
* The [PIP](https://pip.pypa.io/) package manager for Python. Also see
125
129
* [install_requires vs requirements files](https://packaging.python.org/discussions/install-requires-vs-requirements/)
@@ -128,6 +132,7 @@ private val OPERATING_SYSTEMS = listOf("linux", "mac", "windows")
128
132
* This package manager supports the following [options][PackageManagerConfiguration.options]:
129
133
* - *operatingSystem*: The name of the operating system to resolve dependencies for. One of "linux", "mac", or
130
134
* "windows". Defaults to "linux".
135
+ * - *pythonVersion*: The Python version to resolve dependencies for. Defaults to "3.10".
131
136
*/
132
137
@Suppress(" TooManyFunctions" )
133
138
class Pip (
@@ -157,6 +162,13 @@ class Pip(
157
162
}
158
163
}
159
164
165
+ private val pythonVersionOption = (options[OPTION_PYTHON_VERSION ] ? : OPTION_PYTHON_VERSION_DEFAULT )
166
+ .also { pythonVersion ->
167
+ require(pythonVersion in PYTHON_VERSIONS ) {
168
+ " The 'pythonVersion' option must be one of ${PYTHON_VERSIONS .joinToString { " '$it '" }} ."
169
+ }
170
+ }
171
+
160
172
override fun command (workingDir : File ? ) = " pip"
161
173
162
174
override fun transformVersion (output : String ) = output.removePrefix(" pip " ).substringBefore(' ' )
@@ -193,7 +205,7 @@ class Pip(
193
205
val virtualEnvDir = setupVirtualEnv(workingDir, pythonMajorVersion)
194
206
195
207
val project = getProjectBasics(definitionFile, virtualEnvDir)
196
- val (packages, installDependencies) = getInstallDependencies(definitionFile, pythonMajorVersion )
208
+ val (packages, installDependencies) = getInstallDependencies(definitionFile)
197
209
198
210
// TODO: Handle "extras" and "tests" dependencies.
199
211
val scopes = sortedSetOf(
@@ -287,29 +299,20 @@ class Pip(
287
299
)
288
300
}
289
301
290
- private fun getInstallDependencies (
291
- definitionFile : File ,
292
- pythonMajorVersion : Int
293
- ): Pair <SortedSet <Package >, SortedSet<PackageReference>> {
302
+ private fun getInstallDependencies (definitionFile : File ): Pair <SortedSet <Package >, SortedSet<PackageReference>> {
294
303
val workingDir = definitionFile.parentFile
295
304
296
- val pythonVersion = when (pythonMajorVersion) {
297
- 2 -> " 2.7" // 2.7 is the only 2.x version supported by python-inspector.
298
- 3 -> " 3.10" // 3.10 is the version currently used in the ORT Docker image.
299
- else -> throw IllegalArgumentException (" Unsupported Python major version '$pythonMajorVersion '." )
300
- }
301
-
302
305
logger.info {
303
- " Resolving dependencies for '${definitionFile.absolutePath} ' with Python version '$pythonVersion ' and " +
304
- " operating system '$operatingSystemOption '."
306
+ " Resolving dependencies for '${definitionFile.absolutePath} ' with Python version '$pythonVersionOption ' " +
307
+ " and operating system '$operatingSystemOption '."
305
308
}
306
309
307
310
val pythonInspectorResult = runCatching {
308
311
try {
309
312
PythonInspector .run (
310
313
workingDir = workingDir,
311
314
definitionFile = definitionFile,
312
- pythonVersion = pythonVersion .replace(" ." , " " ),
315
+ pythonVersion = pythonVersionOption .replace(" ." , " " ),
313
316
operatingSystem = operatingSystemOption
314
317
)
315
318
} finally {
0 commit comments