Lore Environment¶
Lore maintains an independent python virtualenv for each app, along with several ways to set environment variables that allow Lore apps apps to be 100% replicated from development to production, without any day to day effort on the behalf of developers. There is no manual activation, or magic env vars, or hidden files that break python for everything else. No knowledge required of venv, pyenv, pyvenv, virtualenv, virtualenvwrapper, pipenv, conda. Ain’t nobody got time for that.
The first thing lore does when launched from a command line, is to find the correct virtualenv, with the perfect set of dependencies and relaunch the same command in that environment. Virtualenv names are based on the Lore app name, so if you have two apps with the same name, they will share a virtualenv by default.
lore.env
provides constants to make working with the correct
executables easy. The most common is lore.env.NAME
.
-
lore.env.
APP
= 'stable'¶ The name of this Lore app
-
lore.env.
BIN_FLASK
= u'/home/docs/.pyenv/versions/3.6.6/envs/stable/bin/flask'¶ path to virtualenv flask executable
-
lore.env.
BIN_JUPYTER
= u'/home/docs/.pyenv/versions/3.6.6/envs/stable/bin/jupyter'¶ path to virtualenv jupyter executable
-
lore.env.
BIN_LORE
= u'/home/docs/.pyenv/versions/3.6.6/envs/stable/bin/lore'¶ path to virtualenv lore executable
-
lore.env.
BIN_PYENV
= u'/home/docs/.pyenv/bin/pyenv'¶ path to pyenv executable
-
lore.env.
BIN_PYTHON
= u'/home/docs/.pyenv/versions/3.6.6/envs/stable/bin/python'¶ path to virtualenv python executable
-
lore.env.
COLOR
= 32¶ color code environment names for logging
-
lore.env.
DATA_DIR
= u'./data'¶ disk based caching and data dependencies
-
lore.env.
DEFAULT_NAME
= u'development'¶ the environment you get when you just can’t be bothered to care
-
lore.env.
DEVELOPMENT
= u'development'¶ environment for mucking about
-
lore.env.
ENV_DIRECTORY
= u'/conf/env'¶ more environment variables will be loaded from files in this directory
-
lore.env.
ENV_FILE
= u'./.env'¶ environment variables will be loaded from this file first
-
lore.env.
FLASK_APP
= u'/home/docs/.pyenv/versions/3.6.6/envs/stable/lib/python3.6/site-packages/lore/www/__init__.py'¶ path to the current lore app’s flask app
-
lore.env.
HOME
= u'/home/User'¶ HOME
directory of the current user orROOT
if unset
-
lore.env.
HOST
= u'localhost'¶ current machine name:
socket.gethostname
-
lore.env.
JUPYTER_KERNEL_PATH
= u'/'¶ location of jupyter kernels
-
lore.env.
LIB
= u'/home/docs/checkouts/readthedocs.org/user_builds/lore-machine-learning/checkouts/stable/lib'¶ packages in
./lib
are also available for import in the Lore app.
-
lore.env.
LOG_DIR
= u'./logs'¶ log file storage
-
lore.env.
MODELS_DIR
= u'./models'¶ disk based model store
-
lore.env.
NAME
= u'development'¶ current environment name, e.g.
'development'
,'test'
,'production'
-
lore.env.
PREFIX
= u'/home/docs/.pyenv/versions/3.6.6/envs/stable'¶ path to the Lore app virtualenv
-
lore.env.
PRODUCTION
= u'production'¶ environment that actually matters
-
lore.env.
PYENV
= '/home/docs/.pyenv'¶ Path to pyenv root
-
lore.env.
PYTHON_VERSION
= u'2.7.16'¶ Version of python required by this Lore app.
-
lore.env.
PYTHON_VERSION_INFO
= [2, 7, 16]¶ Parsed version of python required by this Lore app.
-
lore.env.
REQUIREMENTS
= u'./requirements.txt'¶ requirement files
-
lore.env.
ROOT
= u'.'¶ Relative root for all app files. Determined by
LORE_ROOT
, or iterating up directories until aruntime.txt
is found. If noruntime.txt
is foundos.getcwd
is used.
-
lore.env.
STDOUT_EXCEPTIONS
= True¶ exceptions are always logged, in addition they can be printed to any:sys.stdout
-
lore.env.
TEST
= u'test'¶ environment that definitely should reflect exactly what happens in production
-
lore.env.
TESTS_DIR
= u'./tests'¶ Lore app test suite
-
lore.env.
UNICODE_LOCALE
= True¶ does the current python locale support unicode?
-
lore.env.
UNICODE_UPGRADED
= False¶ did lore change current system locale for unicode support?
-
lore.env.
VERSION_PATH
= u'runtime.txt'¶ Path to the specification of this apps Python version.
-
lore.env.
WORK_DIR
= u'.'¶ root for disk based work
-
lore.env.
check_requirements
()[source]¶ Make sure all listed packages from requirements.txt have been installed into the virtualenv at boot.
-
lore.env.
exists
()[source]¶ Test whether a lore environmnet can be found from the current working directory.
Returns: True
if the environment existsReturn type: bool
-
lore.env.
extend_path
()[source]¶ Adds Lore App modules to the path to making importing easy, including
LIB
-
lore.env.
get_config
(path)[source]¶ Load a config from disk
Parameters: path (unicode) – target config Returns: Return type: configparser.Config
-
lore.env.
launched
()[source]¶ Test whether the current python environment is the correct lore env.
Returns: True
if the environment is launchedReturn type: bool
-
lore.env.
load_env_directory
()[source]¶ Adds environment variables defined in
ENV_DIRECTORY
to os.environ. Each file will be added to os.environ via filename = contents. Supports bash style comments and variable interpolation.
-
lore.env.
load_env_file
()[source]¶ Adds environment variables defined in
ENV_FILE
to os.environ. Supports bash style comments and variable interpolation.
-
lore.env.
read_version
(path)[source]¶ Attempts to read a python version string from a runtime.txt file
Parameters: path – to source of the string Returns: python version Return type: unicode or None
-
lore.env.
require
(packages)[source]¶ Ensures that a pypi package has been installed into the App’s python environment. If not, the package will be installed and your env will be rebooted.
- Example:
lore.env.require('pandas') # -> pandas is required. Dependencies added to requirements.txt
Parameters: packages ([unicode]) – requirements.txt style name and versions of packages