-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
82 lines (64 loc) · 2.24 KB
/
config.py
File metadata and controls
82 lines (64 loc) · 2.24 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import sys
import typing
import datetime
import requests
import yaml
class Config:
"""
Consists of methods that parse the global settings summarised in the online
YAML dictionaries
"""
def __init__(self):
"""
The constructor
"""
self.root = os.path.abspath(__package__)
def paths(self, partitions: list):
"""
Creates a path relative to the project's root directory
:param partitions:
:return:
path: The created from a list of directories
"""
path = self.root
for partition in partitions:
path = os.path.join(path, partition)
return path
def variables(self) -> typing.Dict:
"""
Parses the global variables file of this project
:return:
"""
url = 'https://raw.githubusercontent.com/discourses/derma/develop/resources/variables.yml'
try:
req = requests.get(url)
except requests.exceptions.RequestException as e:
print(e)
sys.exit(1)
variables = yaml.safe_load(req.text)
# Image Dimension
variables['images']['image_dimension'] = (variables['images']['rows'], variables['images']['columns'],
variables['images']['channels'])
# local Storage
variables['modelling']['model_checkpoints_path'] = \
self.paths(variables['modelling']['model_checkpoints_directory'])
variables['images']['path'] = self.paths(variables['zipped']['images']['unzipped'])
# Cloud Storage
datetime_string = datetime.datetime.now().strftime('%Y%m%d.%H%M%S')
variables['modelling']['s3_path'] = variables['modelling']['s3_bucket'] + datetime_string + '/'
return variables
@staticmethod
def logs() -> typing.Dict:
"""
Parses the logs settings file of this project
:return:
"""
url = 'https://raw.githubusercontent.com/discourses/derma/develop/resources/logs.yml'
try:
req = requests.get(url)
except requests.exceptions.RequestException as e:
print(e)
sys.exit(1)
logs = yaml.safe_load(req.text)
return logs