-
-
Notifications
You must be signed in to change notification settings - Fork 677
package rules should create wrappers around tool entry_points #341
Description
This feature is inspired by how we handle the ecosystem of tools in rules_nodejs.
For a long time we assumed we needed to write custom rules for each tool in the ecosystem. The last one of these was for the Less CSS preprocessor. Then we realized that since we have Starlark code generating BUILD files to dep on each installed package (via pip_install for example, but will apply for poetry or others), we could also generate .bzl files to call tools. Now every tool in npm ecosystem can be called from Bazel (I wrote more about it )
For example if I pip_install the package Sphinx==3.1.1 then today I can load("@my_deps//:requirements.bzl", "requirement") and dep on requirement("sphinx") - but loading sphinx as a dep is not the common way to use it. It's a utility for generating documentation so it should be called as a separate action, without me writing a custom program to drive it.
This is evident from the package metadata
% less $HOME/.pyenv/versions/3.6.5/lib/python3.6/site-packages/Sphinx-3.1.1.dist-info/entry_points.txt
[console_scripts]
sphinx-build = sphinx.cmd.build:main
So users actually want to do something like this:
load("@my_deps//sphinx:defs.bzl", "sphinx_build")
sphinx_build(
name = "docgen",
srcs = glob(["docs/**"]),
args = ["-b", "html", "$(@D)"],
outdir = "html",
)
Similarly it should be possible to grab a server from pypi and bazel run it, or a testing framework and bazel test it. So in rules_nodejs we actually generate three things in the generated .bzl for any package that exposes entry points.