Description
🚀 feature request
related: #341
Relevant Rules
entry_point
Description
Currently, the entry_point
is a pre-generated py_binary
to expose the console_scripts
. It works for tools that takes file as input and with limited reliance on module resolution e.g. static analysis tools, flake8
, black
.
However, it doesn't quite work with things that expect dependencies on the import path, which is common for running dev server for web development frameworks, e.g flask
, uvicorn
, strawberry
. In order for these use cases to work, we need a mechanism to properly propagate the import paths when executing the console scripts target.
Describe the solution you'd like
One solution would be to convert entry_point
into a macro that dynamically generate py_binary
on the fly, so that it can take additional deps
attribute to construct the console scripts py_binary
.
Roughly can be implemented as below?
In the generated @pip//:requirements.bzl
load("@rules_python//python:defs.bzl", "py_binary")
load("@pip//:requirements.bzl", "requirement")
def new_entry_point(name, pkg, script = None, **kwargs):
if not script:
script = pkg
entry_point_py = "@{repo_prefix}" + _clean_name(pkg) + "//:{entry_point_prefix}_" + script + ".py"
py_binary(
name = name,
srcs = kwargs.pop("srcs", []) + [entry_point_py],
main = entry_point_py,
deps = kwargs.pop("deps", []) + [requirement(pkg)],
**kwargs
)
In BUILD.bazel
new_entry_porint(
name = "strawberry",
pkg = "strawberry-graphql",
script = "strawberry",
deps = [
":schema",
],
)
Describe alternatives you've considered
use environment variables PYTHONPATH
when calling PYTHONPATH=... bazel run ...
. but it's hard and not trivial to figure out all import paths and add to it.