Comments (5)
I don't think I wrote that bit of code, but I believe the idea here was that manually set environment variables should take precedence over variables specified in a file. For example, if I have a test program foo
that reads from a file that specifies MYKEY=myval
, and then i run foo
as:
$ MYKEY=differentval foo
The principle of least surprise would dictate that differentval
overrides the default specified in the file.
It seems like in your case, you'd want a refresh=True
kwarg.
A couple of issues here:
-
Environment variables aren't really designed to be changed at run-time. I think the 12-factor app-ish suggestion would be that a new process with a new environment should be forked off and used. But, in your case, that might not be possible or make sense.
-
The API design of
read_envfile
is a little wonky in theat**overrides
captures all of the kwargs, so just adding arefresh=True
environment variable will break backwards compatibility. Not a huge issue though, since that probably should be fixed any way: I'm not really sure whyoverrides
need to be specified this way (again, I don't think I wrote this bit of code).
I'm open to suggestions on what you think is best here. Thanks!
from envparse.
Good point about how the existing implementation ensures manually set env vars take precedence.
You're right too about the 12-factor approach. The trouble is we sometimes want to quickly tweak a setting and see the results without waiting for a new set of servers to deploy (which takes a few minutes).
- The API design of read_envfile is a little wonky in that **overrides captures all of the kwargs, so just adding a refresh=True environment variable will break backwards compatibility. Not a huge issue though, since that probably should be fixed any way: I'm not really sure why overrides need to be specified this way (again, I don't think I wrote this bit of code).
Changing:
def read_envfile(path=None, **overrides):
to
def read_envfile(path=None, refresh=False, **overrides):
only breaks compatibility for people already using an refresh
override right? That doesn't seem too onerous (although easy for me to say - no-one will complain to me if this breaks someone's application).
The only other option would be a new function/method, perhaps refresh_from_file
, that does the same as read_envfile
but ignores existing env vars.
Any preference?
from envparse.
Thinking a bit more about this.
Seems like the name refresh=True
isn't really that descriptive of the general case; for example makes less sense if you're just running this once.
_overwrite=False
seems a little better since it describes what's happening: we're overwriting any existing values with what's in the file; and we're not colliding if someone happens to use OVERRIDE=1
in their app.
In a 1.0
release, I think I'd want to remove that unnecessary **overrides
argument.
from envparse.
Ok, I'll submit a PR with that change.
from envparse.
This has a second implication:
environ.Env.read_env(root('envs/common.env'))
environ.Env.read_env(root('envs/local_settings.env'))
I expected that local_settings would overwrite values set in common. But if a value is set in common then it's already set and read_env('local_settings.env') has no effect.
So to get the behavior I expect (merging two env files) I have to load them in reverse order :0
from envparse.
Related Issues (20)
- Merge with the environs library? HOT 6
- Improve API for preprocessor
- Typo in warning HOT 1
- Schema could include pre/post processors
- Add "True" to truthy value HOT 1
- Adding a description about env vars
- Hash symbol breaks the line
- Can't access a full list of all variables
- read_envfile() recurses up the dir tree if path given, but file not found
- Name your logger with a consistent name
- env.bool('MY_BOOLEAN_VARIABLE') does not work
- Collaborative maintainership with Jazzband HOT 2
- Cannot parse dict with bool subtypes
- Env file always overridden by environment
- env.float doesn't work with negative numbers
- Update PyPi to current master branch. HOT 4
- consider python standard library's strtobool for boolean casting HOT 2
- Mirror os.environ by allowing Env to be accessed like a dictionary HOT 3
- env doesn't have attribute read_env() HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from envparse.