-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpath.py
More file actions
executable file
·34 lines (26 loc) · 927 Bytes
/
path.py
File metadata and controls
executable file
·34 lines (26 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from dotenv import load_dotenv
from pathlib import Path
import os
PATH_DOTENV = Path(__file__).parents[0] / ".env"
PATHS = ["DIR_SRC", "DIR_DATA", "LIB_PYNICHE", "DIR_TMP"]
class PathFinder:
def __init__(self):
self.load_env()
def load_env(self):
env_exists = load_dotenv(PATH_DOTENV)
if env_exists:
print(f"Successfully loaded {PATH_DOTENV}")
else:
raise Exception(f"No .env file found in {PATH_DOTENV}")
self.show()
def find_dirs(self, path):
return [d for d in path.iterdir() if d.is_dir()]
def __getitem__(self, key):
return Path(os.environ.get(key))
def __repr__(self):
self.show()
return f"PathFinder: {PATH_DOTENV}"
def show(self):
print("Available project environments: ")
for env in PATHS:
print(f" {env}={os.environ[env]}")