• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import inspect
2
3
4def _bridge_build_meta():
5    import functools
6    import sys
7
8    from setuptools import build_meta
9
10    self_module = sys.modules[__name__]
11
12    for attr_name in build_meta.__all__:
13        attr_value = getattr(build_meta, attr_name)
14        if callable(attr_value):
15            setattr(self_module, attr_name, functools.partial(_expose_config_settings, attr_value))
16
17
18class ActiveConfigSettings:
19    _current = {}
20
21    def __init__(self, config_settings):
22        self._config = config_settings
23
24    def __enter__(self):
25        type(self)._current = self._config
26
27    def __exit__(self, exc_type, exc_val, exc_tb):
28        type(self)._current = {}
29
30    @classmethod
31    def current(cls):
32        return cls._current
33
34
35def _expose_config_settings(real_method, *args, **kwargs):
36    from contextlib import nullcontext
37    import inspect
38
39    sig = inspect.signature(real_method)
40    boundargs = sig.bind(*args, **kwargs)
41
42    config = boundargs.arguments.get('config_settings')
43
44    ctx = ActiveConfigSettings(config) if config else nullcontext()
45
46    with ctx:
47        return real_method(*args, **kwargs)
48
49
50_bridge_build_meta()
51
52