2525import os .path
2626
2727from ducktools .classbuilder .prefab import Prefab , attribute
28+ from ducktools .lazyimporter import LazyImporter , FromImport , MultiFromImport
2829
2930from . import (
3031 FOLDER_ENVVAR ,
5253from ._logger import log
5354
5455
56+ _laz_internal = LazyImporter (
57+ [
58+ FromImport (".bundle" , "create_bundle" ),
59+ FromImport (".scripts.get_pip" , "retrieve_pip" ),
60+ MultiFromImport (
61+ ".scripts.get_uv" ,
62+ ["retrieve_uv" , "get_available_pythons" , "install_uv_python" ]
63+ ),
64+ MultiFromImport (
65+ ".scripts.create_zipapp" ,
66+ ["build_env_folder" , "build_zipapp" ]
67+ ),
68+ ],
69+ globs = globals (),
70+ )
71+
72+
5573class Manager (Prefab ):
5674 project_name : str = PROJECT_NAME
5775 config : Config = None
@@ -110,11 +128,11 @@ def install_outdated(self):
110128
111129 # Ducktools build commands
112130 def retrieve_pip (self ) -> str :
113- return _laz .retrieve_pip (paths = self .paths )
131+ return _laz_internal .retrieve_pip (paths = self .paths )
114132
115133 def retrieve_uv (self , required = False ) -> str | None :
116134 if self .config .use_uv or required :
117- uv_path = _laz .retrieve_uv (paths = self .paths )
135+ uv_path = _laz_internal .retrieve_uv (paths = self .paths )
118136 else :
119137 uv_path = None
120138
@@ -142,12 +160,12 @@ def _get_python_install(self, spec: EnvironmentSpec):
142160 else :
143161 # If no Python was matched try to install a matching python from UV
144162 if (uv_path := self .retrieve_uv ()) and self .config .uv_install_python :
145- uv_pythons = _laz .get_available_pythons (uv_path )
163+ uv_pythons = _laz_internal .get_available_pythons (uv_path )
146164 matched_python = False
147165 for ver in uv_pythons :
148166 if spec .details .requires_python_spec .contains (ver ):
149167 # Install matching python
150- _laz .install_uv_python (
168+ _laz_internal .install_uv_python (
151169 uv_path = uv_path ,
152170 version_str = ver ,
153171 )
@@ -182,7 +200,7 @@ def build_env_folder(self, clear_old_builds=True) -> None:
182200 # build-env-folder installs into a target directory
183201 # instead of using a venv
184202 base_command = [sys .executable , self .retrieve_pip (), "--disable-pip-version-check" ]
185- _laz .build_env_folder (
203+ _laz_internal .build_env_folder (
186204 paths = self .paths ,
187205 install_base_command = base_command ,
188206 clear_old_builds = clear_old_builds ,
@@ -191,7 +209,7 @@ def build_env_folder(self, clear_old_builds=True) -> None:
191209 def build_zipapp (self , clear_old_builds = True ) -> None :
192210 """Build the ducktools.pyz zipapp"""
193211 base_command = [sys .executable , self .retrieve_pip (), "--disable-pip-version-check" ]
194- _laz .build_zipapp (
212+ _laz_internal .build_zipapp (
195213 paths = self .paths ,
196214 install_base_command = base_command ,
197215 clear_old_builds = clear_old_builds ,
@@ -423,7 +441,7 @@ def create_bundle(
423441 generate_lock = generate_lock ,
424442 )
425443
426- _laz .create_bundle (
444+ _laz_internal .create_bundle (
427445 spec = spec ,
428446 output_file = output_file ,
429447 paths = self .paths ,
0 commit comments