Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding non-strings (eg: a function) to a target's deps #1747

Open
dougthor42 opened this issue Mar 4, 2024 · 0 comments
Open

Adding non-strings (eg: a function) to a target's deps #1747

dougthor42 opened this issue Mar 4, 2024 · 0 comments

Comments

@dougthor42
Copy link

What version of gazelle are you using?

0.33.0
rules_python_gazelle_plugin @ commit da10ac4 (main)

What version of rules_go are you using?

0.41.0

What version of Bazel are you using?

7.0.0

$ bazel version
Bazelisk version: v1.19.0
Build label: 7.0.0
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Mon Dec 11 16:51:49 2023 (1702313509)
Build timestamp: 1702313509
Build timestamp as int: 1702313509

Does this issue reproduce with the latest releases of all the above?

It looks like it, but I'm not 100% sure I'm testing things correctly.

What operating system and processor architecture are you using?

Ubuntu on WSL1 on Windows10, x86_64

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy
$ uname -p
x86_64

What did you do?

I'm working on bazelbuild/rules_python#1789 and am trying to get the deps to use a function rather than a string. From what I can tell, there's no way to pass a non-string as one of the values sent to rule.SetAttr.

It sounds like this might be a feature request, though it's possible I'm just not familiar enough with build-gazelle yet (I've only started updating rules_python about a week or two ago, haha).

I think the solution I'd like to see is to be able to do something like:

// Caveat Emptor: I'm still quite new to Go. Almost all my experience is with python, so
// some python idioms might sneak in.
type DepLabelOrFunc struct {
    label   string
    isFunc  bool
}

func (t *targetBuilder) build() *rule.Rule {
    r := rule.NewRule(t.kind, t.name)
    ...
    deps := []DepLabelOrFunc{
        DepLabelOrFunc{"//foo:bar", false},
        DepLabelOrFunc{`requirement("boto3")`, true},
    }

    r.SetAttr("deps", deps)  // some magic somewhere looks at isFunc and removes the
                             // surrounding quotes when actually writing the BUILD file.
    // or r.SetPrivateAttr(config.GazelleImportsKey, deps)
    return r
}

Does something like that already exist? If not, then this is a feature request 🙃.

What did you expect to see?

py_library(
    ...,
    deps = [
        "//foo:bar",
        requirement("boto3"),
    ],
)

What did you see instead?

py_library(
    ...,
    deps = [
        "//foo:bar",
        "requirement(\"boto3\")",
    ],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant