forked from bazel-contrib/rules_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_tag.bzl
More file actions
41 lines (35 loc) · 1.22 KB
/
Copy pathpython_tag.bzl
File metadata and controls
41 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"A simple utility function to get the python_tag from the implementation name"
load("//python/private:version.bzl", "version")
# Taken from
# https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/#python-tag
_PY_TAGS = {
# "py": Generic Python (does not require implementation-specific features)
"cpython": "cp",
"ironpython": "ip",
"jython": "jy",
"pypy": "pp",
"python": "py",
}
PY_TAG_GENERIC = "py"
def python_tag(implementation_name, python_version = ""):
"""Get the python_tag from the implementation_name.
Args:
implementation_name: {type}`str` the implementation name, e.g. "cpython"
python_version: {type}`str` a version who can be parsed using PEP440 compliant
parser.
Returns:
A {type}`str` that represents the python_tag with a version if the
python_version is given.
"""
if python_version:
v = version.parse(python_version, strict = True)
suffix = "{}{}".format(
v.release[0],
v.release[1] if len(v.release) > 1 else "",
)
else:
suffix = ""
return "{}{}".format(
_PY_TAGS.get(implementation_name, implementation_name),
suffix,
)