From 4037708082ae206d66b7cfe28f5724b0917e580c Mon Sep 17 00:00:00 2001 From: Brandon Squizzato <35474886+bsquizz@users.noreply.github.com> Date: Wed, 27 Oct 2021 14:30:13 -0400 Subject: [PATCH] Fix circular import (#145) --- bonfire/config.py | 20 ++++---------------- bonfire/utils.py | 21 ++++++++++++++++----- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/bonfire/config.py b/bonfire/config.py index 264a15b0..998ddc5a 100644 --- a/bonfire/config.py +++ b/bonfire/config.py @@ -8,26 +8,14 @@ from dotenv import load_dotenv -from bonfire.utils import load_file, FatalError +from bonfire.utils import load_file, get_config_path, FatalError log = logging.getLogger(__name__) -def _get_config_path(): - xdg_config_home = os.environ.get("XDG_CONFIG_HOME") - if xdg_config_home: - config_home = Path(xdg_config_home) - else: - config_home = Path.home().joinpath(".config") - - return config_home.joinpath("bonfire") - - -DEFAULT_CONFIG_PATH = _get_config_path().joinpath("config.yaml") -DEFAULT_ENV_PATH = _get_config_path().joinpath("env") -DEFAULT_SECRETS_DIR = _get_config_path().joinpath("secrets") -VER_CHECK_PATH = _get_config_path().joinpath("lastvercheck") -VER_CHECK_TIME = 3600 # check every 1hr +DEFAULT_CONFIG_PATH = get_config_path().joinpath("config.yaml") +DEFAULT_ENV_PATH = get_config_path().joinpath("env") +DEFAULT_SECRETS_DIR = get_config_path().joinpath("secrets") DEFAULT_CLOWDENV_TEMPLATE = resource_filename( "bonfire", "resources/local-cluster-clowdenvironment.yaml" diff --git a/bonfire/utils.py b/bonfire/utils.py index 33ce6d0d..4230bdc2 100644 --- a/bonfire/utils.py +++ b/bonfire/utils.py @@ -15,8 +15,6 @@ import requests from cached_property import cached_property -import bonfire.config as conf - class FatalError(Exception): """An exception that will cause the CLI to exit""" @@ -24,9 +22,22 @@ class FatalError(Exception): pass +def get_config_path(): + xdg_config_home = os.environ.get("XDG_CONFIG_HOME") + if xdg_config_home: + config_home = Path(xdg_config_home) + else: + config_home = Path.home().joinpath(".config") + + return config_home.joinpath("bonfire") + + PKG_NAME = "crc-bonfire" PYPI_URL = f"https://pypi.python.org/pypi/{PKG_NAME}/json" +VER_CHECK_PATH = get_config_path().joinpath("lastvercheck") +VER_CHECK_TIME = 3600 # check every 1hr + GH_RAW_URL = "https://raw.githubusercontent.com/{org}/{repo}/{ref}{path}" GL_RAW_URL = "https://gitlab.cee.redhat.com/{group}/{project}/-/raw/{ref}{path}" GH_API_URL = os.getenv("GITHUB_API_URL", "https://api.github.com") @@ -436,7 +447,7 @@ def _compare_version(pypi_version): def _update_ver_check_file(): - ver_check_file = Path(conf.VER_CHECK_PATH) + ver_check_file = Path(VER_CHECK_PATH) try: with ver_check_file.open(mode="w") as fp: fp.write(str(time.time())) @@ -445,7 +456,7 @@ def _update_ver_check_file(): def _ver_check_needed(): - ver_check_file = Path(conf.VER_CHECK_PATH) + ver_check_file = Path(VER_CHECK_PATH) if not ver_check_file.exists(): _update_ver_check_file() return True @@ -457,7 +468,7 @@ def _ver_check_needed(): except (OSError, ValueError): log.exception("failed to read version check file at path: %s", ver_check_file.resolve()) - if time.time() > last_check_time + conf.VER_CHECK_TIME: + if time.time() > last_check_time + VER_CHECK_TIME: _update_ver_check_file() return True