B u `J@s6dZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZddlmZddlmZdd lmZmZdd lmZdd lmZed d gddZedZddZd(ddZddZ ddZ!d)ddZ"dddddej#dfddZ$ddZ%d d!Z&d*d$d%Z'd+d&d'Z(dS),)launch_commandload_external_moduleparse_command_lineN) import_file)TempfileManager)ApplicationError)PauseGC)ConverterError)attempt_import)ExtensionPointSingletonPlugin)PySPConfigBlock)PySPConfiguredObjectz pyutilib.pyropyu_pyro)Z alt_namesz pyomo.pyspcCs4ddl}t|}x|tjkr.t|}qW|S)Nr)uuidstrZuuid4sysmodules)rnamer8/tmp/pip-unpacked-wheel-n62dbgi3/pyomo/pysp/util/misc.py_generate_unique_module_name's   rFc Cszjttj}tjddd}d}|tjkrtj|dk r|}|r|rt}|rjtd|dt|t||d}|rtdq|rtd|dt|dd }|rtdn|rtd|d tj|}n|rt}|rtd |d t|t||d}|rjtdnT|r(td |i}t|||d }t |dksLt t| d}|rjtdWd|tjdd<X||fS)Nr.zModule=z@ is already imported - forcing re-import using unique module id=)rzModule successfully loadedz( is already imported - forcing re-importT) clear_cachez is already imported - skippingzImporting module=z using unique module id=)contextr) listrpathinsertrrprintrrlenAssertionErrorkeys) module_nameuniquerverboseZ original_pathZsys_modules_keyZmodule_to_find_contextrrrr.sV           rcs ddltt|fdddS)Nrcs$t|jjjjr|dStdS)NZextension_precedencez-inf) isinstancepysputilZconfigured_objectZPySPConfiguredExtension get_optionfloat)ext)pyomorrusz/sort_extensions_by_precedence..)key)!pyomo.pysp.util.configured_objecttuplesorted) extensionsr)r-rsort_extensions_by_precedenceqsr4c Csddl}t|}g}xz|D]r}t|\}}|dk s6txTt|tjD]B\}} t| trF|dkrFx&|ddD]} t | | rl| | qlWqFWqWt |S)Nrr T)all) Z pyomo.environr rr!inspect getmembersisclass issubclassr r'appendr1) namesZep_typer-pluginsZactive_pluginsZthis_extensionmodule_robjpluginrrrload_extensions{s     rAc s`ddl}|jjddlm}idk rpxBD]:}t|}x(|ddD]}|g|j j qNWq2Wfdd} t |dk rx2D]*} |d} | dk st | j|kst qW| } | j|d\} } | i}dkr| jrbn^tfdd Dr6| jr6| tdx*D]"}t ||||<q}x(||D]}t|tr|qW |qvW| } | j|d} | x8|D]0}x(||D]}t|tr|qWqW| jr*| tdrXx|D]}t||||<q6W|fSSdS) Nr)_domain_tuple_of_strT)r5cst}tdkrdk s t|dd}|dkr<|d7}|d7}x:D]2}|dt|jd7}|t|d7}qJW||d<tjfd tjd |}| ||j d d d dd dd|S)Nrepilogz zRegistered Extensions: z - z:  F)add_helpformatter_classz-hz--help show_help store_truezshow this help message and exit)destactiondefaulthelp) dictr r!popr__name__argparseArgumentParserRawDescriptionHelpFormatterZinitialize_argparse add_argument)optionsZ_kwdsrCrap)kwdsregistered_extensionswith_extensionsrr_get_argument_parsers(      z0parse_command_line.._get_argument_parser)argsc3s$|]}t|dkVqdS)rN)r getvalue).0r)rUrr sz%parse_command_line..)Zpyomo.pysp.pluginsr(r<loadpyomo.pysp.util.configrBr setdefaultr: __class__ __module__r r\r!Z_domainparse_known_argsZimport_argparserHr5 print_helprexitrAr]r'rZregister_options parse_argsZ set_optionsr4)r[Zregister_options_callbackrYrWr-rBrr<r@rZZ configvalrVoptsr>r3r)rWrUrXrYrrsp                       rrDc  Cstj} t||dkrd}|dkr(i}t|(} d} |dkrly6y ddl} Wntk rlddl} YnXddl} Wn&tk rtddt dYnXzt j dd}| dt t|}| |}|d d ||}|||||d d }|||||||d }||||||t |} Wdt| Xn|rz||f||} Wdt| Xnyy||f||} Wnvt k rtj|d tjttd dYn2tk r<tj|dtjttd dYntk rtj|dtjttd dYntk rtj|dtjttd dYnftk rtj|dtjttd dYn"tk rJtj|dtjttd dYnt k rtj|dtjttd dYnt!k rtj|dtjttd dYn\tj|dt"td krtjttd dn|j#tjdYnXWn(tjdtjdd } YnXWdQRXt$|t%rx|j&ddt| | S)NrrT)shutdownz]Cannot use the 'profile' option: the Python 'profile' or 'pstats' package cannot be imported!z.profile)suffixz'command(options, *cmd_args, **cmd_kwds)timeZ cumulativeZcallsz VALUE ERROR: rrEz KEY ERROR: z TYPE ERROR: z NAME ERROR: z IO ERROR: zCONVERTER ERROR: zAPPLICATION ERROR: zRUN-TIME ERROR: z!Encountered unhandled exception: )filez`To obtain further information regarding the source of the exception, use the --traceback option F)error)'loggerlevelsetLevelrZcProfile ImportErrorprofilepstatsZconfigure_loggers ValueErrorrZcreate_tempfileZrunctxglobalslocalsZStatsZ strip_dirsZ sort_statsZ print_statsZ print_callersZ print_calleesZclear_tempfilesrstderrwriterexc_infoKeyError TypeError NameErrorIOErrorr r RuntimeErrorr print_excr'r Z check_usage)commandrUcmd_argsZcmd_kwdsZ error_labelZ disable_gcZ profile_countZ log_level tracebackZprev_log_levelZpgcrcrsrtZtfiletmpprrrr s                          rcCs"|dkr dS||jrtdS)N)poll returncodeOSError)procrrr_polls rcCs|dkr dS|jdk r |j|jdk r4|jx|jdkry |Wn YnXtjr|jdd|jdkry |Wn YnX|jddq6| |jdkrt dy |Wn YnX| q6WdS)Nr)timeoutg?) stdoutcloserxr terminatesixPY3waitkillrrlsleep)rrrr_kills6            r 127.0.0.1c Cs8tjstjsdSd}tjr*ddd|g}ntjr:d|g}|dg7}d}d}xt|D]}ytj}tdt|dg|}tjr|d t|g7}ntjr|d t|g7}td |t j |t j d }t d t|PWqVtk r*tttdt dt|d}d}YqVXqVW||fS)N)NNz-rz-kz-n z--host=z-xzTrying nameserver with port: Zpyomo_nsz-p z--port= )rz5Failed to find open port - trying again in 20 secondsr)r using_pyro3 using_pyro4ranger)find_unused_portrrjoin subprocessPopenPIPErlrrrrrzr)ns_host num_triesZ ns_optionsns_portZ ns_processicmdrrr_get_test_nameserversB         rc CstjstjsdSd}d}xt|D]}y~tj}tdt|ddt|dt|dt|dt|g}td|t j |t j d }t d t|PWq"tk r}z2tttd t d t|d}d}Wdd}~XYq"Xq"W||fS) N)NNzTrying dispatcher with port: Z dispatch_srvrz--host=z--port=z--daemon-host=z--daemon-port=r)rrz5Failed to find open port - trying again in 20 secondsr)rrrrr)rrrrrrrrlrrrrrzr) rrZdispatcher_hostrZdispatcher_portZdispatcher_processrrerrr_get_test_dispatchers6         r)FFF)N)rr)NNrr))__all__loggingrlrrrr6rQZ pyutilib.miscrZpyomo.common.tempfilesrZpyomo.common.errorsrZpyomo.common.gc_managerrZpyomo.opt.baser Zpyomo.common.dependenciesr Zpyomo.common.pluginr r rar r0rr getLoggerrorrr4rArINFOrrrrrrrrr sP          @ # n   %