pico-ioc 0.6.0__py3-none-any.whl → 1.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pico_ioc/resolver.py CHANGED
@@ -1,58 +1,110 @@
1
- # pico_ioc/resolver.py
1
+ # pico_ioc/resolver.py (Python 3.10+)
2
2
 
3
+ from __future__ import annotations
3
4
  import inspect
4
- from typing import Any, Dict, Optional
5
- from .container import PicoContainer
6
- from .typing_utils import evaluated_hints, resolve_annotation_to_type
7
- from ._state import _resolving
5
+ from typing import Any, Annotated, get_args, get_origin, get_type_hints
6
+
7
+
8
+ def _get_hints(obj, owner_cls=None) -> dict:
9
+ """type hints with include_extras=True and correct globals/locals."""
10
+ mod = inspect.getmodule(obj)
11
+ g = getattr(mod, "__dict__", {})
12
+ l = vars(owner_cls) if owner_cls is not None else None
13
+ return get_type_hints(obj, globalns=g, localns=l, include_extras=True)
14
+
15
+
16
+ def _is_collection_hint(tp) -> bool:
17
+ """True if tp is a list[...] or tuple[...]."""
18
+ origin = get_origin(tp) or tp
19
+ return origin in (list, tuple)
20
+
21
+
22
+ def _base_and_qualifiers_from_hint(tp):
23
+ """
24
+ Extract (base, qualifiers, container_kind) from a collection hint.
25
+ Supports list[T] / tuple[T] and Annotated[T, "qual1", ...].
26
+ """
27
+ origin = get_origin(tp) or tp
28
+ args = get_args(tp) or ()
29
+ container_kind = list if origin is list else tuple
30
+
31
+ if not args:
32
+ return (object, (), container_kind)
33
+
34
+ inner = args[0]
35
+ if get_origin(inner) is Annotated:
36
+ base, *extras = get_args(inner)
37
+ quals = tuple(a for a in extras if isinstance(a, str))
38
+ return (base, quals, container_kind)
39
+
40
+ return (inner, (), container_kind)
41
+
8
42
 
9
43
  class Resolver:
10
- def __init__(self, container: PicoContainer):
44
+ def __init__(self, container, *, prefer_name_first: bool = True):
11
45
  self.c = container
46
+ self._prefer_name_first = bool(prefer_name_first)
12
47
 
13
- def _resolve_by_mro(self, ann) -> Optional[Any]:
14
- try:
15
- for base in getattr(ann, "__mro__", ())[1:]:
16
- if base is object: break
17
- if self.c.has(base): return self.c.get(base)
18
- except Exception:
19
- pass
20
- return None
21
-
22
- def _resolve_param(self, name: str, ann) -> Any:
23
- if self.c.has(name): return self.c.get(name)
24
- if ann is not inspect._empty and self.c.has(ann): return self.c.get(ann)
25
- if ann is not inspect._empty:
26
- mro_hit = self._resolve_by_mro(ann)
27
- if mro_hit is not None: return mro_hit
28
- if self.c.has(str(name)): return self.c.get(str(name))
29
- key = name if ann is inspect._empty else ann
30
- return self.c.get(key)
31
-
32
- def kwargs_for_callable(self, fn, owner_cls=None) -> Dict[str, Any]:
33
- sig = inspect.signature(fn)
34
- hints = evaluated_hints(fn, owner_cls=owner_cls)
35
- deps: Dict[str, Any] = {}
48
+ def create_instance(self, cls):
49
+ sig = inspect.signature(cls.__init__)
50
+ hints = _get_hints(cls.__init__, owner_cls=cls)
51
+ kwargs = {}
52
+ for name, param in sig.parameters.items():
53
+ if name == "self":
54
+ continue
55
+ if param.kind in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD):
56
+ continue
57
+ ann = hints.get(name, param.annotation)
58
+ try:
59
+ value = self._resolve_param(name, ann)
60
+ except NameError:
61
+ if param.default is not inspect._empty:
62
+ continue
63
+ raise
64
+ kwargs[name] = value
65
+ return cls(**kwargs)
36
66
 
