Skip to content

Commit 556857a

Browse files
committed
Add manifest with type example
1 parent c0fd9ec commit 556857a

File tree

9 files changed

+117
-4
lines changed

9 files changed

+117
-4
lines changed

examples/bzlmod_build_file_generation/BUILD.bazel

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ modules_mapping(
3535
wheels = all_whl_requirements,
3636
)
3737

38+
modules_mapping(
39+
name = "modules_map_with_types",
40+
exclude_patterns = [
41+
"^_|(\\._)+", # This is the default.
42+
"(\\.tests)+", # Add a custom one to get rid of the psutil tests.
43+
"^colorama", # Get rid of colorama on Windows.
44+
"^lazy_object_proxy\\.cext$", # Get rid of this on Linux because it isn't included on Windows.
45+
],
46+
include_stub_packages = True,
47+
modules_mapping_name = "modules_mapping_with_types.json",
48+
wheels = all_whl_requirements,
49+
)
50+
3851
# Gazelle python extension needs a manifest file mapping from
3952
# an import to the installed package that provides it.
4053
# This macro produces two targets:
@@ -52,6 +65,14 @@ gazelle_python_manifest(
5265
tags = ["exclusive"],
5366
)
5467

68+
gazelle_python_manifest(
69+
name = "gazelle_python_manifest_with_types",
70+
manifest = "gazelle_python_with_types.yaml",
71+
modules_mapping = ":modules_map_with_types",
72+
pip_repository_name = "pip",
73+
tags = ["exclusive"],
74+
)
75+
5576
# Our gazelle target points to the python gazelle binary.
5677
# This is the simple case where we only need one language supported.
5778
# If you also had proto, go, or other gazelle-supported languages,

examples/bzlmod_build_file_generation/MODULE.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ pip.parse(
7272
# on your system.
7373
python_version = "3.9",
7474
requirements_lock = "//:requirements_lock.txt",
75-
requirements_windows = "//:requirements_windows.txt",
7675
)
7776

7877
# Imports the pip toolchain generated by the given module extension into the scope of the current module.

examples/bzlmod_build_file_generation/gazelle_python.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,28 @@
66
manifest:
77
modules_mapping:
88
S3: s3cmd
9+
asgiref: asgiref
910
astroid: astroid
1011
certifi: certifi
1112
chardet: chardet
1213
dateutil: python_dateutil
1314
dill: dill
15+
django: Django
16+
django_stubs_ext: django_stubs_ext
1417
idna: idna
1518
isort: isort
1619
lazy_object_proxy: lazy_object_proxy
1720
magic: python_magic
1821
mccabe: mccabe
22+
mypy_django_plugin: django_stubs
1923
pathspec: pathspec
2024
pkg_resources: setuptools
2125
platformdirs: platformdirs
2226
pylint: pylint
2327
requests: requests
2428
setuptools: setuptools
2529
six: six
30+
sqlparse: sqlparse
2631
tabulate: tabulate
2732
tomli: tomli
2833
tomlkit: tomlkit
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# GENERATED FILE - DO NOT EDIT!
2+
#
3+
# To update this file, run:
4+
# bazel run //:gazelle_python_manifest_with_types.update
5+
6+
manifest:
7+
modules_mapping:
8+
S3: s3cmd
9+
asgiref: asgiref
10+
astroid: astroid
11+
certifi: certifi
12+
chardet: chardet
13+
dateutil: python_dateutil
14+
dill: dill
15+
django: Django
16+
django_stubs: django_stubs
17+
django_stubs_ext: django_stubs_ext
18+
idna: idna
19+
isort: isort
20+
lazy_object_proxy: lazy_object_proxy
21+
magic: python_magic
22+
mccabe: mccabe
23+
pathspec: pathspec
24+
pkg_resources: setuptools
25+
platformdirs: platformdirs
26+
pylint: pylint
27+
requests: requests
28+
setuptools: setuptools
29+
six: six
30+
sqlparse: sqlparse
31+
tabulate: tabulate
32+
tomli: tomli
33+
tomlkit: tomlkit
34+
types_pyyaml: types_pyyaml
35+
types_tabulate: types_tabulate
36+
typing_extensions: typing_extensions
37+
urllib3: urllib3
38+
wrapt: wrapt
39+
yaml: PyYAML
40+
yamllint: yamllint
41+
pip_repository:
42+
name: pip

examples/bzlmod_build_file_generation/requirements.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ requests~=2.25.1
22
s3cmd~=2.1.0
33
yamllint>=1.28.0
44
tabulate~=0.9.0
5+
types-tabulate
56
pylint~=2.15.5
67
python-dateutil>=2.8.2
8+
django
9+
django-stubs

