MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / get_python_version_os

Function get_python_version_os

src/packagedcode/pypi.py:2275–2313  ·  view source on GitHub ↗

Return the "python_version" or "os related values of a ``marker`` requirement Marker or None.

(marker)

Source from the content-addressed store, hash-verified

2273
2274
2275def get_python_version_os(marker):
2276 """
2277 Return the "python_version" or "os related values of a ``marker``
2278 requirement Marker or None.
2279 """
2280 platform_data = {}
2281 python_version_operators = ['<', '>=', '==', '<=', '<']
2282
2283 if not marker or not isinstance(marker, markers.Marker):
2284 return platform_data
2285
2286 marks = getattr(marker, '_markers', [])
2287
2288 for mark in marks:
2289 # filter for variable(extra) == value tuples of (Variable, Op, Value)
2290 if not isinstance(mark, tuple) and not len(mark) == 3:
2291 continue
2292
2293 variable, operator, value = mark
2294
2295 if (
2296 isinstance(variable, markers.Variable)
2297 and variable.value == 'python_version'
2298 and isinstance(operator, markers.Op)
2299 and operator.value in python_version_operators
2300 and isinstance(value, markers.Value)
2301 ):
2302 platform_data["python_version"] = f"{operator.value} {value.value}"
2303
2304 if (
2305 isinstance(variable, markers.Variable)
2306 and variable.value == 'sys_platform'
2307 and isinstance(operator, markers.Op)
2308 and operator.value == '=='
2309 and isinstance(value, markers.Value)
2310 ):
2311 platform_data["sys_platform"] = f"{operator.value} {value.value}"
2312
2313 return platform_data
2314
2315
2316def get_dparse2_supported_file_name(file_name):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected