Skip to content

Commit c0fd9ec

Browse files
committed
Remove binary wheels and add internal_dev_deps
1 parent 631ab19 commit c0fd9ec

9 files changed

+96
-26
lines changed

gazelle/MODULE.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,14 @@ use_repo(
3333
python_stdlib_list,
3434
"python_stdlib_list",
3535
)
36+
37+
internal_dev_deps = use_extension(
38+
"//:internal_dev_deps.bzl",
39+
"internal_dev_deps_extension",
40+
dev_dependency = True,
41+
)
42+
use_repo(
43+
internal_dev_deps,
44+
"django-types",
45+
"pytest",
46+
)

gazelle/internal_dev_deps.bzl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Module extension for internal dev_dependency=True setup."""
15+
16+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
17+
18+
def internal_dev_deps():
19+
"""This extension creates internal rules_python_gazelle dev dependencies."""
20+
http_file(
21+
name = "pytest",
22+
downloaded_file_path = "pytest-8.3.3-py3-none-any.whl",
23+
sha256 = "a6853c7375b2663155079443d2e45de913a911a11d669df02a50814944db57b2",
24+
urls = [
25+
"https://files.pythonhosted.org/packages/6b/77/7440a06a8ead44c7757a64362dd22df5760f9b12dc5f11b6188cd2fc27a0/pytest-8.3.3-py3-none-any.whl",
26+
],
27+
)
28+
http_file(
29+
name = "django-types",
30+
downloaded_file_path = "django_types-0.19.1-py3-none-any.whl",
31+
sha256 = "b3f529de17f6374d41ca67232aa01330c531bbbaa3ac4097896f31ac33c96c30",
32+
urls = [
33+
"https://files.pythonhosted.org/packages/25/cb/d088c67245a9d5759a08dbafb47e040ee436e06ee433a3cdc7f3233b3313/django_types-0.19.1-py3-none-any.whl",
34+
],
35+
)
36+
37+
def _internal_dev_deps_impl(mctx):
38+
_ = mctx # @unused
39+
40+
# This wheel is purely here to validate the wheel extraction code. It's not
41+
# intended for anything else.
42+
internal_dev_deps()
43+
44+
internal_dev_deps_extension = module_extension(
45+
implementation = _internal_dev_deps_impl,
46+
doc = "This extension creates internal rules_python_gazelle dev dependencies.",
47+
)

gazelle/modules_mapping/BUILD.bazel

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
12
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
23

34
# gazelle:exclude *.py
@@ -8,10 +9,25 @@ py_binary(
89
visibility = ["//visibility:public"],
910
)
1011

12+
copy_file(
13+
name = "pytest_wheel",
14+
src = "@pytest//file",
15+
out = "pytest-8.3.3-py3-none-any.whl",
16+
)
17+
18+
copy_file(
19+
name = "django_types_wheel",
20+
src = "@django-types//file",
21+
out = "django_types-0.19.1-py3-none-any.whl",
22+
)
23+
1124
py_test(
1225
name = "test_generator",
1326
srcs = ["test_generator.py"],
14-
data = glob(["testdata/**"]),
27+
data = [
28+
"django_types_wheel",
29+
"pytest_wheel",
30+
],
1531
imports = ["."],
1632
main = "test_generator.py",
1733
deps = [":generator"],

gazelle/modules_mapping/def.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ modules_mapping = rule(
5151
doc = "A set of regex patterns to match against each calculated module path. By default, exclude the modules starting with underscores.",
5252
mandatory = False,
5353
),
54-
"modules_mapping_name": attr.string(
55-
default = "modules_mapping.json",
56-
doc = "The name for the output JSON file.",
57-
mandatory = False,
58-
),
5954
"include_stub_packages": attr.bool(
6055
default = False,
6156
doc = "Whether to include stub packages in the mapping.",
6257
mandatory = False,
6358
),
59+
"modules_mapping_name": attr.string(
60+
default = "modules_mapping.json",
61+
doc = "The name for the output JSON file.",
62+
mandatory = False,
63+
),
6464
"wheels": attr.label_list(
6565
allow_files = True,
6666
doc = "The list of wheels, usually the 'all_whl_requirements' from @<pip_repository>//:requirements.bzl",

gazelle/modules_mapping/generator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ def __init__(self, stderr, output_file, excluded_patterns, include_stub_packages
3838
def dig_wheel(self, whl):
3939
# Skip stubs and types wheels.
4040
wheel_name = get_wheel_name(whl)
41-
if wheel_name.endswith(("_stubs", "_types")) and self.include_stub_packages:
41+
if self.include_stub_packages and (
42+
wheel_name.endswith(("_stubs", "_types"))
43+
or wheel_name.startswith(("types_", "stubs_"))
44+
):
4245
self.mapping[wheel_name.lower()] = wheel_name.lower()
4346
return
4447
with zipfile.ZipFile(whl, "r") as zip_file:

gazelle/modules_mapping/test_generator.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
class GeneratorTest(unittest.TestCase):
88
def test_generator(self):
9-
whl = pathlib.Path(
10-
pathlib.Path(__file__).parent, "testdata", "pytest-7.1.1-py3-none-any.whl"
11-
)
9+
whl = pathlib.Path(__file__).parent / "pytest-8.3.3-py3-none-any.whl"
1210
gen = Generator(None, None, {}, False)
1311
gen.dig_wheel(whl)
1412
self.assertLessEqual(
@@ -22,11 +20,7 @@ def test_generator(self):
2220
)
2321

2422
def test_stub_generator(self):
25-
whl = pathlib.Path(
26-
pathlib.Path(__file__).parent,
27-
"testdata",
28-
"django_types-0.15.0-py3-none-any.whl",
29-
)
23+
whl = pathlib.Path(__file__).parent / "django_types-0.19.1-py3-none-any.whl"
3024
gen = Generator(None, None, {}, True)
3125
gen.dig_wheel(whl)
3226
self.assertLessEqual(
@@ -37,11 +31,7 @@ def test_stub_generator(self):
3731
)
3832

3933
def test_stub_excluded(self):
40-
whl = pathlib.Path(
41-
pathlib.Path(__file__).parent
42-
/ "testdata"
43-
/ "django_types-0.15.0-py3-none-any.whl"
44-
)
34+
whl = pathlib.Path(__file__).parent / "django_types-0.19.1-py3-none-any.whl"
4535
gen = Generator(None, None, {}, False)
4636
gen.dig_wheel(whl)
4737
self.assertEqual(
Binary file not shown.
Binary file not shown.

gazelle/python/resolve.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,16 @@ func (py *Resolver) Resolve(
192192
if dep, distributionName, ok := cfg.FindThirdPartyDependency(moduleName); ok {
193193
deps.Add(dep)
194194
// Add the type and stub dependencies if they exist.
195-
typeModule := fmt.Sprintf("%s_types", strings.ToLower(distributionName))
196-
if dep, _, ok := cfg.FindThirdPartyDependency(typeModule); ok {
197-
deps.Add(dep)
195+
modules := []string{
196+
fmt.Sprintf("%s_stubs", strings.ToLower(distributionName)),
197+
fmt.Sprintf("%s_types", strings.ToLower(distributionName)),
198+
fmt.Sprintf("types_%s", strings.ToLower(distributionName)),
199+
fmt.Sprintf("stubs_%s", strings.ToLower(distributionName)),
198200
}
199-
stubModule := fmt.Sprintf("%s_stubs", strings.ToLower(distributionName))
200-
if dep, _, ok := cfg.FindThirdPartyDependency(stubModule); ok {
201-
deps.Add(dep)
201+
for _, module := range modules {
202+
if dep, _, ok := cfg.FindThirdPartyDependency(module); ok {
203+
deps.Add(dep)
204+
}
202205
}
203206
if explainDependency == dep {
204207
log.Printf("Explaining dependency (%s): "+

0 commit comments

Comments
 (0)