37
- tok = _resolving.set(True)
38
- try:
39
- for p in sig.parameters.values():
40
- if p.name == "self" or p.kind in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD):
67
+ def kwargs_for_callable(self, fn, *, owner_cls=None):
68
+ sig = inspect.signature(fn)
69
+ hints = _get_hints(fn, owner_cls=owner_cls)
70
+ kwargs = {}
71
+ for name, param in sig.parameters.items():
72
+ if name == "self":
73
+ continue
74
+ if param.kind in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD):
75
+ continue
76
+ ann = hints.get(name, param.annotation)
77
+ try:
78
+ value = self._resolve_param(name, ann)
79
+ except NameError:
80
+ if param.default is not inspect._empty:
41
81
  continue
42
- raw_ann = hints.get(p.name, p.annotation)
43
- ann = resolve_annotation_to_type(raw_ann, fn, owner_cls)
44
- try:
45
- deps[p.name] = self._resolve_param(p.name, ann)
46
- except NameError:
47
- if p.default is not inspect._empty:
48
- continue
49
- missing = ann if ann is not inspect._empty else p.name
50
- raise NameError(f"No provider found for key: {missing}")
51
- return deps
52
- finally:
53
- _resolving.reset(tok)
54
-
55
- def create_instance(self, cls: type) -> Any:
56
- kw = self.kwargs_for_callable(cls.__init__, owner_cls=cls)
57
- return cls(**kw)
82
+ raise
83
+ kwargs[name] = value
84
+ return kwargs
85
+
86
+ def _resolve_param(self, name: str, ann: Any):
87
+ # collections (list/tuple) with optional qualifiers via Annotated
88
+ if _is_collection_hint(ann):
89
+ base, quals, container_kind = _base_and_qualifiers_from_hint(ann)
90
+ items = self.c._resolve_all_for_base(base, qualifiers=quals)
91
+ return list(items) if container_kind is list else tuple(items)
92
+
93
+ # precedence: by name > by exact annotation > by MRO > by name again
94
+ if self._prefer_name_first and self.c.has(name):
95
+ return self.c.get(name)
96
+
97
+ if ann is not inspect._empty and self.c.has(ann):
98
+ return self.c.get(ann)
99
+
100
+ if ann is not inspect._empty and isinstance(ann, type):
101
+ for base in ann.__mro__[1:]:
102
+ if self.c.has(base):
103
+ return self.c.get(base)
104
+
105
+ if self.c.has(name):
106
+ return self.c.get(name)
107
+
108
+ missing = ann if ann is not inspect._empty else name
109
+ raise NameError(f"No provider found for key {missing!r}")
58
110
 
pico_ioc/scanner.py CHANGED
@@ -1,8 +1,10 @@
1
+ # pico_ioc/scanner.py
1
2
  import importlib
2
3
  import inspect
3
4
  import logging
4
5
  import pkgutil
5
- from typing import Any, Callable, Optional, Tuple, List
6
+ from types import ModuleType
7
+ from typing import Any, Callable, Optional, Tuple, List, Iterable
6
8
 
7
9
  from .container import PicoContainer, Binder
8
10
  from .decorators import (
@@ -16,6 +18,7 @@ from .decorators import (
16
18
  from .proxy import ComponentProxy
17
19
  from .resolver import Resolver
18
20
  from .plugins import PicoPlugin
21
+ from . import _state
19
22
 
20
23
 
21
24
  def scan_and_configure(
@@ -24,82 +27,212 @@ def scan_and_configure(
24
27
  *,
25
28
  exclude: Optional[Callable[[str], bool]] = None,
26
29
  plugins: Tuple[PicoPlugin, ...] = (),
27
- ):
28
- package = importlib.import_module(package_or_name) if isinstance(package_or_name, str) else package_or_name
29
- logging.info(f"Scanning in '{package.__name__}'...")
30
+ ) -> None:
31
+ """
32
+ Scan a package, discover component classes/factories, and bind them into the container.
33
+
34
+ Args:
35
+ package_or_name: Package module or importable package name (str).
36
+ container: Target PicoContainer to receive bindings.
37
+ exclude: Optional predicate that receives a module name and returns True to skip it.
38
+ plugins: Optional lifecycle plugins that receive scan/bind events.
39
+ """
40
+ package = _as_module(package_or_name)
41
+ logging.info("Scanning in '%s'...", getattr(package, "__name__", repr(package)))
42
+
30
43
  binder = Binder(container)
31
44
  resolver = Resolver(container)
32
45
 
46
+ _run_plugin_hook(plugins, "before_scan", package, binder)
47
+
48
+ comp_classes, factory_classes = _collect_decorated_classes(
49
+ package=package,
50
+ exclude=exclude,
51
+ plugins=plugins,
52
+ binder=binder,
53
+ )
54
+
55
+ _run_plugin_hook(plugins, "after_scan", package, binder)
56
+
57
+ _register_component_classes(
58
+ classes=comp_classes,
59
+ container=container,
60
+ resolver=resolver,
61
+ )
62
+
63
+ _register_factory_classes(
64
+ factory_classes=factory_classes,
65
+ container=container,
66
+ resolver=resolver,
67
+ )
68
+
69
+
70
+ # -------------------- Helpers (private) --------------------
71
+
72
+ def _as_module(package_or_name: Any) -> ModuleType:
73
+ """Return a module from either a module object or an importable string name."""
74
+ if isinstance(package_or_name, str):
75
+ return importlib.import_module(package_or_name)
76
+ if hasattr(package_or_name, "__spec__"):
77
+ return package_or_name # type: ignore[return-value]
78
+ raise TypeError("package_or_name must be a module or importable package name (str).")
79
+
80
+
81
+ def _run_plugin_hook(
82
+ plugins: Tuple[PicoPlugin, ...],
83
+ hook_name: str,
84
+ *args,
85
+ **kwargs,
86
+ ) -> None:
87
+ """Run a lifecycle hook across all plugins, logging (but not raising) exceptions."""
33
88
  for pl in plugins:
34
89
  try:
35
- getattr(pl, "before_scan", lambda *a, **k: None)(package, binder)
90
+ fn = getattr(pl, hook_name, None)
91
+ if fn:
92
+ fn(*args, **kwargs)
36
93
  except Exception:
37
- logging.exception("Plugin before_scan failed")
94
+ logging.exception("Plugin %s failed", hook_name)
95
+
96
+
97
+ def _iter_package_modules(
98
+ package: ModuleType,
99
+ ) -> Iterable[str]:
100
+ """
101
+ Yield fully qualified module names under the given package.
102
+
103
+ Requires the package to have a __path__ (i.e., be a package, not a single module).
104
+ """
105
+ try:
106
+ pkg_path = package.__path__ # type: ignore[attr-defined]
107
+ except Exception:
108
+ return # not a package; nothing to iterate
38
109
 
110
+ prefix = package.__name__ + "."
111
+ for _finder, name, _is_pkg in pkgutil.walk_packages(pkg_path, prefix):
112
+ yield name
113
+
114
+
115
+ def _collect_decorated_classes(
116
+ *,
117
+ package: ModuleType,
118
+ exclude: Optional[Callable[[str], bool]],
119
+ plugins: Tuple[PicoPlugin, ...],
120
+ binder: Binder,
121
+ ) -> Tuple[List[type], List[type]]:
122
+ """
123
+ Import modules under `package`, visit classes, and collect those marked with
124
+ @component or @factory_component decorators.
125
+ """
39
126
  comp_classes: List[type] = []
40
127
  factory_classes: List[type] = []
41
128
 
42
- for _, name, _ in pkgutil.walk_packages(package.__path__, package.__name__ + "."):
43
- if exclude and exclude(name):
44
- logging.info(f"Skipping module {name} (excluded)")
129
+ def _visit_module(module: ModuleType):
130
+ for _name, obj in inspect.getmembers(module, inspect.isclass):
131
+ # Allow plugins to inspect/transform/record classes
132
+ _run_plugin_hook(plugins, "visit_class", module, obj, binder)
133
+
134
+ # Collect decorated classes
135
+ if getattr(obj, COMPONENT_FLAG, False):
136
+ comp_classes.append(obj)
137
+ elif getattr(obj, FACTORY_FLAG, False):
138
+ factory_classes.append(obj)
139
+
140
+ # 1) Si es un paquete, recorrer submódulos
141
+ for mod_name in _iter_package_modules(package):
142
+ if exclude and exclude(mod_name):
143
+ logging.info("Skipping module %s (excluded)", mod_name)
45
144
  continue
145
+
46
146
  try:
47
- module = importlib.import_module(name)
48
- for _, obj in inspect.getmembers(module, inspect.isclass):
49
- for pl in plugins:
50
- try:
51
- getattr(pl, "visit_class", lambda *a, **k: None)(module, obj, binder)
52
- except Exception:
53
- logging.exception("Plugin visit_class failed")
54
- if getattr(obj, COMPONENT_FLAG, False):
55
- comp_classes.append(obj)
56
- elif getattr(obj, FACTORY_FLAG, False):
57
- factory_classes.append(obj)
147
+ module = importlib.import_module(mod_name)
58
148
  except Exception as e:
59
- logging.warning(f"Module {name} not processed: {e}")
149
+ logging.warning("Module %s not processed: %s", mod_name, e)
150
+ continue
60
151
 
61
- for pl in plugins:
62
- try:
63
- getattr(pl, "after_scan", lambda *a, **k: None)(package, binder)
64
- except Exception:
65
- logging.exception("Plugin after_scan failed")
152
+ _visit_module(module)
153
+
154
+ # 2) Si el “paquete” raíz es un módulo (sin __path__), también hay que visitarlo.
155
+ if not hasattr(package, "__path__"):
156
+ _visit_module(package)
66
157
 
67
- # Register @component classes (bind ONLY by declared key)
68
- for cls in comp_classes:
158
+ return comp_classes, factory_classes
159
+
160
+
161
+ def _register_component_classes(
162
+ *,
163
+ classes: List[type],
164
+ container: PicoContainer,
165
+ resolver: Resolver,
166
+ ) -> None:
167
+ """
168
+ Register @component classes into the container.
169
+
170
+ Binding key:
171
+ - If the class has COMPONENT_KEY, use it; otherwise, bind by the class itself.
172
+ Laziness:
173
+ - If COMPONENT_LAZY is True, provide a proxy that defers instantiation.
174
+ """
175
+ for cls in classes:
69
176
  key = getattr(cls, COMPONENT_KEY, cls)
70
177
  is_lazy = bool(getattr(cls, COMPONENT_LAZY, False))
71
178
 
72
- def provider_factory(c=cls, lazy=is_lazy):
179
+ def _provider_factory(c=cls, lazy=is_lazy):
73
180
  def _factory():
74
181
  if lazy:
75
182
  return ComponentProxy(lambda: resolver.create_instance(c))
76
183
  return resolver.create_instance(c)
77
184
  return _factory
78
185
 
79
- container.bind(key, provider_factory(), lazy=is_lazy)
186
+ container.bind(key, _provider_factory(), lazy=is_lazy)
80
187
 
81
- # Register @factory_component methods marked with @provides
188
+
189
+ def _register_factory_classes(
190
+ *,
191
+ factory_classes: List[type],
192
+ container: PicoContainer,
193
+ resolver: Resolver,
194
+ ) -> None:
195
+ """
196
+ Register products of @factory_component classes.
197
+
198
+ For each factory class:
199
+ - Instantiate the factory via the resolver.
200
+ - For each method with @provides:
201
+ - Bind the provided key to a callable that calls the factory method.
202
+ - If PROVIDES_LAZY is True, bind a proxy that defers the method call.
203
+ """
82
204
  for fcls in factory_classes:
83
205
  try:
84
- finst = resolver.create_instance(fcls)
85
- for name, func in inspect.getmembers(fcls, predicate=inspect.isfunction):
86
- pk = getattr(func, PROVIDES_KEY, None)
87
- if pk is None:
88
- continue
89
- is_lazy = bool(getattr(func, PROVIDES_LAZY, False))
90
- bound = getattr(finst, name, func.__get__(finst, fcls))
206
+ # Durante el escaneo, permitir la resolución de dependencias de la factory
207
+ # elevando temporalmente el flag `_resolving` para no chocar con la guardia.
208
+ tok_res = _state._resolving.set(True)
209
+ try:
210
+ finst = resolver.create_instance(fcls)
211
+ finally:
212
+ _state._resolving.reset(tok_res)
213
+ except Exception:
214
+ logging.exception("Error in factory %s", fcls.__name__)
215
+ continue
91
216
 
92
- def make_provider(m=bound, lazy=is_lazy):
93
- def _factory():
94
- kwargs = resolver.kwargs_for_callable(m, owner_cls=fcls)
217
+ for attr_name, func in inspect.getmembers(fcls, predicate=inspect.isfunction):
218
+ provided_key = getattr(func, PROVIDES_KEY, None)
219
+ if provided_key is None:
220
+ continue
95
221
 
96
- def _call():
97
- return m(**kwargs)
222
+ is_lazy = bool(getattr(func, PROVIDES_LAZY, False))
223
+ # `bound` is the bound method on the instance (so it has `self`)
224
+ bound = getattr(finst, attr_name, func.__get__(finst, fcls))
98
225
 
99
- return ComponentProxy(lambda: _call()) if lazy else _call()
100
- return _factory
226
+ def _make_provider(m=bound, owner=fcls, lazy=is_lazy):
227
+ def _factory():
228
+ # Compute kwargs at call time to ensure up-to-date dependency resolution
229
+ kwargs = resolver.kwargs_for_callable(m, owner_cls=owner)
101
230
 
102
- container.bind(pk, make_provider(), lazy=is_lazy)
103
- except Exception:
104
- logging.exception(f"Error in factory {fcls.__name__}")
231
+ def _call():
232
+ return m(**kwargs)
233
+
234
+ return ComponentProxy(lambda: _call()) if lazy else _call()
235
+ return _factory
236
+
237
+ container.bind(provided_key, _make_provider(), lazy=is_lazy)
105
238
 
pico_ioc/typing_utils.py CHANGED
@@ -1,23 +1,28 @@
1
1
  # pico_ioc/typing_utils.py
2
2
 
3
- import sys, typing
3
+ import sys
4
+ import typing
5
+
4
6
 
5
7
  def evaluated_hints(func, owner_cls=None) -> dict:
8
+ """Return type hints; swallow any error and return {}."""
6
9
  try:
7
10
  module = sys.modules.get(func.__module__)
8
11
  globalns = getattr(module, "__dict__", {})
9
- localns = vars(owner_cls) if owner_cls is not None else {}
10
- return typing.get_type_hints(func, globalns=globalns, localns=localns)
12
+ localns = vars(owner_cls) if owner_cls is not None else None
13
+ return typing.get_type_hints(func, globalns=globalns, localns=localns, include_extras=True)
11
14
  except Exception:
12
15
  return {}
13
16
 
17
+
14
18
  def resolve_annotation_to_type(ann, func, owner_cls=None):
19
+ """Best-effort evaluation of a string annotation; return original on failure."""
15
20
  if not isinstance(ann, str):
16
21
  return ann
17
22
  try:
18
23
  module = sys.modules.get(func.__module__)
19
24
  globalns = getattr(module, "__dict__", {})
20
- localns = vars(owner_cls) if owner_cls is not None else {}
25
+ localns = vars(owner_cls) if owner_cls is not None else None
21
26
  return eval(ann, globalns, localns)
22
27
  except Exception:
23
28
  return ann
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.4
2
+ Name: pico-ioc
3
+ Version: 1.1.0
4
+ Summary: A minimalist, zero-dependency Inversion of Control (IoC) container for Python.
5
+ Author-email: David Perez Cabrera <dperezcabrera@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 David Pérez Cabrera
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/dperezcabrera/pico-ioc
29
+ Project-URL: Repository, https://github.com/dperezcabrera/pico-ioc
30
+ Project-URL: Issue Tracker, https://github.com/dperezcabrera/pico-ioc/issues
31
+ Keywords: ioc,di,dependency injection,inversion of control,decorator
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Programming Language :: Python :: 3 :: Only
35
+ Classifier: Programming Language :: Python :: 3.10
36
+ Classifier: Programming Language :: Python :: 3.11
37
+ Classifier: Programming Language :: Python :: 3.12
38
+ Classifier: Programming Language :: Python :: 3.13
39
+ Classifier: License :: OSI Approved :: MIT License
40
+ Classifier: Operating System :: OS Independent
41
+ Requires-Python: >=3.8
42
+ Description-Content-Type: text/markdown
43
+ License-File: LICENSE
44
+ Dynamic: license-file
45
+
46
+ # 📦 Pico-IoC: A Minimalist IoC Container for Python
47
+
48
+ [![PyPI](https://img.shields.io/pypi/v/pico-ioc.svg)](https://pypi.org/project/pico-ioc/)
49
+ [![DeepWiki](https://img.shields.io/badge/docs-DeepWiki-blue)](https://deepwiki.com/dperezcabrera/pico-ioc)
50
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
51
+ ![CI (tox matrix)](https://github.com/dperezcabrera/pico-ioc/actions/workflows/ci.yml/badge.svg)
52
+ [![codecov](https://codecov.io/gh/dperezcabrera/pico-ioc/branch/main/graph/badge.svg)](https://codecov.io/gh/dperezcabrera/pico-ioc)
53
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=dperezcabrera_pico-ioc&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-ioc)
54
+ [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=dperezcabrera_pico-ioc&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-ioc)
55
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=dperezcabrera_pico-ioc&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-ioc)
56
+
57
+ **pico-ioc** is a **tiny, zero-dependency, decorator-based IoC container for Python**.
58
+ It helps you build loosely-coupled, testable apps without manual wiring. Inspired by the Spring ecosystem, but minimal.
59
+
60
+ > ⚠️ **Requires Python 3.10+** (uses `typing.Annotated` and `include_extras=True`).
61
+
62
+ ---
63
+
64
+ ## ✨ Features
65
+
66
+ - **Zero dependencies** — pure Python, framework-agnostic.
67
+ - **Decorator API** — `@component`, `@factory_component`, `@provides`, `@plugin`.
68
+ - **Fail-fast bootstrap** — eager by default; missing deps surface at startup.
69
+ - **Opt-in lazy** — `lazy=True` wraps with `ComponentProxy`.
70
+ - **Smart resolution order** — parameter name → type annotation → MRO → string.
71
+ - **Qualifiers & collections** — `list[Annotated[T, Q]]` filters by qualifier.
72
+ - **Plugins** — lifecycle hooks (`before_scan`, `after_ready`).
73
+ - **Public API helper** — auto-export decorated symbols in `__init__.py`.
74
+ - **Thread/async safe** — isolation via `ContextVar`.
75
+ - **Overrides for testing** — inject mocks/fakes directly via `init(overrides={...})`.
76
+
77
+ ---
78
+
79
+ ## 📦 Installation
80
+
81
+ ```bash
82
+ # Requires Python 3.10+
83
+ pip install pico-ioc
84
+ ````
85
+
86
+ ---
87
+
88
+ ## 🚀 Quick start
89
+
90
+ ```python
91
+ from pico_ioc import component, init
92
+
93
+ @component
94
+ class Config:
95
+ url = "sqlite:///demo.db"
96
+
97
+ @component
98
+ class Repo:
99
+ def __init__(self, cfg: Config):
100
+ self.url = cfg.url
101
+ def fetch(self): return f"fetching from {self.url}"
102
+
103
+ @component
104
+ class Service:
105
+ def __init__(self, repo: Repo):
106
+ self.repo = repo
107
+ def run(self): return self.repo.fetch()
108
+
109
+ # bootstrap
110
+ import myapp
111
+ c = init(myapp)
112
+ svc = c.get(Service)
113
+ print(svc.run())
114
+ ```
115
+
116
+ **Output:**
117
+
118
+ ```
119
+ fetching from sqlite:///demo.db
120
+ ```
121
+ ---
122
+
123
+ ### Quick overrides for testing
124
+
125
+ ```python
126
+ from pico_ioc import init
127
+ import myapp
128
+
129
+ fake = {"repo": "fake-data"}
130
+ c = init(myapp, overrides={
131
+ "fast_model": fake, # constant instance
132
+ "user_service": lambda: {"id": 1}, # provider
133
+ })
134
+ assert c.get("fast_model") == {"repo": "fake-data"}
135
+ ```
136
+ ---
137
+
138
+ ## 📖 Documentation
139
+
140
+ * [Overview](.llm/OVERVIEW.md) — mission & concepts
141
+ * [Guide](.llm/GUIDE.md) — practical usage & recipes
142
+ * [Architecture](.llm/ARCHITECTURE.md) — internals & design rationale
143
+
144
+ ---
145
+
146
+ ## 🧪 Development
147
+
148
+ ```bash
149
+ pip install tox
150
+ tox
151
+ ```
152
+
153
+ ---
154
+
155
+ ## 📜 Changelog
156
+
157
+ See [CHANGELOG.md](./CHANGELOG.md) for version history.
158
+
159
+ ---
160
+
161
+ ## 📜 License
162
+
163
+ MIT — see [LICENSE](https://opensource.org/licenses/MIT)
164
+
165
+
166
+
@@ -0,0 +1,17 @@
1
+ pico_ioc/__init__.py,sha256=7EyifZ02LFfhkAR6zzAaQJvByyMI2_-qNrw49gPoJkA,633
2
+ pico_ioc/_state.py,sha256=KHNtdPrv1s-uynfot2IsNkWotBPyORPCcM2xe9qMMPo,286
3
+ pico_ioc/_version.py,sha256=b6-WiVk0Li5MaV2rBnHYl104TsouINojSWKqHDas0js,22
4
+ pico_ioc/api.py,sha256=pInjKJ1oi8bM4N0u4T3XLFa2qmYiHpQ7omcdXFFkGmE,3928
5
+ pico_ioc/container.py,sha256=oyCCeiPFVx7qw51IR9_ReuccInnpYMNuYhKxOKsioYE,5193
6
+ pico_ioc/decorators.py,sha256=gNPxLFNEdFUFYlxILKjU76XyoPohediK0DNiv-RpK3I,1902
7
+ pico_ioc/plugins.py,sha256=JbI-28VLGJaik7ysXi3L-YGTGxhqwJH4W5QYuWSruDE,589
8
+ pico_ioc/proxy.py,sha256=-e3Z9z7Bc_2wxswwUJI_s8AfvCTps8f8RWUJ9RuEp7E,4606
9
+ pico_ioc/public_api.py,sha256=E3sArCoI1xxkIw7xQBvLYAWcIoVJjcq1s0kH-0qIVDE,2383
10
+ pico_ioc/resolver.py,sha256=PN5uq2dFEStAzzTEl0n4AEyC-k7TowqCu7-uwIDDgEk,3897
11
+ pico_ioc/scanner.py,sha256=-iOj_qX15IBFmOAFQlP_1rIkBfamGzdqYdvIPOvq7sY,7709
12
+ pico_ioc/typing_utils.py,sha256=JQ4bkR60pKxFs3f8JlEz41ruKDsWj-SmkKv3DLJriec,950
13
+ pico_ioc-1.1.0.dist-info/licenses/LICENSE,sha256=N1_nOvHTM6BobYnOTNXiQkroDqCEi6EzfGBv8lWtyZ0,1077
14
+ pico_ioc-1.1.0.dist-info/METADATA,sha256=9tZ6dAnCgwLxD2GinaNb3U0FsCTPHTmicJxk9YsFY18,5920
15
+ pico_ioc-1.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ pico_ioc-1.1.0.dist-info/top_level.txt,sha256=_7_RLu616z_dtRw16impXn4Mw8IXe2J4BeX5912m5dQ,9
17
+ pico_ioc-1.1.0.dist-info/RECORD,,