1"""Starlark representation of locked requirements. 2 3@generated by rules_python pip_parse repository rule. 4""" 5 6%%IMPORTS%% 7 8all_requirements = %%ALL_REQUIREMENTS%% 9 10all_whl_requirements_by_package = %%ALL_WHL_REQUIREMENTS_BY_PACKAGE%% 11 12all_whl_requirements = all_whl_requirements_by_package.values() 13 14all_data_requirements = %%ALL_DATA_REQUIREMENTS%% 15 16_packages = %%PACKAGES%% 17_config = %%CONFIG%% 18_annotations = %%ANNOTATIONS%% 19 20def requirement(name): 21 return "%%MACRO_TMPL%%".format(pip_utils.normalize_name(name), "pkg") 22 23def whl_requirement(name): 24 return "%%MACRO_TMPL%%".format(pip_utils.normalize_name(name), "whl") 25 26def data_requirement(name): 27 return "%%MACRO_TMPL%%".format(pip_utils.normalize_name(name), "data") 28 29def dist_info_requirement(name): 30 return "%%MACRO_TMPL%%".format(pip_utils.normalize_name(name), "dist_info") 31 32def _get_annotation(requirement): 33 # This expects to parse `setuptools==58.2.0 --hash=sha256:2551203ae6955b9876741a26ab3e767bb3242dafe86a32a749ea0d78b6792f11` 34 # down to `setuptools`. 35 name = requirement.split(" ")[0].split("=")[0].split("[")[0] 36 return _annotations.get(name) 37 38def install_deps(**whl_library_kwargs): 39 """Repository rule macro. Install dependencies from `pip_parse`. 40 41 Args: 42 **whl_library_kwargs: Additional arguments which will flow to underlying 43 `whl_library` calls. See pip_repository.bzl for details. 44 """ 45 46 # Set up the requirement groups 47 all_requirement_groups = %%ALL_REQUIREMENT_GROUPS%% 48 49 requirement_group_mapping = { 50 requirement: group_name 51 for group_name, group_requirements in all_requirement_groups.items() 52 for requirement in group_requirements 53 } 54 55 # %%GROUP_LIBRARY%% 56 57 # Install wheels which may be participants in a group 58 whl_config = dict(_config) 59 whl_config.update(whl_library_kwargs) 60 61 for name, requirement in _packages: 62 group_name = requirement_group_mapping.get(name.replace("%%NAME%%_", "")) 63 group_deps = all_requirement_groups.get(group_name, []) 64 65 whl_library( 66 name = name, 67 requirement = requirement, 68 group_name = group_name, 69 group_deps = group_deps, 70 annotation = _get_annotation(requirement), 71 **whl_config 72 ) 73