|
1 | 1 | import contextlib |
2 | 2 | import functools |
3 | 3 | import importlib |
4 | | -import inspect |
5 | 4 | import os |
6 | 5 | import re |
7 | 6 | import shutil |
|
10 | 9 | import sysconfig |
11 | 10 | import warnings |
12 | 11 | from enum import Enum |
| 12 | +from inspect import Parameter, signature |
13 | 13 | from pathlib import Path |
14 | 14 | from types import FunctionType |
15 | 15 | from typing import ( |
@@ -105,7 +105,7 @@ def __init__( |
105 | 105 | vocab_config: Type[BaseDefaults] = None, |
106 | 106 | meta: Dict[str, Any] = None, |
107 | 107 | pipeline: Optional[Sequence[str]] = None, |
108 | | - components: Dict[str, CurriedFactory] = {}, |
| 108 | + components: Dict[str, Any] = {}, |
109 | 109 | disable: AsList[str] = EMPTY_LIST, |
110 | 110 | enable: AsList[str] = EMPTY_LIST, |
111 | 111 | exclude: AsList = EMPTY_LIST, |
@@ -232,17 +232,18 @@ def create_pipe( |
232 | 232 | Pipe |
233 | 233 | """ |
234 | 234 | try: |
235 | | - curried: CurriedFactory = Config( |
| 235 | + pipe = Config( |
236 | 236 | { |
237 | 237 | "@factory": factory, |
238 | 238 | **(config if config is not None else {}), |
239 | 239 | } |
240 | 240 | ).resolve(registry=registry) |
241 | | - if name is None: |
242 | | - name = inspect.signature(curried.factory).parameters.get("name").default |
243 | | - if name is None or name == inspect.Parameter.empty: |
244 | | - name = factory |
245 | | - pipe = curried.instantiate(nlp=self, path=(name,)) |
| 241 | + if isinstance(pipe, CurriedFactory): |
| 242 | + if name is None: |
| 243 | + name = signature(pipe.factory).parameters.get("name").default |
| 244 | + if name is None or name == Parameter.empty: |
| 245 | + name = factory |
| 246 | + pipe = pipe.instantiate(nlp=self, path=(name,)) |
246 | 247 | except ConfitValidationError as e: |
247 | 248 | raise e.with_traceback(None) |
248 | 249 | return pipe |
@@ -413,8 +414,8 @@ def pipe( |
413 | 414 | inputs: Iterable[Union[str, Doc]] |
414 | 415 | The inputs to create the Docs from, or Docs directly. |
415 | 416 | n_process: int |
416 | | - Deprecated. Use the ".set(num_cpu_workers=n_process)" method on the returned |
417 | | - data stream instead. |
| 417 | + Deprecated. Use the ".set_processing(num_cpu_workers=n_process)" method |
| 418 | + on the returned data stream instead. |
418 | 419 | The number of parallel workers to use. If 0, the operations will be |
419 | 420 | executed sequentially. |
420 | 421 |
|
@@ -589,16 +590,6 @@ def _add_pipes( |
589 | 590 | enable: Container[str], |
590 | 591 | disable: Container[str], |
591 | 592 | ): |
592 | | - # Since components are actually resolved as curried factories, |
593 | | - # we need to instantiate them here |
594 | | - for name, component in components.items(): |
595 | | - if not isinstance(component, CurriedFactory): |
596 | | - raise ValueError( |
597 | | - f"Component {repr(name)} is not instantiable (got {component}). " |
598 | | - f"Please make sure that you didn't forget to add a '@factory' " |
599 | | - f"key to the component config." |
600 | | - ) |
601 | | - |
602 | 593 | try: |
603 | 594 | components = CurriedFactory.instantiate(components, nlp=self) |
604 | 595 | except ConfitValidationError as e: |
@@ -1215,7 +1206,7 @@ def load( |
1215 | 1206 | elif is_package: |
1216 | 1207 | # Load as package |
1217 | 1208 | available_kwargs = {"overrides": overrides, **pipe_selection} |
1218 | | - signature_kwargs = inspect.signature(module.load).parameters |
| 1209 | + signature_kwargs = signature(module.load).parameters |
1219 | 1210 | kwargs = { |
1220 | 1211 | name: available_kwargs[name] |
1221 | 1212 | for name in signature_kwargs |
|
0 commit comments