1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""A dependency-free lazy module loader.
Workbenches (Draft in particular) defer ``import Part`` until an attribute is
actually used::
import lazy_loader.lazy_loader as lz
Part = lz.LazyLoader("Part", globals(), "Part")
The value bound to the global is this loader. The first attribute access imports
the target module, replaces the global with the module object, and caches it, so
the cost is paid once and subsequent accesses are ordinary module lookups. This
is the subset of the upstream ``lazy_loader`` package that FreeCAD uses; it has
no third-party dependencies.
"""
=
"""Stand-in for a module, imported on first attribute access.
Parameters
----------
name:
The name the loader is bound to in ``module_globals``. Also the module
to import when ``module_name`` is not given.
module_globals:
The ``globals()`` of the defining module. On first access it is updated
so ``name`` refers to the imported module instead of this loader.
module_name:
The module to import, when it differs from ``name``.
"""
=
=
= or
= None
"""Import the target module once, replacing the global binding."""
=
=
=
return
# ``__getattr__`` only runs for attributes the loader itself does not
# define, so the bookkeeping fields above cannot recurse here.
return
return
return f
return