1
1
import tempfile
2
+ import uuid
2
3
from enum import Enum
3
4
from pathlib import Path
4
5
from types import MappingProxyType
@@ -42,16 +43,16 @@ def __init__(self, params: Optional[MappingProxyType] = None, from_file_path: Op
42
43
43
44
assert (params is not None ) or (from_file_path is not None ), 'One of params or from_file_path must be provided'
44
45
45
- if from_file_path is not None :
46
- self ._id = hash (from_file_path )
47
- self ._file_path = from_file_path
48
-
49
46
if params is not None :
50
47
self ._params = dict (params )
48
+ self ._file_path = Path (tempfile .gettempdir (), f'geophires-input-params_{ uuid .uuid4 ()!s} .txt' )
51
49
52
- if self ._file_path is None :
53
- self ._id = abs (hash (frozenset (self ._params .items ())))
54
- self ._file_path = Path (tempfile .gettempdir (), f'geophires-input-params_{ self ._id } .txt' )
50
+ if from_file_path is not None :
51
+ with open (from_file_path , encoding = 'UTF-8' ) as base_file :
52
+ with open (self ._file_path , 'a' , encoding = 'UTF-8' ) as f :
53
+ f .writelines (base_file .readlines ())
54
+ else :
55
+ self ._file_path = from_file_path
55
56
56
57
if params is not None :
57
58
# TODO validate params - i.e. that all names are accepted by simulation, values don't exceed max allowed,
@@ -60,11 +61,14 @@ def __init__(self, params: Optional[MappingProxyType] = None, from_file_path: Op
60
61
with open (self ._file_path , 'a' , encoding = 'UTF-8' ) as f :
61
62
f .writelines ([', ' .join ([str (p ) for p in param_item ]) + '\n ' for param_item in self ._params .items ()])
62
63
64
+ self ._id = hash (self ._file_path )
65
+
63
66
def as_file_path (self ):
64
67
return self ._file_path
65
68
66
69
def get_output_file_path (self ):
67
70
return Path (tempfile .gettempdir (), f'geophires-result_{ self ._id } .out' )
68
71
69
72
def __hash__ (self ):
73
+ """TODO make hashes for equivalent parameters equal"""
70
74
return self ._id
0 commit comments