Skip to content

Commit

Permalink
Fix circular import (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsquizz authored Oct 27, 2021
1 parent d37f5d6 commit 4037708
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
20 changes: 4 additions & 16 deletions bonfire/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 16 additions & 5 deletions bonfire/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,29 @@
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"""

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")
Expand Down Expand Up @@ -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()))
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 4037708

Please sign in to comment.