pyani
pyani copied to clipboard
Have `pyani` use a user-controlled config file
Summary:
The current config arrangement is hacky and awful. It would be better to have a user-controlled config file that specifies colour palettes, application locations and so on. This could be defined in environment variables and/or a config.py
or config.json
file.
An extension of this could be used for pipeline control of the pyani
chain.
Proposed format: .toml
for readability.
Options to include:
- custom paths for executables†
- colour scheme used for plots†
- input and output directories
- modifiable parameters for the algorithms†
- algorithm itself?
† should have a default value on which to fall back
Default values could continue to be defined as they are now, in a top-level config.py
(or even TOML) file, e.g.:
import os
from dotenv import load_dotenv
BASEDIR = os.path.abspath(os.path.dirname(__file__))
load_dotenv(os.path.join(BASEDIR, ".env"))
class Config(object):
# Database configuration
TEST_DBPATH = os.path.join(BASEDIR, "testdb.sqlite")
DBPATH = os.environ.get("SRE_DBPATH") or TEST_DBPATH
# Flask app configuration
SREDB_HOST = "127.0.0.1"
SREDB_PORT = "5000"
FLASK_SECRET_KEY = os.environ.get("FLASK_SECRET_KEY") or os.urandom(24)
SQLALCHEMY_DATABASE_URI = os.environ.get(
"SREDB_DBURL"
) or "sqlite:///" + os.path.join(BASEDIR, DBPATH)
SQLALCHEMY_TRACK_MODIFICATIONS = False
values are then imported as a Config object:
from config import Config
which can be used to populated, for example, the argparse
default values and/or anything that's not present in the user-defined TOML.
I was assuming the default values would be in pyani_config.py
. Anything similar thing would be fine, but defaults definitely don't need to be in a file the user would generally modify.
I was assuming the default values would be in pyani_config.py.
Yes - it seems a sensible place.