aboutsummaryrefslogtreecommitdiff
path: root/python/pip_install/pip_repository_requirements.bzl.tmpl
blob: 411f334671856aafa8af97414deb75a0eda86ed3 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Starlark representation of locked requirements.

@generated by rules_python pip_parse repository rule
from %%REQUIREMENTS_LOCK%%
"""

%%IMPORTS%%

all_requirements = %%ALL_REQUIREMENTS%%

all_whl_requirements = %%ALL_WHL_REQUIREMENTS%%

all_data_requirements = %%ALL_DATA_REQUIREMENTS%%

_packages = %%PACKAGES%%
_config = %%CONFIG%%
_annotations = %%ANNOTATIONS%%

def _clean_name(name):
    return name.replace("-", "_").replace(".", "_").lower()

def requirement(name):
    return "@%%NAME%%_" + _clean_name(name) + "//:pkg"

def whl_requirement(name):
    return "@%%NAME%%_" + _clean_name(name) + "//:whl"

def data_requirement(name):
    return "@%%NAME%%_" + _clean_name(name) + "//:data"

def dist_info_requirement(name):
    return "@%%NAME%%_" + _clean_name(name) + "//:dist_info"

def entry_point(pkg, script = None):
    if not script:
        script = pkg
    return "@%%NAME%%_" + _clean_name(pkg) + "//:rules_python_wheel_entry_point_" + script

def _get_annotation(requirement):
    # This expects to parse `setuptools==58.2.0     --hash=sha256:2551203ae6955b9876741a26ab3e767bb3242dafe86a32a749ea0d78b6792f11`
    # down to `setuptools`.
    name = requirement.split(" ")[0].split("=")[0].split("[")[0]
    return _annotations.get(name)

def install_deps(**whl_library_kwargs):
    whl_config = dict(_config)
    whl_config.update(whl_library_kwargs)
    for name, requirement in _packages:
        whl_library(
            name = name,
            requirement = requirement,
            annotation = _get_annotation(requirement),
            **whl_config
        )