Skip to content

Commit 746d80e

Browse files
authored
Merge pull request #14 from hippolyteblot/loading_config_file_name_from_env
Using env variable for the config file
2 parents 482c29b + ff43479 commit 746d80e

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

moteur_server_rest/bootstrap.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from dotenv import load_dotenv
2+
import os
23
import shutil
34
import signal
45
import sys
@@ -8,16 +9,7 @@
89

910

1011
def init_runtime():
11-
if len(sys.argv) > 1:
12-
logging.info("Loading config file %s", sys.argv[1])
13-
config_file = sys.argv[1]
14-
else:
15-
logging.info("Loading default config file %s", ".env")
16-
config_file = None
17-
load_dotenv(config_file)
18-
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
19-
set_docker_available(shutil.which("docker") is not None)
20-
12+
2113
logging.basicConfig(
2214
level=logging.INFO,
2315
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
@@ -29,6 +21,20 @@ def init_runtime():
2921

3022
logger = logging.getLogger("moteur-server")
3123

24+
# Config file from environment variable
25+
config_file = os.environ.get("MSR_CONF_FILE")
26+
if config_file:
27+
logging.info("Loading config file %s", config_file)
28+
else:
29+
logging.info("Loading default config file %s", ".env")
30+
config_file = None
31+
32+
# Load environment from the specified file
33+
load_dotenv(config_file)
34+
35+
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
36+
set_docker_available(shutil.which("docker") is not None)
37+
3238
def log_uncaught_exceptions(exc_type, exc_value, exc_traceback):
3339
if issubclass(exc_type, KeyboardInterrupt):
3440
sys.__excepthook__(exc_type, exc_value, exc_traceback)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "moteur-server-rest"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
description = ""
55
readme = "README.md"
66
requires-python = ">=3.9"

0 commit comments

Comments
 (0)