2
2
Module dedicated to interacting with the environment (variables, version.json)
3
3
"""
4
4
import json
5
- import os
6
5
from functools import lru_cache
6
+ from pathlib import Path
7
7
8
8
from pydantic import BaseSettings
9
9
10
10
11
11
class Settings (BaseSettings ):
12
- """
13
- The Settings object extracts environment variables for convenience
14
- """
12
+ """The Settings object extracts environment variables for convenience."""
15
13
16
14
host : str = "0.0.0.0"
17
15
port : str = "80"
@@ -33,9 +31,7 @@ class Settings(BaseSettings):
33
31
34
32
@lru_cache ()
35
33
def get_settings () -> Settings :
36
- """
37
- Return the Settings object; use cache
38
- """
34
+ """Return the Settings object; use cache"""
39
35
return Settings ()
40
36
41
37
@@ -45,10 +41,9 @@ def get_version():
45
41
Return contents of version.json.
46
42
This has generic data in repo, but gets the build details in CI.
47
43
"""
48
- _root = os .path .dirname (os .path .dirname (os .path .dirname (__file__ )))
49
- version_path = os .path .join (_root , "version.json" )
50
44
info = {}
51
- if os .path .exists (version_path ):
52
- with open (version_path , "r" , encoding = "utf8" ) as version_file :
53
- info = json .load (version_file )
45
+ version_path = Path (__file__ ).parents [2 ] / "version.json"
46
+ print (version_path )
47
+ if version_path .exists ():
48
+ info = json .loads (version_path .read_text (encoding = "utf8" ))
54
49
return info
0 commit comments