Skip to content

Commit

Permalink
Makes current working dir the default INVESTD_DATA dir (#59)
Browse files Browse the repository at this point in the history
* Update default investd_data folder if not provided. rename .env to .investd
* Update .investd
  • Loading branch information
adri0 authored Dec 20, 2023
1 parent 4a41de7 commit 8e01fce
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .investd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Investd will read configuration variables from a file named .investd in the current working directory if available.
INVESTD_REF_CURRENCY = PLN
INVESTD_DATA = sample_data
3 changes: 0 additions & 3 deletions .template.env

This file was deleted.

4 changes: 2 additions & 2 deletions investd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import yaml
from dotenv import load_dotenv

load_dotenv()
load_dotenv(".investd")

path_logging_conf = Path("logging.yaml")
path_logging_conf = Path(__file__).parent.parent / "logging.yaml"
if path_logging_conf.exists():
with path_logging_conf.open("r") as conf_yaml:
log_conf = yaml.safe_load(conf_yaml)
Expand Down
15 changes: 11 additions & 4 deletions investd/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@

log = logging.getLogger(__name__)

INVESTD_DATA = Path(os.getenv("INVESTD_DATA", "investd_data"))

if not os.getenv("INVESTD_DATA"):
log.warn(
"INVESTD_DATA environment variable not set. "
"Using current working directory as INVESTD_DATA."
)


INVESTD_DATA = Path(os.getenv("INVESTD_DATA", "."))
INVESTD_SOURCES = Path(os.getenv("INVESTD_SOURCES", INVESTD_DATA / "sources"))
INVESTD_PERSIST = Path(os.getenv("INVESTD_PERSIST", INVESTD_DATA / "persist"))
INVESTD_REPORTS = Path(os.getenv("INVESTD_REPORTS", INVESTD_DATA / "reports"))
Expand All @@ -36,11 +44,10 @@ def init_dirs() -> None:
Check if data dirs exist, create them otherwise.
"""
config_vars = get_config_variables().items()
log.info(", ".join(f"{name}: {value}" for name, value in config_vars))
log.debug(", ".join(f"{name}: {value}" for name, value in config_vars))
if not INVESTD_DATA.exists():
print(
f"INVESTD_DATA directory ({INVESTD_DATA}) doesn't exist. "
"Let me create it for you."
)
for conf_path in (INVESTD_SOURCES, INVESTD_PERSIST, INVESTD_REPORTS):
conf_path.mkdir(exist_ok=True)
INVESTD_DATA.mkdir(exist_ok=True, parents=True)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ profile = "black"

[tool.pytest.ini_options]
testpaths = ["tests"]
env_files = "tests/resources/.test.env"
env_files = "tests/resources/.investd"

[tool.mypy]
plugins = "pydantic.mypy"
Expand Down
File renamed without changes.

0 comments on commit 8e01fce

Please sign in to comment.