examples/bzlmod_build_file_generation/requirements_lock.txt

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
#
55
# bazel run //:requirements.update
66
#
7+
asgiref==3.8.1 \
8+
--hash=sha256:3e1e3ecc849832fe52ccf2cb6686b7a55f82bb1d6aee72a58826471390335e47 \
9+
--hash=sha256:c343bd80a0bec947a9860adb4c432ffa7db769836c64238fc34bdc3fec84d590
10+
# via
11+
# django
12+
# django-stubs
713
astroid==2.12.13 \
814
--hash=sha256:10e0ad5f7b79c435179d0d0f0df69998c4eef4597534aae44910db060baeb907 \
915
--hash=sha256:1493fe8bd3dfd73dc35bd53c9d5b6e49ead98497c47b2307662556a5692d29d7
@@ -20,6 +26,21 @@ dill==0.3.6 \
2026
--hash=sha256:a07ffd2351b8c678dfc4a856a3005f8067aea51d6ba6c700796a4d9e280f39f0 \
2127
--hash=sha256:e5db55f3687856d8fbdab002ed78544e1c4559a130302693d839dfe8f93f2373
2228
# via pylint
29+
django==4.2.16 \
30+
--hash=sha256:1ddc333a16fc139fd253035a1606bb24261951bbc3a6ca256717fa06cc41a898 \
31+
--hash=sha256:6f1616c2786c408ce86ab7e10f792b8f15742f7b7b7460243929cb371e7f1dad
32+
# via
33+
# -r requirements.in
34+
# django-stubs
35+
# django-stubs-ext
36+
django-stubs==5.0.0 \
37+
--hash=sha256:084484cbe16a6d388e80ec687e46f529d67a232f3befaf55c936b3b476be289d \
38+
--hash=sha256:b8a792bee526d6cab31e197cb414ee7fa218abd931a50948c66a80b3a2548621
39+
# via -r requirements.in
40+
django-stubs-ext==5.1.1 \
41+
--hash=sha256:3907f99e178c93323e2ce908aef8352adb8c047605161f8d9e5e7b4efb5a6a9c \
42+
--hash=sha256:db7364e4f50ae7e5360993dbd58a3a57ea4b2e7e5bab0fbd525ccdb3e7975d1c
43+
# via django-stubs
2344
idna==2.10 \
2445
--hash=sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6 \
2546
--hash=sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0
@@ -129,23 +150,40 @@ six==1.16.0 \
129150
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
130151
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
131152
# via python-dateutil
153+
sqlparse==0.5.2 \
154+
--hash=sha256:9e37b35e16d1cc652a2545f0997c1deb23ea28fa1f3eefe609eee3063c3b105f \
155+
--hash=sha256:e99bc85c78160918c3e1d9230834ab8d80fc06c59d03f8db2618f65f65dda55e
156+
# via django
132157
tabulate==0.9.0 \
133158
--hash=sha256:0095b12bf5966de529c0feb1fa08671671b3368eec77d7ef7ab114be2c068b3c \
134159
--hash=sha256:024ca478df22e9340661486f85298cff5f6dcdba14f3813e8830015b9ed1948f
135160
# via -r requirements.in
136161
tomli==2.0.1 \
137162
--hash=sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc \
138163
--hash=sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f
139-
# via pylint
164+
# via
165+
# django-stubs
166+
# pylint
140167
tomlkit==0.11.6 \
141168
--hash=sha256:07de26b0d8cfc18f871aec595fda24d95b08fef89d147caa861939f37230bf4b \
142169
--hash=sha256:71b952e5721688937fb02cf9d354dbcf0785066149d2855e44531ebdd2b65d73
143170
# via pylint
171+
types-pyyaml==6.0.12.20240917 \
172+
--hash=sha256:392b267f1c0fe6022952462bf5d6523f31e37f6cea49b14cee7ad634b6301570 \
173+
--hash=sha256:d1405a86f9576682234ef83bcb4e6fff7c9305c8b1fbad5e0bcd4f7dbdc9c587
174+
# via django-stubs
175+
types-tabulate==0.9.0.20240106 \
176+
--hash=sha256:0378b7b6fe0ccb4986299496d027a6d4c218298ecad67199bbd0e2d7e9d335a1 \
177+
--hash=sha256:c9b6db10dd7fcf55bd1712dd3537f86ddce72a08fd62bb1af4338c7096ce947e
178+
# via -r requirements.in
144179
typing-extensions==4.4.0 \
145180
--hash=sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa \
146181
--hash=sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e
147182
# via
183+
# asgiref
148184
# astroid
185+
# django-stubs
186+
# django-stubs-ext
149187
# pylint
150188
urllib3==1.26.13 \
151189
--hash=sha256:47cc05d99aaa09c9e72ed5809b60e7ba354e64b59c9c173ac3018642d8bb41fc \

gazelle/WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories")
3838

3939
py_repositories()
4040

41+
load("//:internal_dev_deps.bzl", "internal_dev_deps")
42+
43+
internal_dev_deps()
44+
4145
load("//:deps.bzl", _py_gazelle_deps = "gazelle_deps")
4246

4347
# gazelle:repository_macro deps.bzl%go_deps

gazelle/modules_mapping/def.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def _modules_mapping_impl(ctx):
3131
transitive = [dep[DefaultInfo].files for dep in ctx.attr.wheels] + [dep[DefaultInfo].data_runfiles.files for dep in ctx.attr.wheels],
3232
)
3333
args.add("--output_file", modules_mapping.path)
34-
args.add("--include_stub_packages", ctx.attr.include_stub_packages)
34+
if ctx.attr.include_stub_packages:
35+
args.add("--include_stub_packages")
3536
args.add_all("--exclude_patterns", ctx.attr.exclude_patterns)
3637
args.add_all("--wheels", [whl.path for whl in all_wheels.to_list()])
3738
ctx.actions.run(

gazelle/modules_mapping/generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def data_has_purelib_or_platlib(path):
154154
description="Generates the modules mapping used by the Gazelle manifest.",
155155
)
156156
parser.add_argument("--output_file", type=str)
157-
parser.add_argument("--include_stub_packages", type=bool)
157+
parser.add_argument("--include_stub_packages", action="store_true")
158158
parser.add_argument("--exclude_patterns", nargs="+", default=[])
159159
parser.add_argument("--wheels", nargs="+", default=[])
160160
args = parser.parse_args()

0 commit comments

Comments
 (0)