5
5
import re
6
6
import subprocess
7
7
8
+ import eosfactory
8
9
import eosfactory .core .errors as errors
9
10
import eosfactory .core .logger as logger
10
11
import eosfactory .core .utils as utils
15
16
EOSIO_CDT_VERSION = "1.6.1"
16
17
PYTHON_VERSION = "3.5 or higher"
17
18
EOSFACTORY_DIR = "eosfactory/"
18
- APP_DATA_DIR_USER = (
19
- os .path .expandvars ("${HOME}/.local/" + EOSFACTORY_DIR ),
20
- os .path .expandvars ("${HOME}" )
21
- )
22
- APP_DATA_DIR_SUDO = ("/usr/local/" + EOSFACTORY_DIR , "/usr/local/" )
23
- APP_CWD_DIR = "/tmp/eosfactory/"
19
+ TMP = "/tmp/eosfactory/"
24
20
SETUPTOOLS_NAME = "eosfactory_tokenika"
25
21
26
22
LOCALHOST_HTTP_ADDRESS = "127.0.0.1:8888"
32
28
TEMPLATE_DIR = ("TEMPLATE_DIR" , "templates/contracts" )
33
29
EOSIO_CPP_DIR = "/usr/opt/eosio.cdt/0.0.0/"
34
30
31
+ eosfactory_data_ = ("EOSFACTORY_DATA_DIR" ,
32
+ [os .path .expandvars ("${HOME}/.local/" + EOSFACTORY_DIR ),\
33
+ "/usr/local/" + EOSFACTORY_DIR ,],
34
+ [])
35
35
node_address_ = ("LOCAL_NODE_ADDRESS" , [LOCALHOST_HTTP_ADDRESS ])
36
36
wallet_address_ = ("WALLET_MANAGER_ADDRESS" , [LOCALHOST_HTTP_ADDRESS ])
37
37
genesis_json_ = ("EOSIO_GENESIS_JSON" ,
74
74
"EOSIO_CONTRACT_WORKSPACE" , [CONTRACTS_DIR ])
75
75
76
76
77
- def get_app_data_dir ():
78
- if APP_DATA_DIR_SUDO [1 ] in __file__ :
79
- app_data_dir = APP_DATA_DIR_SUDO [0 ]
80
- elif os .path .expandvars (APP_DATA_DIR_USER [1 ]) in __file__ :
81
- app_data_dir = APP_DATA_DIR_USER [0 ]
82
- else :
83
- app_data_dir = eosf_dir ()
84
-
85
- if app_data_dir and os .path .exists (app_data_dir ):
86
- return app_data_dir
77
+ def eosfactory_data ():
78
+ '''Data directory.
87
79
88
- raise errors .Error ('''
89
- Cannot determine the directory of application data. Tried:
90
- {}
91
- {}
92
- {}
93
- The path '__file__' is
94
- {}
95
- The chosen path is
80
+ For developer's installation, data is in the root of the installation.
81
+ .: wsl_root.sh
82
+ config: config.ini, config.json, genesis.json, ...
83
+ contracts: eosio_token, hello_world, tic_tac_toe, ...
84
+ templates: contracts, ...
85
+ includes: eoside, ...
86
+ libs: ...
87
+ '''
88
+ tested = []
89
+ is_not_linked = is_site_package ()
90
+
91
+ if not is_not_linked :
92
+ path = eosf_dir ()
93
+ tested .append (path )
94
+ if os .path .exists (os .path .join (path , "config" , "config.ini" )):
95
+ return path
96
+ elif is_not_linked == 1 :
97
+ for path in eosfactory_data_ [1 ]:
98
+ tested .append (path )
99
+ if os .path .exists (os .path .join (path , "config" , "config.ini" )):
100
+ return path
101
+ elif is_not_linked == 2 :
102
+ for path in eosfactory_data_ [2 ]:
103
+ tested .append (path )
104
+ if os .path .exists (os .path .join (path , "config" , "config.ini" )):
105
+ return path
106
+
107
+ msg = "Cannot determine the directory of application data. Tried:"
108
+ for path in tested :
109
+ msg = '''{}
96
110
{}
97
- but it does not exist, seemingly.
98
- ''' .format (
99
- APP_DATA_DIR_SUDO [0 ], APP_DATA_DIR_USER [0 ], eosf_dir (),
100
- __file__ ,
101
- app_data_dir ),
102
- translate = False )
111
+ ''' .format (msg , path )
112
+
113
+ raise errors .Error (msg , translate = False )
114
+
115
+
116
+ def is_site_package ():
117
+ is_local_or_system = - 1
118
+ eosfactory_path = eosfactory .__path__
119
+ for item in eosfactory_path :
120
+ if "site-packages" in item :
121
+ if "local" in item :
122
+ is_local_or_system = 1
123
+ else :
124
+ is_local_or_system = 2
103
125
126
+ break
127
+
128
+ if "eosfactory/eosfactory" in item :
129
+ is_local_or_system = 0
104
130
105
- def is_linked_package ():
106
- is_linked = os .path .exists (os .path .join (eosf_dir (), CONFIG_DIR ))
107
- is_installed_package = not is_linked and get_app_data_dir ()
131
+ # No EOSFactory:
132
+ # import eosfactory
133
+ # Traceback (most recent call last):
134
+ # File "<stdin>", line 1, in <module>
135
+ # ModuleNotFoundError: No module named 'eosfactory'
108
136
109
- if (not is_linked ) and (not is_installed_package ):
137
+ # developer's installation:
138
+ # >>> import eosfactory
139
+ # >>> print(eosfactory.__path__)
140
+ # ['/mnt/c/Workspaces/EOS/eosfactory/eosfactory']
141
+
142
+ if is_local_or_system == - 1 :
110
143
raise errors .Error ('''
111
- Cannot determine the configuration directory.
112
- {}
144
+ Cannot determine the configuration directory. 'eosfactory.__path__' is
113
145
{}
114
- {}
115
- ''' .format (
116
- os .path .join (eosf_dir (), CONFIG_DIR ),
117
- os .path .join (APP_DATA_DIR_USER [0 ], CONFIG_DIR ),
118
- os .path .join (APP_DATA_DIR_SUDO [0 ], CONFIG_DIR )
119
- ), translate = False )
120
-
121
- if is_linked and is_installed_package :
122
- is_linked = True
146
+ ''' .format (eosfactory_path ), translate = False )
123
147
124
- return is_linked
148
+ return is_local_or_system
125
149
126
150
127
151
def set_contract_workspace_dir (contract_workspace_dir = None , is_set = False ):
@@ -155,7 +179,7 @@ def set(contract_workspace_dir):
155
179
if contract_workspace_dir_ [0 ] in map :
156
180
contract_workspace_dir = map [contract_workspace_dir_ [0 ]]
157
181
else :
158
- contract_workspace_dir = os .path .join (APP_CWD_DIR , CONTRACTS_DIR )
182
+ contract_workspace_dir = os .path .join (TMP , CONTRACTS_DIR )
159
183
160
184
new_dir = tilde (input (utils .heredoc ('''
161
185
Where do you prefer to keep your smart-contract projects?
@@ -183,7 +207,7 @@ def set(contract_workspace_dir):
183
207
184
208
185
209
def config_dir ():
186
- dir = os .path .join (get_app_data_dir (), CONFIG_DIR )
210
+ dir = os .path .join (eosfactory_data (), CONFIG_DIR )
187
211
if not os .path .exists (dir ):
188
212
raise errors .Error ('''
189
213
Cannot find the configuration directory
@@ -193,7 +217,7 @@ def config_dir():
193
217
194
218
195
219
def template_dir ():
196
- dir = os .path .join (get_app_data_dir (), TEMPLATE_DIR [1 ])
220
+ dir = os .path .join (eosfactory_data (), TEMPLATE_DIR [1 ])
197
221
if not os .path .exists (dir ):
198
222
raise errors .Error ('''
199
223
Cannot find the template directory
@@ -211,7 +235,7 @@ def eoside_includes_dir():
211
235
'''
212
236
dir = includes_ [1 ]
213
237
if not os .path .isabs (dir ):
214
- dir = os .path .join (get_app_data_dir (), includes_ [1 ])
238
+ dir = os .path .join (eosfactory_data (), includes_ [1 ])
215
239
if not os .path .exists (dir ):
216
240
dir = None
217
241
return dir
@@ -226,7 +250,7 @@ def eoside_libs_dir():
226
250
'''
227
251
dir = libs_ [1 ]
228
252
if not os .path .isabs (dir ):
229
- dir = os .path .join (get_app_data_dir (), libs_ [1 ])
253
+ dir = os .path .join (eosfactory_data (), libs_ [1 ])
230
254
if not os .path .exists (dir ):
231
255
dir = None
232
256
return dir
@@ -242,7 +266,7 @@ def contract_workspace_dir(dont_set_workspace=False):
242
266
subdirectory (typically *contracts/*) of the EOSFActory installation, if
243
267
EOSFactory is installed from its GitHub repository, otherwise, they go to
244
268
a directory specified as
245
- `join(.config.APP_CWD_DIR , .config.CONTRACTS_DIR)`.
269
+ `join(.config.TMP , .config.CONTRACTS_DIR)`.
246
270
247
271
The setting may be changed with
248
272
*EOSIO_CONTRACT_WORKSPACE* entry in the *config.json* file,
@@ -271,10 +295,10 @@ def contract_workspace_dir(dont_set_workspace=False):
271
295
set as the contract workspace directory, does not exist.
272
296
''' .format (path ), translate = False )
273
297
else :
274
- if is_linked_package ():
298
+ if not is_site_package ():
275
299
path = os .path .join (eosf_dir (), path )
276
300
else :
277
- path = os .path .join (APP_CWD_DIR , path )
301
+ path = os .path .join (TMP , path )
278
302
if not os .path .exists (path ):
279
303
os .makedirs (path )
280
304
@@ -307,20 +331,14 @@ def abi_file(contract_dir_hint):
307
331
def eosf_dir ():
308
332
'''The absolute directory of the EOSFactory installation.
309
333
'''
310
- try :
311
- path = os .path .realpath (os .path .join (
334
+ path = os .path .realpath (os .path .join (
312
335
os .path .realpath (__file__ ), FROM_HERE_TO_EOSF_DIR ))
313
- except Exception as e :
314
- raise errors .Error ('''
315
- Impossible error: __file__ path cannot be determined. The message is
316
- {}
317
- ''' .format (str (e )))
318
336
319
337
if os .path .exists (path ):
320
338
return path
321
339
322
340
raise errors .Error ('''
323
- Cannot determine the root directory of EOSFactory.
341
+ Cannot determine the root directory of the EOSFactory installation .
324
342
The path to the file 'config.py' is
325
343
'{}'.
326
344
The expected installation path, which is
@@ -426,7 +444,7 @@ def wsl_root():
426
444
return ""
427
445
428
446
wsl_root_sh = "wsl_root.sh"
429
- wsl_root_sh = os .path .join (get_app_data_dir (), wsl_root_sh )
447
+ wsl_root_sh = os .path .join (eosfactory_data (), wsl_root_sh )
430
448
431
449
if wsl_root_ [1 ][0 ] is None :
432
450
path = ""
@@ -882,9 +900,9 @@ def contract_dir(contract_dir_hint):
882
900
return os .path .realpath (contract_dir_ )
883
901
884
902
# ? the relative path to a contract directory, relative to
885
- # 'get_app_data_dir ()/contracts'
903
+ # 'eosfactory_data ()/contracts'
886
904
contract_dir_ = os .path .join (
887
- get_app_data_dir (), CONTRACTS_DIR , contract_dir_hint )
905
+ eosfactory_data (), CONTRACTS_DIR , contract_dir_hint )
888
906
889
907
trace = trace + contract_dir_ + "\n "
890
908
if os .path .isdir (contract_dir_ ):
@@ -1102,11 +1120,11 @@ def current_config(contract_dir=None, dont_set_workspace=False):
1102
1120
map = {}
1103
1121
1104
1122
map ["CONFIG_FILE" ] = config_file ()
1105
- if is_linked_package ():
1123
+ if not is_site_package ():
1106
1124
try :
1107
- map ["EOS_FACTORY_DIR " ] = eosf_dir ()
1125
+ map ["EOSFACTORY_DIR " ] = eosf_dir ()
1108
1126
except :
1109
- map ["EOS_FACTORY_DIR " ] = None
1127
+ map ["EOSFACTORY_DIR " ] = None
1110
1128
try :
1111
1129
map [node_address_ [0 ]] = http_server_address ()
1112
1130
except :
@@ -1185,10 +1203,15 @@ def current_config(contract_dir=None, dont_set_workspace=False):
1185
1203
map [libs_ [0 ]] = eoside_libs_dir ()
1186
1204
except :
1187
1205
map [libs_ [0 ]] = None
1206
+ try :
1207
+ map [eosfactory_data_ [0 ]] = eosfactory_data ()
1208
+ except :
1209
+ map [eosfactory_data_ [0 ]] = None
1188
1210
try :
1189
1211
map [TEMPLATE_DIR [0 ]] = template_dir ()
1190
1212
except :
1191
1213
map [TEMPLATE_DIR [0 ]] = None
1214
+
1192
1215
1193
1216
map ["EOSIO_VERSION" ] = eosio_version ()
1194
1217
map ["EOSIO_CDT_VERSION" ] = eosio_cpp_version ()
@@ -1226,22 +1249,21 @@ def config():
1226
1249
Python version {}
1227
1250
''' .format (VERSION , EOSIO_VERSION , EOSIO_CDT_VERSION , PYTHON_VERSION )
1228
1251
)
1229
- import pdb ; pdb . set_trace ()
1230
- if is_linked_package () :
1252
+ is_not_linked = is_site_package ()
1253
+ if not is_not_linked :
1231
1254
print (
1232
- '''
1233
- EOSFactory package is installed as a link to the directory:
1255
+ '''EOSFactory package is installed as a link to the directory:
1234
1256
'{}'
1235
1257
''' .format (os .path .join (eosf_dir (), EOSFACTORY_DIR ))
1236
1258
)
1237
- elif APP_DATA_DIR_USER [ 0 ] == get_app_data_dir () :
1259
+ elif is_not_linked == 1 :
1238
1260
print (
1239
- '''EOSFactory is installed as a PyPi package locally.
1261
+ '''EOSFactory is installed as a site package locally.
1240
1262
'''
1241
1263
)
1242
- elif APP_DATA_DIR_SUDO [ 0 ] == get_app_data_dir () :
1264
+ elif is_not_linked == 2 :
1243
1265
print (
1244
- '''EOSFactory is installed as a PyPi package globally.
1266
+ '''EOSFactory is installed as a site package globally.
1245
1267
'''
1246
1268
)
1247
1269
0 commit comments