aboutsummaryrefslogtreecommitdiff
path: root/python/pip_install/pip_repository_requirements.bzl.tmpl
diff options
context:
space:
mode:
Diffstat (limited to 'python/pip_install/pip_repository_requirements.bzl.tmpl')
-rw-r--r--python/pip_install/pip_repository_requirements.bzl.tmpl54
1 files changed, 54 insertions, 0 deletions
diff --git a/python/pip_install/pip_repository_requirements.bzl.tmpl b/python/pip_install/pip_repository_requirements.bzl.tmpl
new file mode 100644
index 0000000..411f334
--- /dev/null
+++ b/python/pip_install/pip_repository_requirements.bzl.tmpl
@@ -0,0 +1,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
+ )