U C^D@sddlmZmZddlmZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZd d Zd d Zd dZdddZddZddZddZdS))unicode_literalsprint_function)PathN)msg)path2str) get_data_path)aboutc std4ttj}|jdkr:tjd|jdddW5QRXt d| d}tj }| d dd }||stjd |tjddt }t|D]>\}}|||D]\}}d d |D|||<qqt}t|} dd|D} dd| D} | dd |Dfdd | D} fdd | D} ttjj}tdtj tdt||s| rd}g}| D]\}}|t||tq|D] \}}|t||tdqtj||dntjdd d| rNtdtddtdfdd | Dd| rntdtj d | | rtd!jtt d"| s| rt!"dd#S)$z Validate that the currently installed version of spaCy is compatible with the installed models. Should be run after `pip install -U spacy`. zLoading compatibility table...zServer error ({})z#Couldn't fetch compatibility table.)ZexitszLoaded compatibility tableZspacyz.devrz+Can't find spaCy v{} in compatibility tablecSsg|] }t|qS)reformat_version).0vr r 5/tmp/pip-install-6_kvzl1k/spacy/spacy/cli/validate.py +szvalidate..cSsh|]\}}|ds|qS)compatr )rldr r r .szvalidate..cSs h|]\}}|ds|dqSrnamer r_rr r rr/scSs g|]\}}|ds|dqSrr rr r rr1scsg|]}|kr|qSr r rmcurrent_compatr rr3scsg|]}|kr|qSr r rrr rr4szInstalled models (spaCy v{})zspaCy installation: {})ZTYPENAMEZMODELVERSIONlink)headerz,No models found in your current environment.zInstall updatesz8Use the following commands to update the model packages:zpython -m spacy download {} csg|]}|qSr )format)rpkg)cmdr rrHsz8The following models are not available for spaCy v{}: {}z, zYou may also want to overwrite the incompatible links using the `python -m spacy link` command with `--force`, or remove them from the data directory. Data path: {path})pathN)#rZloadingrequestsgetr Z__compatibility__ status_codefailr$goodjson __version__rsplitsetdictitemsupdatekeysget_model_linksget_model_pkgsr__file__parentdividerinforappend get_model_rowtabletextprintjoinrsysexit)rrversion all_modelsZspacy_vmodelsmodelZmodel_vsZ model_linksZ model_pkgsZincompat_linksZincompat_modelsZ na_modelsZ update_modelsZ spacy_dirr"Zrowsrdatar )r&rrvalidates              rIc Csi}t}|rdd|D}|D]b}t|d}|s>q$t|}|jd}|dd|d}||dt|||dd ||<q$|S) NcSsg|]}t|r|qSr ) is_model_path)rpr r rr]sz#get_model_links..z meta.jsonlangrrrDrrDr)riterdirrexistssrsly read_jsonparts is_compat) rlinksZ data_pathrFrG meta_pathmetar!rr r rr5Ys     r5cCsXddl}i}|jjD]:\}}|dd}||kr|j}||t|||d||<q|S)Nr-rrN) pkg_resources working_setby_keyr2replacerDrT)rrErYpkgspkg_nameZpkg_datapackagerDr r rr6ms  r6r_cCsr|dr0|jddddd}|j|dddd}n0|j|dd dd}d ||d d gd }|||d ||fS)Nrr Zgreenr,T)colorZiconno_printrD)r`raZredz--> {}rzn/ar)r>r$r))rrrHrZ model_typecomprDr r rr<}s r<cCs0dddg}|jd}|o.||ko.|d S)Ncachepycache __pycache__rL.)rSis_dir startswith)Z model_pathexcluderr r rrJs  rJcCs||ko|||kS)Nr )rrrDr r rrTsrTcCs"|dr|ddS|ddS)zEHack to reformat old versions ending on '-alpha' to match pip format.z-alphaZa0a)endswithr\)rDr r rr s  r )r_) __future__rrpathlibrrAr(rQZwasabirrrutilrr r rIr5r6r<rJrTr r r r rs     J