3 ms·
import envkey # Fetches and install environment In Python at least, that feels a bit icky. Modules can run complex code at import time, but it's rarely done.
by ProblemFactory 9y ago
import envkey # Fetches and install environment
In Python at least, that feels a bit icky. Modules can run complex code at import time, but it's rarely done.
The import order between modules is often not specified or carefully maintained, and web projects can have many main entry points. For example, a Django app might start from "wsgi.py" if run in a web server, from "manage.py" when running command-line utility scripts or tests, or from any other script file at all if a few setup lines are added.
People prefer to put all imports at the top of the file, but may want to do something right before or after envkey runs. Imports are not supposed to fail or throw exceptions, unless there is a serious code bug.
It would be nicer to have
import envkey # No important side-effects
envkey.setup() # Can be placed at the appropriate place
or similar.
- danenania 9y agoThanks for the feedback. A one-liner to import is more consistent with EnvKey's style (this is how it works in all the libraries), but perhaps it makes sense to expose the loader as a separate package so that you can have more granular control when it's necessary.