@@ -1144,182 +1144,3 @@ def updateDynamics(self):
1144
1144
for this_type in self .agents :
1145
1145
setattr (this_type , var_name , this_obj )
1146
1146
return dynamics
1147
-
1148
-
1149
- # ------------------------------------------------------------------------------
1150
- # Code to copy entire modules to a local directory
1151
- # ------------------------------------------------------------------------------
1152
-
1153
- # Define a function to run the copying:
1154
- def copy_module (target_path , my_directory_full_path , my_module ):
1155
- '''
1156
- Helper function for copy_module_to_local(). Provides the actual copy
1157
- functionality, with highly cautious safeguards against copying over
1158
- important things.
1159
-
1160
- Parameters
1161
- ----------
1162
- target_path : string
1163
- String, file path to target location
1164
-
1165
- my_directory_full_path: string
1166
- String, full pathname to this file's directory
1167
-
1168
- my_module : string
1169
- String, name of the module to copy
1170
-
1171
- Returns
1172
- -------
1173
- none
1174
- '''
1175
-
1176
- if target_path == 'q' or target_path == 'Q' :
1177
- print ("Goodbye!" )
1178
- return
1179
- elif target_path == os .path .expanduser ("~" ) or os .path .normpath (target_path ) == os .path .expanduser ("~" ):
1180
- print ("You have indicated that the target location is " + target_path +
1181
- " -- that is, you want to wipe out your home directory with the contents of " + my_module +
1182
- ". My programming does not allow me to do that.\n \n Goodbye!" )
1183
- return
1184
- elif os .path .exists (target_path ):
1185
- print ("There is already a file or directory at the location " + target_path +
1186
- ". For safety reasons this code does not overwrite existing files.\n Please remove the file at "
1187
- + target_path +
1188
- " and try again." )
1189
- return
1190
- else :
1191
- user_input = input ("""You have indicated you want to copy module:\n """ + my_module
1192
- + """\n to:\n """ + target_path + """\n Is that correct? Please indicate: y / [n]\n \n """ )
1193
- if user_input == 'y' or user_input == 'Y' :
1194
- # print("copy_tree(",my_directory_full_path,",", target_path,")")
1195
- copy_tree (my_directory_full_path , target_path )
1196
- else :
1197
- print ("Goodbye!" )
1198
- return
1199
-
1200
-
1201
- def print_helper ():
1202
-
1203
- my_directory_full_path = os .path .dirname (os .path .realpath (__file__ ))
1204
-
1205
- print (my_directory_full_path )
1206
-
1207
-
1208
- def copy_module_to_local (full_module_name ):
1209
- '''
1210
- This function contains simple code to copy a submodule to a location on
1211
- your hard drive, as specified by you. The purpose of this code is to provide
1212
- users with a simple way to access a *copy* of code that usually sits deep in
1213
- the Econ-ARK package structure, for purposes of tinkering and experimenting
1214
- directly. This is meant to be a simple way to explore HARK code. To interact
1215
- with the codebase under active development, please refer to the documentation
1216
- under github.com/econ-ark/HARK/
1217
-
1218
- To execute, do the following on the Python command line:
1219
-
1220
- from HARK.core import copy_module_to_local
1221
- copy_module_to_local("FULL-HARK-MODULE-NAME-HERE")
1222
-
1223
- For example, if you want SolvingMicroDSOPs you would enter
1224
-
1225
- from HARK.core import copy_module_to_local
1226
- copy_module_to_local("HARK.SolvingMicroDSOPs")
1227
-
1228
- '''
1229
-
1230
- # Find a default directory -- user home directory:
1231
- home_directory_RAW = os .path .expanduser ("~" )
1232
- # Thanks to https://stackoverflow.com/a/4028943
1233
-
1234
- # Find the directory of the HARK.core module:
1235
- # my_directory_full_path = os.path.dirname(os.path.realpath(__file__))
1236
- hark_core_directory_full_path = os .path .dirname (os .path .realpath (__file__ ))
1237
- # From https://stackoverflow.com/a/5137509
1238
- # Important note from that answer:
1239
- # (Note that the incantation above won't work if you've already used os.chdir()
1240
- # to change your current working directory,
1241
- # since the value of the __file__ constant is relative to the current working directory and is not changed by an
1242
- # os.chdir() call.)
1243
- #
1244
- # NOTE: for this specific file that I am testing, the path should be:
1245
- # '/home/npalmer/anaconda3/envs/py3fresh/lib/python3.6/site-packages/HARK/SolvingMicroDSOPs/---example-file---
1246
-
1247
- # Split out the name of the module. Break if proper format is not followed:
1248
- all_module_names_list = full_module_name .split ('.' ) # Assume put in at correct format
1249
- if all_module_names_list [0 ] != "HARK" :
1250
- print ("\n Warning: the module name does not start with 'HARK'. Instead it is: '"
1251
- + all_module_names_list [0 ]+ "' --please format the full namespace of the module you want. \n "
1252
- "For example, 'HARK.SolvingMicroDSOPs'" )
1253
- print ("\n Goodbye!" )
1254
- return
1255
-
1256
- # Construct the pathname to the module to copy:
1257
- my_directory_full_path = hark_core_directory_full_path
1258
- for a_directory_name in all_module_names_list [1 :]:
1259
- my_directory_full_path = os .path .join (my_directory_full_path , a_directory_name )
1260
-
1261
- head_path , my_module = os .path .split (my_directory_full_path )
1262
-
1263
- home_directory_with_module = os .path .join (home_directory_RAW , my_module )
1264
-
1265
- print ("\n \n \n my_directory_full_path:" , my_directory_full_path , '\n \n \n ' )
1266
-
1267
- # Interact with the user:
1268
- # - Ask the user for the target place to copy the directory
1269
- # - Offer use "q/y/other" option
1270
- # - Check if there is something there already
1271
- # - If so, ask if should replace
1272
- # - If not, just copy there
1273
- # - Quit
1274
-
1275
- target_path = input ("""You have invoked the 'replicate' process for the current module:\n """ +
1276
- my_module + """\n The default copy location is your home directory:\n """ +
1277
- home_directory_with_module + """\n Please enter one of the three options in single quotes below, excluding the quotes:
1278
-
1279
- 'q' or return/enter to quit the process
1280
- 'y' to accept the default home directory: """ + home_directory_with_module + """
1281
- 'n' to specify your own pathname\n \n """ )
1282
-
1283
- if target_path == 'n' or target_path == 'N' :
1284
- target_path = input ("""Please enter the full pathname to your target directory location: """ )
1285
-
1286
- # Clean up:
1287
- target_path = os .path .expanduser (target_path )
1288
- target_path = os .path .expandvars (target_path )
1289
- target_path = os .path .normpath (target_path )
1290
-
1291
- # Check to see if they included the module name; if not add it here:
1292
- temp_head , temp_tail = os .path .split (target_path )
1293
- if temp_tail != my_module :
1294
- target_path = os .path .join (target_path , my_module )
1295
-
1296
- elif target_path == 'y' or target_path == 'Y' :
1297
- # Just using the default path:
1298
- target_path = home_directory_with_module
1299
- else :
1300
- # Assume "quit"
1301
- return
1302
-
1303
- if target_path != 'q' and target_path != 'Q' or target_path == '' :
1304
- # Run the copy command:
1305
- copy_module (target_path , my_directory_full_path , my_module )
1306
-
1307
- return
1308
-
1309
- if target_path != 'q' and target_path != 'Q' or target_path == '' :
1310
- # Run the copy command:
1311
- copy_module (target_path , my_directory_full_path , my_module )
1312
-
1313
- return
1314
-
1315
-
1316
- def main ():
1317
- print ("Sorry, HARK.core doesn't actually do anything on its own." )
1318
- print ("To see some examples of its frameworks in action, try running a model module." )
1319
- print ("Several interesting model modules can be found in /ConsumptionSavingModel." )
1320
- print ('For an extraordinarily simple model that demonstrates the "microeconomic" and' )
1321
- print ('"macroeconomic" frameworks, see /FashionVictim/FashionVictimModel.' )
1322
-
1323
-
1324
- if __name__ == '__main__' :
1325
- main ()
0 commit comments