-
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
Setting environment variables on a per-recipe basis without $-parameters #2408
Comments
That seems reasonable. What's the use-case? And, why not 'This would be slightly awkward as-is, since it would create a variable which is exported, but not available in To make it fit in better with existing functionality, it might be best to instead add a way to add |
The use case I had in mind was being able to create individual recipes that have some environment variables in scope, without affecting the environment variables of other recipes (which is what But yeah finding a way to scope I guess this could also be done with attributes, maybe something like:
|
Can you make your recipe a shebang recipe? -
|
This is what I ended up doing, which does work, but it's a bit inelegant. |
Hi, I'm porting one of my Makefiles to Just and I have a use case that might be relevant. I'm building a python app with MAKEFILE_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
.PHONY: build
build: export PYAPP_DISTRIBUTION_EMBED = 1
build: export PYAPP_FULL_ISOLATION = 1
build: export PYAPP_PROJECT_PATH = $(MAKEFILE_DIR)/dist/foo-$(shell $(python) -m hatch version)-py3-none-any.whl
build:
python -m hatch build --clean --target wheel
python -m hatch build --clean --target binary
The equivalent Justfile would look something like this: [windows]
build:
#!powershell.exe
$env:PYAPP_DISTRIBUTION_EMBED = "1"
$env:PYAPP_FULL_ISOLATION = "1"
$env:PYAPP_PROJECT_PATH = "{{justfile_dir()}}/dist/foo-$(python -m hatch version)-py3-none-any.whl"
uv run python -m hatch build --clean --target wheel
uv run python -m hatch build --clean --target binary
[unix]
build:
#!/usr/bin/env sh
export PYAPP_DISTRIBUTION_EMBED='1'
export PYAPP_FULL_ISOLATION='1'
export PYAPP_PROJECT_PATH='{{justfile_dir()}}/dist/foo-$(python -m hatch version)-py3-none-any.whl'
python -m hatch build --clean --target wheel
python -m hatch build --clean --target binary And based on @neunenak examples, it would look like this: [export: "PYAPP_DISTRIBUTION_EMBED", "1"]
[export: "PYAPP_FULL_ISOLATION", "1"]
[export: "PYAPP_PROJECT_PATH", "{{justfile_dir()}}/dist/foo-{{shell('python -m hatch version')}}-py3-none-any.whl"]
build:
python -m hatch build --clean --target wheel
python -m hatch build --clean --target binary I hope this help. |
@laniakea64 Although a shebang recipe works, it is not very cross-platform. If the recipe must work in Windows and in Linux, then that would require duplication of the recipe with minor modifications and overrides, or special steps to prepare the developer environments. Having attributes to deal with environment variables will greatly simplify cross-platform recipes. |
Since this is really about having a per-recipe scope for expressions, then I think we should think about reusing the existing expression syntax. I.e., I have no good ideas for syntax though 😂 |
I'm almost tempted to close this in favor of #1023, since I think they're basically the same thing, a per-recipe scope for expressions. But there's good discussion here so whatever. |
#2409 (comment) mentioned the idea of scoping to recipe groups instead of individual recipes. If that would do the job, what about setting the
Edit: Oops, that technically wouldn't be backwards-compatible, since it is not an error in current |
That's an interesting option. I think it's a downside that you have to add a group to a recipe if you want scoped variables, and you have assignments which potentially share a scope, but aren't syntactically grouped. That being said, I think invalid attributes being accepted on assignments is an inadvertent bug which should be fixed, so this is potentially backwards compatible. |
Fixed in #2412. |
A wacky option would be to allow defining inline modules, place the recipe you want to have its own scope in the module, and then use normal assignments within that module: my-recipe: foo::my-recipe
# or maybe:
use foo::my-recipe
use foo::*
# hypothetical inline module syntax
foo::
export ANDROID_SDK_HOME := "~/Android"
my-recipe:
echo $ANDROID_SDK_HOME This allows multiple recipes to share a scope, and re-uses existing functionality. However, given the current limitations of modules, a workaround may be desirable. |
I kind of like this, since it allows a group of recipes to share a common set of variables, which I could see being useful. Actually, maybe I could solve my problem today by simply using modules (which I don't personally normally use in |
Another option could be to have an [env_file("./myvars.env")]
my-recipe:
echo $ANDROID_SDK_HOME |
I think I'm inclined to implement this with inline modules, since it's more general and powerful, although it might take awhile for someone to get around to it. See #2442 for some discussion. |
I find i also would need this functionality. The ticket is closed as completed, but #2442 is still open so that's not how it's been completed. May I ask what the resolution was ? For context, I have some build-time vars and some run-time vars. I use the export feature to pull the run-time ones from Vault when running locally. |
#2442 is big, so it may take a while. |
Thanks for the reply. No problem, I just wasn't sure where to go look for
updates. I'll watch #2442 <#2442> .
…On Mon, Nov 18, 2024 at 1:05 PM Casey Rodarmor ***@***.***> wrote:
#2442 <#2442> is big, so it may take
a while.
—
Reply to this email directly, view it on GitHub
<#2408 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHAAOJ22OAD4V4QJM2UNMCD2BI3BHAVCNFSM6AAAAABPI4AT7GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOBTHA4DCOJSG4>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I think it would be useful if there was a way to set environment variables on a per-recipe basis without using the
$VARIABLE
syntax in parameters. Maybe this could be an attribute:The text was updated successfully, but these errors were encountered: