@@ -9,11 +9,8 @@ that generates BUILD file content for Python code.
99First, you'll need to add Gazelle to your ` WORKSPACE ` file.
1010Follow the instructions at https://github.com/bazelbuild/bazel-gazelle#running-gazelle-with-bazel
1111
12- Next, we need to add two more things to the ` WORKSPACE ` :
13-
14- 1 . fetch the third-party Go libraries that the python extension depends on
15- 1 . fetch metadata about your Python dependencies, so that gazelle can
16- determine which package a given import statement comes from.
12+ Next, we need to fetch the third-party Go libraries that the python extension
13+ depends on.
1714
1815Add this to your ` WORKSPACE ` :
1916
@@ -23,22 +20,12 @@ Add this to your `WORKSPACE`:
2320load(" @rules_python//gazelle:deps.bzl" , _py_gazelle_deps = " gazelle_deps" )
2421
2522_py_gazelle_deps()
26-
27- load(" @rules_python//gazelle/modules_mapping:def.bzl" , " modules_mapping" )
28-
29- # This repository rule fetches the metadata for python packages we
30- # depend on. That data is required for the gazelle_python_manifest
31- # rule to update our manifest file.
32- # To see what this rule does, try `bazel run @modules_map//:print`
33- modules_mapping(
34- name = " modules_map" ,
35- # This should point to wherever we declare our python dependencies
36- requirements = " //:requirements_lock.txt" ,
37- )
3823```
3924
40- Next, we'll make a pair of targets for consuming that ` modules_mapping ` we
41- fetched, and writing it as a manifest file for Gazelle to read.
25+ Next, we'll fetch metadata about your Python dependencies, so that gazelle can
26+ determine which package a given import statement comes from. This is provided
27+ by the ` modules_mapping ` rule. We'll make a target for consuming this
28+ ` modules_mapping ` , and writing it as a manifest file for Gazelle to read.
4229This is checked into the repo for speed, as it takes some time to calculate
4330in a large monorepo.
4431
@@ -48,7 +35,16 @@ file. (You can just use `touch` at this point, it just needs to exist.)
4835Then put this in your ` BUILD.bazel ` file next to the ` requirements.txt ` :
4936
5037``` starlark
38+ load(" @pip//:requirements.bzl" , " all_whl_requirements" )
5139load(" @rules_python//gazelle/manifest:defs.bzl" , " gazelle_python_manifest" )
40+ load(" @rules_python//gazelle/modules_mapping:def.bzl" , " modules_mapping" )
41+
42+ # This rule fetches the metadata for python packages we depend on. That data is
43+ # required for the gazelle_python_manifest rule to update our manifest file.
44+ modules_mapping(
45+ name = " modules_map" ,
46+ wheels = all_whl_requirements,
47+ )
5248
5349# Gazelle python extension needs a manifest file mapping from
5450# an import to the installed package that provides it.
@@ -59,9 +55,7 @@ load("@rules_python//gazelle/manifest:defs.bzl", "gazelle_python_manifest")
5955# the manifest doesn't need to be updated
6056gazelle_python_manifest(
6157 name = " gazelle_python_manifest" ,
62- # The @modules_map refers to the name we gave in the modules_mapping
63- # rule in the WORKSPACE
64- modules_mapping = " @modules_map//:modules_mapping.json" ,
58+ modules_mapping = " :modules_map" ,
6559 # This is what we called our `pip_install` rule, where third-party
6660 # python libraries are loaded in BUILD files.
6761 pip_deps_repository_name = " pip" ,
0 commit comments