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

Allow inject enviroment variables via .env or other env file #3355

Open
1 task done
Zheaoli opened this issue Dec 22, 2024 · 5 comments · May be fixed by #3358
Open
1 task done

Allow inject enviroment variables via .env or other env file #3355

Zheaoli opened this issue Dec 22, 2024 · 5 comments · May be fixed by #3358
Labels
⭐ enhancement Improvements for existing features

Comments

@Zheaoli
Copy link
Contributor

Zheaoli commented Dec 22, 2024

Feature Description

For now, we may run some code via PDM script like

run_server = { shell = "uvicorn --host 0.0.0.0 --port $SERVER_PORT exporter.app:app --reload"}

Or I may some other environment variables in my program. I may want to write the environment variables to a file like .env when I deploy my program.

Problem and Solution

I propose add new global flag --env-file, the default value is .env. The PDM main process will inject the environment variables into subprocess if the file is exist

Additional Context

No response

Are you willing to contribute to the development of this feature?

  • Yes, I am willing to contribute to the development of this feature.
@Zheaoli Zheaoli added the ⭐ enhancement Improvements for existing features label Dec 22, 2024
@frostming
Copy link
Collaborator

does this work for you?
https://pdm-project.org/en/latest/usage/scripts/#env_file

@Zheaoli
Copy link
Contributor Author

Zheaoli commented Dec 23, 2024

I think this can work for basic usage, but it will still depend on some hard-code config.

In some circumstances, I may create different env files for various environments, like alpha.env and beta.env. I prefer to add a flag to switch the file instead of hard-code config.

@frostming
Copy link
Collaborator

I have some other ideas.

A famous saying goes "convention over configuration". It would be great if we could automatically read .env.<mode>[.local] like Vite.

But at this stage, explicitly passing the dotenv file name from the command line parameters can solve your problem.

@Zheaoli
Copy link
Contributor Author

Zheaoli commented Dec 24, 2024

I have some other ideas.

A famous saying goes "convention over configuration". It would be great if we could automatically read .env.<mode>[.local] like Vite.

But at this stage, explicitly passing the dotenv file name from the command line parameters can solve your problem.

we can do this thing at the same time lol.

@Zheaoli
Copy link
Contributor Author

Zheaoli commented Dec 24, 2024

So, Let me describe the detail

  1. We will add a flag named --environment and PDM_SCRIPT_ENVIRONMENT env variable to identify the environment we would like to use. Default value is local
  2. We will add a flag named --env-file to identify the env file we would like to use. The default value is .env.${PDM_SCRIPT_ENVIRONMENT}
  3. The current config option env_file will be deprecated in the future version and will raise a warning message for now.
  4. We make a convention that the variables in env file should not override the global env variables.

@frostming WDYT

@Zheaoli Zheaoli linked a pull request Dec 25, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ enhancement Improvements for existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants