@@ -9,11 +9,8 @@ that generates BUILD file content for Python code.
9
9
First, you'll need to add Gazelle to your ` WORKSPACE ` file.
10
10
Follow the instructions at https://github.com/bazelbuild/bazel-gazelle#running-gazelle-with-bazel
11
11
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.
17
14
18
15
Add this to your ` WORKSPACE ` :
19
16
@@ -23,22 +20,12 @@ Add this to your `WORKSPACE`:
23
20
load(" @rules_python//gazelle:deps.bzl" , _py_gazelle_deps = " gazelle_deps" )
24
21
25
22
_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
- )
38
23
```
39
24
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.
42
29
This is checked into the repo for speed, as it takes some time to calculate
43
30
in a large monorepo.
44
31
@@ -48,7 +35,16 @@ file. (You can just use `touch` at this point, it just needs to exist.)
48
35
Then put this in your ` BUILD.bazel ` file next to the ` requirements.txt ` :
49
36
50
37
``` starlark
38
+ load(" @pip//:requirements.bzl" , " all_whl_requirements" )
51
39
load(" @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
+ )
52
48
53
49
# Gazelle python extension needs a manifest file mapping from
54
50
# an import to the installed package that provides it.
@@ -59,9 +55,7 @@ load("@rules_python//gazelle/manifest:defs.bzl", "gazelle_python_manifest")
59
55
# the manifest doesn't need to be updated
60
56
gazelle_python_manifest(
61
57
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" ,
65
59
# This is what we called our `pip_install` rule, where third-party
66
60
# python libraries are loaded in BUILD files.
67
61
pip_deps_repository_name = " pip" ,
0 commit comments