Skip to content

Commit 2db3447

Browse files
committed
Merge branch 'main' of https://github.com/bazel-contrib/rules_python into feat.default.bootstrap.script
2 parents 3b5830b + 183d297 commit 2db3447

File tree

5 files changed

+67
-30
lines changed

5 files changed

+67
-30
lines changed

.github/workflows/mypy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ defaults:
1515

1616
jobs:
1717
ci:
18-
runs-on: ubuntu-20.04
18+
runs-on: ubuntu-latest
1919
steps:
2020
# Checkout the code
2121
- uses: actions/checkout@v4

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ Unreleased changes template.
7676
* (pypi) The PyPI extension will no longer write the lock file entries as the
7777
extension has been marked reproducible.
7878
Fixes [#2434](https://github.com/bazel-contrib/rules_python/issues/2434).
79+
* (gazelle) Lazily load and parse manifest files when running Gazelle. This ensures no
80+
manifest files are loaded when Gazelle is run over a set of non-python directories
81+
[PR #2746](https://github.com/bazel-contrib/rules_python/pull/2746).
7982
* (rules) {attr}`py_binary.srcs` and {attr}`py_test.srcs` is no longer mandatory when
8083
`main_module` is specified (for `--bootstrap_impl=script`)
8184

docs/support.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,35 @@ minor/patch versions.
3131
See [Bazel's release support matrix](https://bazel.build/release#support-matrix)
3232
for what versions are the rolling, active, and prior releases.
3333

34+
## Supported Python versions
35+
36+
As a general rule we test all released non-EOL Python versions. Different
37+
interpreter versions may work but are not guaranteed. We are interested in
38+
staying compatible with upcoming unreleased versions, so if you see that things
39+
stop working, please create tickets or, more preferably, pull requests.
40+
3441
## Supported Platforms
3542

3643
We only support the platforms that our continuous integration jobs run, which
37-
is Linux, Mac, and Windows. Code to support other platforms is allowed, but
38-
can only be on a best-effort basis.
44+
is Linux, Mac, and Windows.
45+
46+
In order to better describe different support levels, the below acts as a rough
47+
guideline for different platform tiers:
48+
* Tier 0 - The platforms that our CI runs: `linux_x86_64`, `osx_x86_64`, `RBE linux_x86_64`.
49+
* Tier 1 - The platforms that are similar enough to what the CI runs: `linux_aarch64`, `osx_arm64`.
50+
What is more, `windows_x86_64` is in this list as we run tests in CI but
51+
developing for Windows is more challenging and features may come later to
52+
this platform.
53+
* Tier 2 - The rest of the platforms that may have varying level of support, e.g.
54+
`linux_s390x`, `linux_ppc64le`, `windows_arm64`.
55+
56+
:::{note}
57+
Code to support Tier 2 platforms is allowed, but regressions will be fixed on a
58+
best-effort basis, so feel free to contribute by creating PRs.
59+
60+
If you would like to provide/sponsor CI setup for a platform that is not Tier 0,
61+
please create a ticket or contact the maintainers on Slack.
62+
:::
3963

4064
## Compatibility Policy
4165

gazelle/python/configure.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"flag"
1919
"fmt"
2020
"log"
21-
"os"
2221
"path/filepath"
2322
"strconv"
2423
"strings"
@@ -27,7 +26,6 @@ import (
2726
"github.com/bazelbuild/bazel-gazelle/rule"
2827
"github.com/bmatcuk/doublestar/v4"
2928

30-
"github.com/bazel-contrib/rules_python/gazelle/manifest"
3129
"github.com/bazel-contrib/rules_python/gazelle/pythonconfig"
3230
)
3331

@@ -228,25 +226,5 @@ func (py *Configurer) Configure(c *config.Config, rel string, f *rule.File) {
228226
}
229227

230228
gazelleManifestPath := filepath.Join(c.RepoRoot, rel, gazelleManifestFilename)
231-
gazelleManifest, err := py.loadGazelleManifest(gazelleManifestPath)
232-
if err != nil {
233-
log.Fatal(err)
234-
}
235-
if gazelleManifest != nil {
236-
config.SetGazelleManifest(gazelleManifest)
237-
}
238-
}
239-
240-
func (py *Configurer) loadGazelleManifest(gazelleManifestPath string) (*manifest.Manifest, error) {
241-
if _, err := os.Stat(gazelleManifestPath); err != nil {
242-
if os.IsNotExist(err) {
243-
return nil, nil
244-
}
245-
return nil, fmt.Errorf("failed to load Gazelle manifest at %q: %w", gazelleManifestPath, err)
246-
}
247-
manifestFile := new(manifest.File)
248-
if err := manifestFile.Decode(gazelleManifestPath); err != nil {
249-
return nil, fmt.Errorf("failed to load Gazelle manifest at %q: %w", gazelleManifestPath, err)
250-
}
251-
return manifestFile.Manifest, nil
229+
config.SetGazelleManifestPath(gazelleManifestPath)
252230
}

gazelle/pythonconfig/pythonconfig.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ package pythonconfig
1616

1717
import (
1818
"fmt"
19+
"log"
20+
"os"
1921
"path"
2022
"regexp"
2123
"strings"
@@ -153,10 +155,11 @@ func (c Configs) ParentForPackage(pkg string) *Config {
153155
type Config struct {
154156
parent *Config
155157

156-
extensionEnabled bool
157-
repoRoot string
158-
pythonProjectRoot string
159-
gazelleManifest *manifest.Manifest
158+
extensionEnabled bool
159+
repoRoot string
160+
pythonProjectRoot string
161+
gazelleManifestPath string
162+
gazelleManifest *manifest.Manifest
160163

161164
excludedPatterns *singlylinkedlist.List
162165
ignoreFiles map[string]struct{}
@@ -281,11 +284,26 @@ func (c *Config) SetGazelleManifest(gazelleManifest *manifest.Manifest) {
281284
c.gazelleManifest = gazelleManifest
282285
}
283286

287+
// SetGazelleManifestPath sets the path to the gazelle_python.yaml file
288+
// for the current configuration.
289+
func (c *Config) SetGazelleManifestPath(gazelleManifestPath string) {
290+
c.gazelleManifestPath = gazelleManifestPath
291+
}
292+
284293
// FindThirdPartyDependency scans the gazelle manifests for the current config
285294
// and the parent configs up to the root finding if it can resolve the module
286295
// name.
287296
func (c *Config) FindThirdPartyDependency(modName string) (string, string, bool) {
288297
for currentCfg := c; currentCfg != nil; currentCfg = currentCfg.parent {
298+
// Attempt to load the manifest if needed.
299+
if currentCfg.gazelleManifestPath != "" && currentCfg.gazelleManifest == nil {
300+
currentCfgManifest, err := loadGazelleManifest(currentCfg.gazelleManifestPath)
301+
if err != nil {
302+
log.Fatal(err)
303+
}
304+
currentCfg.SetGazelleManifest(currentCfgManifest)
305+
}
306+
289307
if currentCfg.gazelleManifest != nil {
290308
gazelleManifest := currentCfg.gazelleManifest
291309
if distributionName, ok := gazelleManifest.ModulesMapping[modName]; ok {
@@ -526,3 +544,17 @@ func (c *Config) FormatThirdPartyDependency(repositoryName string, distributionN
526544

527545
return label.New(repositoryName, normConventionalDistributionName, normConventionalDistributionName)
528546
}
547+
548+
func loadGazelleManifest(gazelleManifestPath string) (*manifest.Manifest, error) {
549+
if _, err := os.Stat(gazelleManifestPath); err != nil {
550+
if os.IsNotExist(err) {
551+
return nil, nil
552+
}
553+
return nil, fmt.Errorf("failed to load Gazelle manifest at %q: %w", gazelleManifestPath, err)
554+
}
555+
manifestFile := new(manifest.File)
556+
if err := manifestFile.Decode(gazelleManifestPath); err != nil {
557+
return nil, fmt.Errorf("failed to load Gazelle manifest at %q: %w", gazelleManifestPath, err)
558+
}
559+
return manifestFile.Manifest, nil
560+
}

0 commit comments

Comments
 (0)