@@ -151,7 +151,7 @@ def install_model(self) -> SCAProcedureResult:
151151 "-m" ,
152152 "pip" ,
153153 "install" ,
154- "https://master.dl.sourceforge.net/project/en-core-web-sm/en_core_web_sm-3.6 .0-py3-none-any.whl?viasf=1" ,
154+ "https://master.dl.sourceforge.net/project/en-core-web-sm/en_core_web_sm-3.7 .0-py3-none-any.whl?viasf=1" ,
155155 ]
156156 else :
157157 command = [sys .executable , "-m" , "spacy" , "download" , "en_core_web_sm" ]
@@ -164,44 +164,83 @@ def install_model(self) -> SCAProcedureResult:
164164 return True , None
165165
166166 def check_spacy_and_model (self ) -> SCAProcedureResult :
167+ required_version_prefix = "3.7."
168+ required_version_range = ">=3.7.0,<3.8.0"
169+ ask_install_spacy = False
170+ ask_install_model = False
171+
167172 try :
168173 logging .info ("Trying to load spaCy..." )
169174 import spacy # type: ignore # noqa: F401 'spacy' imported but unused
175+
170176 except ModuleNotFoundError :
171- is_install = get_yes_or_no (
172- "Running LCA requires spaCy. Do you want me to install it for you?"
173- )
174- if not is_install :
175- return (
176- False ,
177- (
178- "\n spaCy installation is refused. You need to manually install it using:"
179- "\n pip install spacy"
180- ),
181- )
182- return self .install_spacy ()
177+ ask_install_spacy = True
183178 else :
184- color_print ("OKGREEN" , "ok" , prefix = "spaCy has already been installed. " )
179+ spacy_version = spacy .__version__
180+ if not spacy_version .startswith (required_version_prefix ):
181+ logging .info (
182+ f"The installed version { spacy_version } of spaCy does not match the version"
183+ f" required by NeoSCA: { required_version_range } "
184+ )
185+ ask_install_spacy = True
186+ else :
187+ color_print (
188+ "OKGREEN" ,
189+ "ok" ,
190+ prefix = f"spaCy{ required_version_range } has already been installed. " ,
191+ )
185192
186193 try :
187194 logging .info ("Trying to load en_core_web_sm..." )
188195 import en_core_web_sm # type: ignore # noqa: F401 'en_core_web_sm' imported but unused
189196 except ModuleNotFoundError :
197+ ask_install_model = True
198+ else :
199+ model_version = en_core_web_sm .__version__
200+ if not model_version .startswith (required_version_prefix ):
201+ logging .info (
202+ f"The installed version { model_version } of en_core_web_sm does not match the"
203+ f" version required by NeoSCA: { required_version_range } "
204+ )
205+ ask_install_model = True
206+ else :
207+ color_print (
208+ "OKGREEN" ,
209+ "ok" ,
210+ prefix = (
211+ f"en_core_web_sm{ required_version_range } has already been installed. "
212+ ),
213+ )
214+
215+ if ask_install_spacy :
216+ is_install = get_yes_or_no (
217+ f"\n Running LCA requires spaCy{ required_version_range } , do you want me to"
218+ " install/update it for you?"
219+ )
220+ if is_install :
221+ return self .install_spacy ()
222+ else :
223+ return (
224+ False ,
225+ "\n You need to manually install it using:\n pip install -U spacy" ,
226+ )
227+ if ask_install_model :
190228 is_install = get_yes_or_no (
191- "Running LCA requires spaCy's en_core_web_sm model. Do you want me to install it for you?"
229+ f"\n Running LCA requires spaCy's model en_core_web_sm{ required_version_range } ,"
230+ " do you want me to install it for you?"
192231 )
193- if not is_install :
232+ if is_install :
233+ return self .install_model ()
234+ else :
194235 return (
195236 False ,
196237 (
197- "\n en_core_web_sm installation is refused. You need to manually install it using:"
238+ "\n You need to manually install it using:"
198239 "\n python -m spacy download en_core_web_sm"
199240 ),
200241 )
201- return self .install_model ()
202- else :
203- color_print ("OKGREEN" , "ok" , prefix = "en_core_web_sm has already been installed. " )
204- return True , None
242+
243+ return True , None
205244
206245 def exit_routine (self ) -> None :
207246 if self .options .is_quiet or self .options .is_stdout :
0 commit comments