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

Support setting the --environment flag via env var #889

Closed
mariusvniekerk opened this issue Feb 29, 2024 · 7 comments
Closed

Support setting the --environment flag via env var #889

mariusvniekerk opened this issue Feb 29, 2024 · 7 comments
Labels
✨ enhancement Feature request

Comments

@mariusvniekerk
Copy link
Contributor

Problem description

When running a pixi task in an config that has >1 environment and the task is defined in default env pixi will ask you to specify the environment

$ pixi run test_sdk
  × the task 'install_sdk' is ambiguous
  help: These environments provide the task 'install_sdk': default, engine
        
        Specify the '--environment' flag to run the task in a specific environment, e.g:.
        
                pixi run --environment default install_sdk

It would be a nice ux improvement to allow setting the environment flag by means of the PIXI_ENVIRONMENT_NAME env var

$ PIXI_ENVIRONMENT_NAME=default pixi run test_sdk

That will allow a bunch of associated tasks to be more easily coordinated from a higher order place (or using the env var as a matrix in things like github actions)

@mariusvniekerk mariusvniekerk added the ✨ enhancement Feature request label Feb 29, 2024
@ruben-arts
Copy link
Contributor

I'm trying to understand the use-case, as I think it would be more transparent in GitHub actions if you do:

pixi run -e $PIXI_ENVIRONMENT_NAME install_sdk

The problem I see is that people unexpectedly start running with different environments than they expect, thus we would need to add more logging or other logic to make sure that doesn't happen.

@baszalmstra
Copy link
Contributor

Note that once #900 is merged this will work out of the box.

@pavelzw
Copy link
Contributor

pavelzw commented Mar 2, 2024

I like this approach since this ensures that you are running the proper commands when you are in pixi shell or you did the activation with eval "$(pixi shell-hook)" and direnv.

Maybe also add the behavior that you don't activate again if the env var is already set? But this might be a bit too much magic...

@baszalmstra
Copy link
Contributor

I think there are two cases:

  1. You already activated the environment through shell-hook or shell, in that case, I also think it makes sense that we default the environment to the currently activated environment.
  2. You have not yet activated an environment. This is the case that @ruben-arts is talking about I think.

We could also look at the PIXI_PROJECT_MANIFEST variable and only if that points to the same path as the current project use PIXI_ENVIRONMENT_NAME as the default. We could also short-circuit activation if the environment is already activated based on that environment variable.

WDYT?

@mariusvniekerk
Copy link
Contributor Author

I think as long as we print something when this env var is actually set the "magic" behavior that may exist goes away

@ruben-arts
Copy link
Contributor

We've decided that we want to implement as @baszalmstra describes. Adding the warning as @mariusvniekerk describes is a nice to have.

@ruben-arts
Copy link
Contributor

Fixed in: #1080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement Feature request
Projects
None yet
Development

No branches or pull requests

4 participants