Skip to content

Commit

Permalink
Add manifest with type example
Browse files Browse the repository at this point in the history
  • Loading branch information
ewianda committed Nov 25, 2024
1 parent c0fd9ec commit 556857a
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 4 deletions.
21 changes: 21 additions & 0 deletions examples/bzlmod_build_file_generation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ modules_mapping(
wheels = all_whl_requirements,
)

modules_mapping(
name = "modules_map_with_types",
exclude_patterns = [
"^_|(\\._)+", # This is the default.
"(\\.tests)+", # Add a custom one to get rid of the psutil tests.
"^colorama", # Get rid of colorama on Windows.
"^lazy_object_proxy\\.cext$", # Get rid of this on Linux because it isn't included on Windows.
],
include_stub_packages = True,
modules_mapping_name = "modules_mapping_with_types.json",
wheels = all_whl_requirements,
)

# Gazelle python extension needs a manifest file mapping from
# an import to the installed package that provides it.
# This macro produces two targets:
Expand All @@ -52,6 +65,14 @@ gazelle_python_manifest(
tags = ["exclusive"],
)

gazelle_python_manifest(
name = "gazelle_python_manifest_with_types",
manifest = "gazelle_python_with_types.yaml",
modules_mapping = ":modules_map_with_types",
pip_repository_name = "pip",
tags = ["exclusive"],
)

# Our gazelle target points to the python gazelle binary.
# This is the simple case where we only need one language supported.
# If you also had proto, go, or other gazelle-supported languages,
Expand Down
1 change: 0 additions & 1 deletion examples/bzlmod_build_file_generation/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ pip.parse(
# on your system.
python_version = "3.9",
requirements_lock = "//:requirements_lock.txt",
requirements_windows = "//:requirements_windows.txt",
)

# Imports the pip toolchain generated by the given module extension into the scope of the current module.
Expand Down
5 changes: 5 additions & 0 deletions examples/bzlmod_build_file_generation/gazelle_python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@
manifest:
modules_mapping:
S3: s3cmd
asgiref: asgiref
astroid: astroid
certifi: certifi
chardet: chardet
dateutil: python_dateutil
dill: dill
django: Django
django_stubs_ext: django_stubs_ext
idna: idna
isort: isort
lazy_object_proxy: lazy_object_proxy
magic: python_magic
mccabe: mccabe
mypy_django_plugin: django_stubs
pathspec: pathspec
pkg_resources: setuptools
platformdirs: platformdirs
pylint: pylint
requests: requests
setuptools: setuptools
six: six
sqlparse: sqlparse
tabulate: tabulate
tomli: tomli
tomlkit: tomlkit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# GENERATED FILE - DO NOT EDIT!
#
# To update this file, run:
# bazel run //:gazelle_python_manifest_with_types.update

manifest:
modules_mapping:
S3: s3cmd
asgiref: asgiref
astroid: astroid
certifi: certifi
chardet: chardet
dateutil: python_dateutil
dill: dill
django: Django
django_stubs: django_stubs
django_stubs_ext: django_stubs_ext
idna: idna
isort: isort
lazy_object_proxy: lazy_object_proxy
magic: python_magic
mccabe: mccabe
pathspec: pathspec
pkg_resources: setuptools
platformdirs: platformdirs
pylint: pylint
requests: requests
setuptools: setuptools
six: six
sqlparse: sqlparse
tabulate: tabulate
tomli: tomli
tomlkit: tomlkit
types_pyyaml: types_pyyaml
types_tabulate: types_tabulate
typing_extensions: typing_extensions
urllib3: urllib3
wrapt: wrapt
yaml: PyYAML
yamllint: yamllint
pip_repository:
name: pip
3 changes: 3 additions & 0 deletions examples/bzlmod_build_file_generation/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ requests~=2.25.1
s3cmd~=2.1.0
yamllint>=1.28.0
tabulate~=0.9.0
types-tabulate
pylint~=2.15.5
python-dateutil>=2.8.2
django
django-stubs
40 changes: 39 additions & 1 deletion examples/bzlmod_build_file_generation/requirements_lock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
#
# bazel run //:requirements.update
#
asgiref==3.8.1 \
--hash=sha256:3e1e3ecc849832fe52ccf2cb6686b7a55f82bb1d6aee72a58826471390335e47 \
--hash=sha256:c343bd80a0bec947a9860adb4c432ffa7db769836c64238fc34bdc3fec84d590
# via
# django
# django-stubs
astroid==2.12.13 \
--hash=sha256:10e0ad5f7b79c435179d0d0f0df69998c4eef4597534aae44910db060baeb907 \
--hash=sha256:1493fe8bd3dfd73dc35bd53c9d5b6e49ead98497c47b2307662556a5692d29d7
Expand All @@ -20,6 +26,21 @@ dill==0.3.6 \
--hash=sha256:a07ffd2351b8c678dfc4a856a3005f8067aea51d6ba6c700796a4d9e280f39f0 \
--hash=sha256:e5db55f3687856d8fbdab002ed78544e1c4559a130302693d839dfe8f93f2373
# via pylint
django==4.2.16 \
--hash=sha256:1ddc333a16fc139fd253035a1606bb24261951bbc3a6ca256717fa06cc41a898 \
--hash=sha256:6f1616c2786c408ce86ab7e10f792b8f15742f7b7b7460243929cb371e7f1dad
# via
# -r requirements.in
# django-stubs
# django-stubs-ext
django-stubs==5.0.0 \
--hash=sha256:084484cbe16a6d388e80ec687e46f529d67a232f3befaf55c936b3b476be289d \
--hash=sha256:b8a792bee526d6cab31e197cb414ee7fa218abd931a50948c66a80b3a2548621
# via -r requirements.in
django-stubs-ext==5.1.1 \
--hash=sha256:3907f99e178c93323e2ce908aef8352adb8c047605161f8d9e5e7b4efb5a6a9c \
--hash=sha256:db7364e4f50ae7e5360993dbd58a3a57ea4b2e7e5bab0fbd525ccdb3e7975d1c
# via django-stubs
idna==2.10 \
--hash=sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6 \
--hash=sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0
Expand Down Expand Up @@ -129,23 +150,40 @@ six==1.16.0 \
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
# via python-dateutil
sqlparse==0.5.2 \
--hash=sha256:9e37b35e16d1cc652a2545f0997c1deb23ea28fa1f3eefe609eee3063c3b105f \
--hash=sha256:e99bc85c78160918c3e1d9230834ab8d80fc06c59d03f8db2618f65f65dda55e
# via django
tabulate==0.9.0 \
--hash=sha256:0095b12bf5966de529c0feb1fa08671671b3368eec77d7ef7ab114be2c068b3c \
--hash=sha256:024ca478df22e9340661486f85298cff5f6dcdba14f3813e8830015b9ed1948f
# via -r requirements.in
tomli==2.0.1 \
--hash=sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc \
--hash=sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f
# via pylint
# via
# django-stubs
# pylint
tomlkit==0.11.6 \
--hash=sha256:07de26b0d8cfc18f871aec595fda24d95b08fef89d147caa861939f37230bf4b \
--hash=sha256:71b952e5721688937fb02cf9d354dbcf0785066149d2855e44531ebdd2b65d73
# via pylint
types-pyyaml==6.0.12.20240917 \
--hash=sha256:392b267f1c0fe6022952462bf5d6523f31e37f6cea49b14cee7ad634b6301570 \
--hash=sha256:d1405a86f9576682234ef83bcb4e6fff7c9305c8b1fbad5e0bcd4f7dbdc9c587
# via django-stubs
types-tabulate==0.9.0.20240106 \
--hash=sha256:0378b7b6fe0ccb4986299496d027a6d4c218298ecad67199bbd0e2d7e9d335a1 \
--hash=sha256:c9b6db10dd7fcf55bd1712dd3537f86ddce72a08fd62bb1af4338c7096ce947e
# via -r requirements.in
typing-extensions==4.4.0 \
--hash=sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa \
--hash=sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e
# via
# asgiref
# astroid
# django-stubs
# django-stubs-ext
# pylint
urllib3==1.26.13 \
--hash=sha256:47cc05d99aaa09c9e72ed5809b60e7ba354e64b59c9c173ac3018642d8bb41fc \
Expand Down
4 changes: 4 additions & 0 deletions gazelle/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

load("//:internal_dev_deps.bzl", "internal_dev_deps")

internal_dev_deps()

load("//:deps.bzl", _py_gazelle_deps = "gazelle_deps")

# gazelle:repository_macro deps.bzl%go_deps
Expand Down
3 changes: 2 additions & 1 deletion gazelle/modules_mapping/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def _modules_mapping_impl(ctx):
transitive = [dep[DefaultInfo].files for dep in ctx.attr.wheels] + [dep[DefaultInfo].data_runfiles.files for dep in ctx.attr.wheels],
)
args.add("--output_file", modules_mapping.path)
args.add("--include_stub_packages", ctx.attr.include_stub_packages)
if ctx.attr.include_stub_packages:
args.add("--include_stub_packages")
args.add_all("--exclude_patterns", ctx.attr.exclude_patterns)
args.add_all("--wheels", [whl.path for whl in all_wheels.to_list()])
ctx.actions.run(
Expand Down
2 changes: 1 addition & 1 deletion gazelle/modules_mapping/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def data_has_purelib_or_platlib(path):
description="Generates the modules mapping used by the Gazelle manifest.",
)
parser.add_argument("--output_file", type=str)
parser.add_argument("--include_stub_packages", type=bool)
parser.add_argument("--include_stub_packages", action="store_true")
parser.add_argument("--exclude_patterns", nargs="+", default=[])
parser.add_argument("--wheels", nargs="+", default=[])
args = parser.parse_args()
Expand Down

0 comments on commit 556857a

Please sign in to comment.