-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathenvironment.py
65 lines (48 loc) · 1.63 KB
/
environment.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import sys
from enum import Enum
from functools import lru_cache
from pathlib import Path
from shared.config import get_config
class Environment(Enum):
production = "production"
local = "local"
enterprise = "enterprise"
def get_current_env() -> Environment:
"""
Gets the current environment of the system
Returns:
Environment: The current environment
"""
return _get_cached_current_env()
def is_enterprise() -> bool:
"""Tells whether the current environment is enterprise or not
Returns:
bool: True if the current environment is enterprise, else False
"""
return get_current_env() == Environment.enterprise
@lru_cache()
def _get_cached_current_env() -> Environment:
return _calculate_current_env()
def _get_current_folder() -> str:
return getattr(sys, "_MEIPASS", os.getcwd())
def _calculate_current_env() -> Environment:
run_env = os.getenv("RUN_ENV")
if run_env is not None:
if run_env == "ENTERPRISE":
return Environment.enterprise
elif run_env == "DEV":
return Environment.local
else:
return Environment.production
os.environ["CODECOV_HOME"] = _get_current_folder()
some_dir = Path(os.getenv("CODECOV_HOME"))
if os.path.exists(some_dir / "src/is_enterprise"):
return Environment.enterprise
if os.getenv("CURRENT_ENVIRONMENT", "production") == "local":
return Environment.local
return Environment.production
def get_external_dependencies_folder():
return get_config(
"services", "external_dependencies_folder", default="./external_deps"
)