1+ import importlib .metadata as importlib_metadata
12import inspect
23import types
34from contextlib import contextmanager
1718from weakref import WeakKeyDictionary
1819
1920import catalogue
21+ import confit
2022import spacy
21- from confit import Config , Registry , RegistryCollection , set_default_registry
23+ import spacy .registrations
24+ from confit import Config , RegistryCollection , set_default_registry
2225from confit .errors import ConfitValidationError , patch_errors
2326from confit .registry import Draft
2427from spacy .pipe_analysis import validate_attrs
28+ from spacy .pipeline .factories import register_factories
2529
2630import edsnlp
2731from edsnlp .utils .collections import FrozenDict , FrozenList
2832
29- try :
30- import importlib .metadata as importlib_metadata
31- except ImportError :
32- import importlib_metadata
33-
3433PIPE_META = WeakKeyDictionary ()
3534
3635
@@ -75,6 +74,13 @@ class FactoryMeta:
7574_AUTO_INSTANTIATE_COMPLETE_PIPE_DRAFT = True
7675
7776
77+ class Registry (confit .Registry ):
78+ def get (self , name : str ) -> Any :
79+ if name .startswith ("spacy." ):
80+ spacy .registrations .populate_registry ()
81+ return super ().get (name )
82+
83+
7884class DraftPipe (Draft [T ]):
7985 def __init__ (self , func , kwargs ):
8086 super ().__init__ (func , kwargs )
@@ -277,10 +283,15 @@ def get(self, name: str) -> Any:
277283 registry_path = list (self .namespace ) + [name ]
278284 registry_spacy_path = ["spacy" , "factories" , name ]
279285 registry_internal_spacy_path = ["spacy" , "internal_factories" , name ]
286+ registry_legacy_spacy_path = ["spacy-legacy" , "factories" , name ]
280287
281288 def check_and_return ():
282289 if not catalogue .check_exists (* registry_path ):
283- for path in (registry_spacy_path , registry_internal_spacy_path ):
290+ for path in (
291+ registry_spacy_path ,
292+ registry_internal_spacy_path ,
293+ registry_legacy_spacy_path ,
294+ ):
284295 if catalogue .check_exists (* path ):
285296 func = catalogue ._get (path )
286297 meta = spacy .Language .get_factory_meta (name )
@@ -301,14 +312,14 @@ def check_and_return():
301312 # Steps 1 & 2
302313 func = check_and_return ()
303314 if func is None and self .entry_points :
315+ register_factories ()
304316 # Update entry points in case packages lookup paths have changed
305317 catalogue .AVAILABLE_ENTRY_POINTS = importlib_metadata .entry_points ()
306318 # Otherwise, step 3
307319 self .get_entry_point (name )
308320 # Then redo steps 1 & 2
309321 func = check_and_return ()
310322 if func is None :
311- # Otherwise, step 4
312323 if hasattr (spacy .registry , "_entry_point_factories" ):
313324 spacy .registry ._entry_point_factories .get_entry_point (name )
314325 # Then redo steps 1 & 2
0 commit comments