cli: add 'config init' command

This commit is contained in:
Dima Gerasimov 2020-05-25 12:21:31 +01:00
parent 7bd7cc9228
commit e351c8ba49
4 changed files with 51 additions and 31 deletions

View file

@ -24,26 +24,13 @@ def assign_module(parent: str, name: str, module: ModuleType) -> None:
del ModuleType
def get_mycfg_dir():
import appdirs # type: ignore[import]
from pathlib import Path
import os
# not sure if that's necessary, i.e. could rely on PYTHONPATH instead
# on the other hand, by using MY_CONFIG we are guaranteed to load it from the desired path?
mvar = os.environ.get('MY_CONFIG')
if mvar is not None:
mycfg_dir = Path(mvar)
else:
mycfg_dir = Path(appdirs.user_config_dir('my'))
return mycfg_dir
# separate function to present namespace pollution
def setup_config() -> None:
import sys
import warnings
from typing import Optional
from .preinit import get_mycfg_dir
mycfg_dir = get_mycfg_dir()
if not mycfg_dir.exists():