feat: Add new command option to set env file for pdm script #3358
feat: Add new command option to set env file for pdm script #3358Zheaoli wants to merge 6 commits intopdm-project:mainfrom
Conversation
Signed-off-by: Manjusaka <me@manjusaka.me>
Signed-off-by: Manjusaka <me@manjusaka.me>
Signed-off-by: Manjusaka <me@manjusaka.me>
Signed-off-by: Manjusaka <me@manjusaka.me>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3358 +/- ##
==========================================
+ Coverage 85.21% 85.24% +0.02%
==========================================
Files 112 112
Lines 11461 11472 +11
Branches 2505 2507 +2
==========================================
+ Hits 9767 9779 +12
+ Misses 1168 1167 -1
Partials 526 526
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Manjusaka <me@manjusaka.me>
There was a problem hiding this comment.
I would like to suggest some improvements
The env files can be cascaded in a way that more specific env file can override less specific ones. For example, if PDM_ENVIRONMENT=prod, we look for the following files and load them if exists:
.env(effective for all environments).env.prod(effective forprodonly).env.local(effective for all environments).env.prod.local(effective forprodonly)
The variables are merged in the above order, with the latter taking precedence.
The improvement is to make .local a special modifier rather than a regular environment name. It contains the env vars for the current machine only, and .env*.local should be added to the .gitignore, while other .env files can be shared safely.
Also happy to hear @noirbizarre 's thoughts since he is the one involved in PDM scripts the most.
Nice idea! I will update it ASAP |
|
Sorry, I thought I answered this long ago, but it wasn't the case. So here's my position: I see value in the However, I have a counterproposal: I see 2 main use cases for dotenv files:
I also like the idea of cascading env files. So, I would:
Then this should work: _.env_file = [
".env.{environment}",
".env.{environment}.local",
]But also this: my-task.env_file = [
"dotenvs/my-task",
"dotenvs/my-task.{environment}",
"dotenvs/my-task.{environment}.local",
]Bonus: the environment could also be exposed as script placeholder What do you think ? |
Pull Request Checklist
news/describing what is new.Describe what you have changed in this PR.
Fix #3355