-
Notifications
You must be signed in to change notification settings - Fork 503
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
Allow interpolation inside of backticks and strings #11
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Interesting how nobody has taken this on yet! I am quite interested in having this and have some basic experience working w/ lexers/parsers for other things, so maybe I'll try to take a look soon-ish and see if I can help make this happen! |
I started working on this, in-progress branch here. I marked this as "good first issue", but I think that's misleading, because it's super hard! I've gotten lexing and parsing mostly working, but I haven't done evaluation, i.e. actually evaluating the fragments, concatenating them, and, in the case of format backticks, evaluating the result. If your interested, you could pick up the branch as a starting point. I'm not sure when I'm going to work on it again. |
Is there any news on the subject? edit: without this I'm forced to go back to make 😅 |
This is a big feature, so time to implementation is unknown. |
Could this crate be any helpful ? MiniJinja -- Powerful but minimal dependency template engine for Rust Announcement on r/rust (2021-09-24).
Cheers |
Is a format expression an easier compromise? I can live without interpolation if there's a string.format(str, args*) method available.
|
i'm hoping for this addition. |
I'm working around this using replace:
It's acceptable if you're only using one value multiple times like I am; it would get gnarly with multiple values and replacements. |
This comment was marked as resolved.
This comment was marked as resolved.
It's very much not clear in the documentation that you can't do this, currently. |
This is the only thing stopping me being able to convert a whole Makefile over to Just :( I have managed to build up the command-line using For example: BLAH := some_example # this is the canonical source that we don't want to repeat through the whole file
VERSION := $(shell cargo metadata --format-version 1 | jq -r '.packages[] | select(.name=="my-prefix-${BLAH}") | .version') I can then convert it to: export BLAH := "some_example" # this is the canonical source that we don't want to repeat
version_cmd := "cargo metadata --format-version 1 | jq -r '.packages[] | select(.name==\"my-prefix-" + BLAH + "\") | .version'"
export VERSION = `...` # what can I do here to execute version_cmd |
I'm in the exact same situation as @NickLarsenNZ. Currently on the verge of convincing my organization to migrate over to Justfiles from Makefiles, but this is the final missing piece. I am tracking this issue closely in the hope it is implemented some time soon, otherwise the opportunity to switch will pass and we will be stuck with Make for the foreseeable future, or worst yet a custom an in-house solution. @casey Apologies to ping you directly, but if you could provide a steer on your appetite to implement this and maybe a ballpark ETA, I can make a more informed decision for my team. edit: For what it's worth, my preference is Python's |
What kinds of workarounds are people using for the lack of way to use variables in backticks? Recently ran into a case where variable in backticks would be useful: writing a justfile to build a soft-fork project that's distributed as a set of source code patches. As there maybe multiple upstream source tarball versions available locally, selecting the right one requires a (user-overridable) command. The output of that command (the selected tarball) needs to be stored in a variable for use by recipes. It's also needed in another variable backtick: since the recipes also have to know where the tarball will extract to, a second command is used to get the name of the subdirectory in the tarball. That second command requires the output of the first to know which tarball to work with. The best I could come up with is making an external Python script to find the correct tarball, with an environment variable override option, and calling it in both backticks. But this is not a great solution: the code is run twice for the same result, and using an environment variable for the override risks build environment pollution. With backtick interpolation, this would be straightforward, only a few lines in the justfile (probably without any external script), and the override could be done with |
If this is what makes this hard, maybe nesting f-strings could be explicitly disallowed, at least initially? Most if not all uses for nesting could be achieved with intermediate variables. Adding nesting support later if needed wouldn't affect backwards compatibility. |
An alternative take is to just make a breaking change allowing interpolation in backticks, and call it v2. Then give instructions to v1 users on how to deal with literals which now have different behavior. |
|
Or, there can be a default (overridable) max level of recursion, above which will cause a runtime error. |
What does @casey think about a |
I think the first easiest step is to parse |
In that case: no escaping, right? |
@casey, |
The old branch is probably pretty out of date, so I'm not sure it will be much help. |
Alright, anyhoo. I'll look into how #2055 works, and figure it out from there. |
Yeah. I'd love that addition too. Python strings f"{{}}" would have my preference. |
PR started but author dropped out for personal reasons in 2021. Took me a while looking for this so linking for visibility |
Thanks. I think I can work with this. A lot has gone into it too. |
*** updated *** ** Isn't this (or at least, a significant subset of the use cases it is meant to address) already solved via e.g. continuing the example from above
becomes
|
To avoid making this a backwards incompatible change, only strings and backticks preceeded by an
f
will allow interpolation:Both
foo
andbaz
evaluate toHello, world!
.To keep this simple, we should only support single identifiers in interpolations, i.e., no arbitrary expressions like
foo + bar
.The text was updated successfully, but these errors were encountered: