pyani icon indicating copy to clipboard operation
pyani copied to clipboard

Have `pyani` use a user-controlled config file

Open widdowquinn opened this issue 4 years ago • 4 comments

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.

widdowquinn avatar Oct 02 '19 08:10 widdowquinn

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

baileythegreen avatar Sep 05 '21 12:09 baileythegreen

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.

widdowquinn avatar Sep 06 '21 14:09 widdowquinn

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.

baileythegreen avatar Sep 06 '21 15:09 baileythegreen

I was assuming the default values would be in pyani_config.py.

Yes - it seems a sensible place.

widdowquinn avatar Sep 06 '21 15:09 widdowquinn