@@ -40,6 +40,7 @@ import org.ossreviewtoolkit.model.ProjectAnalyzerResult
40
40
import org.ossreviewtoolkit.model.Scope
41
41
import org.ossreviewtoolkit.model.VcsInfo
42
42
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
43
+ import org.ossreviewtoolkit.model.config.PackageManagerConfiguration
43
44
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
44
45
import org.ossreviewtoolkit.utils.common.CommandLineTool
45
46
import org.ossreviewtoolkit.utils.common.Os
@@ -115,10 +116,18 @@ object PythonVersion : CommandLineTool, Logging {
115
116
}
116
117
}
117
118
119
+ private const val OPTION_OPERATING_SYSTEM = " operatingSystem"
120
+ private const val OPTION_OPERATING_SYSTEM_DEFAULT = " linux"
121
+ private val OPERATING_SYSTEMS = listOf (" linux" , " mac" , " windows" )
122
+
118
123
/* *
119
124
* The [PIP](https://pip.pypa.io/) package manager for Python. Also see
120
125
* [install_requires vs requirements files](https://packaging.python.org/discussions/install-requires-vs-requirements/)
121
126
* and [setup.py vs. requirements.txt](https://caremad.io/posts/2013/07/setup-vs-requirement/).
127
+ *
128
+ * This package manager supports the following [options][PackageManagerConfiguration.options]:
129
+ * - *operatingSystem*: The name of the operating system to resolve dependencies for. One of "linux", "mac", or
130
+ * "windows". Defaults to "linux".
122
131
*/
123
132
@Suppress(" TooManyFunctions" )
124
133
class Pip (
@@ -141,6 +150,13 @@ class Pip(
141
150
) = Pip (managerName, analysisRoot, analyzerConfig, repoConfig)
142
151
}
143
152
153
+ private val operatingSystemOption = (getOptions()[OPTION_OPERATING_SYSTEM ] ? : OPTION_OPERATING_SYSTEM_DEFAULT )
154
+ .also { os ->
155
+ require(os.isEmpty() || os in OPERATING_SYSTEMS ) {
156
+ " The 'operatingSystem' option must be one of ${OPERATING_SYSTEMS .joinToString { " '$it '" }} ."
157
+ }
158
+ }
159
+
144
160
override fun command (workingDir : File ? ) = " pip"
145
161
146
162
override fun transformVersion (output : String ) = output.removePrefix(" pip " ).substringBefore(' ' )
@@ -284,15 +300,17 @@ class Pip(
284
300
}
285
301
286
302
logger.info {
287
- " Resolving dependencies for '${definitionFile.absolutePath} ' with Python version '$pythonVersion '."
303
+ " Resolving dependencies for '${definitionFile.absolutePath} ' with Python version '$pythonVersion ' and " +
304
+ " operating system '$operatingSystemOption '."
288
305
}
289
306
290
307
val pythonInspectorResult = runCatching {
291
308
try {
292
309
PythonInspector .run (
293
310
workingDir = workingDir,
294
311
definitionFile = definitionFile,
295
- pythonVersion = pythonVersion.replace(" ." , " " )
312
+ pythonVersion = pythonVersion.replace(" ." , " " ),
313
+ operatingSystem = operatingSystemOption
296
314
)
297
315
} finally {
298
316
workingDir.resolve(" .cache" ).safeDeleteRecursively(force = true )
0 commit comments