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

Parameterized load() statements? #87

Closed
thoughtpolice opened this issue Feb 4, 2023 · 2 comments
Closed

Parameterized load() statements? #87

thoughtpolice opened this issue Feb 4, 2023 · 2 comments

Comments

@thoughtpolice
Copy link
Contributor

I have:

load("@bxl//hello.bxl", _hello_main = "main", _hello_args = "args")
hello = bxl(impl = _hello_main, cli_args = _hello_args)

load("@bxl//licenses.bxl", _licenses_main = "main", _licenses_args = "args")
license_check = bxl(impl = _licenses_main, cli_args = _licenses_args)

# ad infinitum...

I want:

files = {
    "hello": "@bxl//hello.bxl",
    # ...
}

for (name, path) in files.items():
    load(path, _main = "main", _args = "args")
    load_symbols({ name: bxl(impl = _main, cli_args = _args) })

But this currently doesn't work. I suspect there are pretty good reasons for this. But would something like this ever be achievable?

Part of the issue I think is just that the API for 'load' is awkward here, because I think it's supposed to introduce the symbols into the module context, not the local scope. But I really just want locally bound names here. So having something like e = load_single_expr(path, name) would be nice. But again I assume there are reasons for this.

@ndmitchell
Copy link
Contributor

Why are you defining all your bxl rules in the same file? Would it be easier to have them in separate files? Is this your #86 approach? Could you change that alias so it was $1.bxl:$1?

We follow the Starlark standard from https://github.com/bazelbuild/starlark/blob/master/spec.md, so our usual way of extending would be to propose additions to the language. This does seem quite a departure from the existing approach though.

@thoughtpolice
Copy link
Contributor Author

I was mostly doing it to keep some code centralized in top.bxl, but I just simplified the example a bunch here. That said, I figured it would be a lot of rigamarole to get this working since it seems like this is a pretty fundamental change, so I figured I'd just open a ticket and ask. :)

So I think for now I'll just do some refactoring another way and close this. In the future a parameterized load() statement might be useful but another ticket is probably better for that, since this case can be handled another way. (I mean I can probably think of some good use cases if you gave me some time, but I don't have any other ones right now.)

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

2 participants