@@ -82,35 +82,12 @@ def setup(
8282 install_root = self .install_root
8383 assert install_root is not None
8484 self .cargo_home .mkdir (parents = True , exist_ok = True )
85- self . _cargo_target_dir ( ).mkdir (parents = True , exist_ok = True )
85+ ( install_root / "target" ).mkdir (parents = True , exist_ok = True )
8686 if install_root != self .cargo_home :
8787 bin_dir = self .bin_dir
8888 assert bin_dir is not None
8989 bin_dir .mkdir (parents = True , exist_ok = True )
9090
91- def _cargo_target_dir (self ) -> Path :
92- install_root = self .install_root
93- assert install_root is not None
94- return install_root / "target"
95-
96- def _cargo_env (self ) -> dict [str , str ]:
97- install_root = self .install_root
98- assert install_root is not None
99- env = os .environ .copy ()
100- env ["CARGO_HOME" ] = str (self .cargo_home )
101- env ["CARGO_TARGET_DIR" ] = str (self ._cargo_target_dir ())
102- if install_root != self .cargo_home :
103- env ["CARGO_INSTALL_ROOT" ] = str (install_root )
104- return env
105-
106- def _cargo_install_args (self ) -> list [str ]:
107- install_root = self .install_root
108- assert install_root is not None
109- install_args = [* self .cargo_install_args ]
110- if install_root != self .cargo_home :
111- install_args .extend (["--root" , str (install_root )])
112- return install_args
113-
11491 def _cargo_package_specs (
11592 self ,
11693 bin_name : str ,
@@ -171,11 +148,25 @@ def default_install_handler(
171148 if min_version and not any (arg .startswith ("--version" ) for arg in install_args ):
172149 install_args = ["--version" , f">={ min_version } " , * install_args ]
173150 installer_bin = self ._require_installer_bin ()
151+ install_root = self .install_root
152+ assert install_root is not None
153+ cargo_install_args = [* self .cargo_install_args ]
154+ if install_root != self .cargo_home :
155+ cargo_install_args .extend (["--root" , str (install_root )])
174156
175157 proc = self .exec (
176158 bin_name = installer_bin ,
177- cmd = ["install" , * self ._cargo_install_args (), * install_args ],
178- env = self ._cargo_env (),
159+ cmd = ["install" , * cargo_install_args , * install_args ],
160+ env = {
161+ ** os .environ ,
162+ "CARGO_HOME" : str (self .cargo_home ),
163+ "CARGO_TARGET_DIR" : str (install_root / "target" ),
164+ ** (
165+ {"CARGO_INSTALL_ROOT" : str (install_root )}
166+ if install_root != self .cargo_home
167+ else {}
168+ ),
169+ },
179170 timeout = timeout ,
180171 )
181172 if proc .returncode != 0 :
@@ -202,16 +193,30 @@ def default_update_handler(
202193 if min_version and not any (arg .startswith ("--version" ) for arg in install_args ):
203194 install_args = ["--version" , f">={ min_version } " , * install_args ]
204195 installer_bin = self ._require_installer_bin ()
196+ install_root = self .install_root
197+ assert install_root is not None
198+ cargo_install_args = [* self .cargo_install_args ]
199+ if install_root != self .cargo_home :
200+ cargo_install_args .extend (["--root" , str (install_root )])
205201
206202 proc = self .exec (
207203 bin_name = installer_bin ,
208204 cmd = [
209205 "install" ,
210206 "--force" ,
211- * self . _cargo_install_args () ,
207+ * cargo_install_args ,
212208 * install_args ,
213209 ],
214- env = self ._cargo_env (),
210+ env = {
211+ ** os .environ ,
212+ "CARGO_HOME" : str (self .cargo_home ),
213+ "CARGO_TARGET_DIR" : str (install_root / "target" ),
214+ ** (
215+ {"CARGO_INSTALL_ROOT" : str (install_root )}
216+ if install_root != self .cargo_home
217+ else {}
218+ ),
219+ },
215220 timeout = timeout ,
216221 )
217222 if proc .returncode != 0 :
@@ -234,20 +239,30 @@ def default_uninstall_handler(
234239 install_args = install_args ,
235240 )
236241 installer_bin = self ._require_installer_bin ()
242+ install_root = self .install_root
243+ assert install_root is not None
237244
238245 proc = self .exec (
239246 bin_name = installer_bin ,
240247 cmd = [
241248 "uninstall" ,
242249 * (
243- ["--root" , str (self .install_root )]
244- if self .install_root is not None
245- and self .install_root != self .cargo_home
250+ ["--root" , str (install_root )]
251+ if install_root != self .cargo_home
246252 else []
247253 ),
248254 * package_specs ,
249255 ],
250- env = self ._cargo_env (),
256+ env = {
257+ ** os .environ ,
258+ "CARGO_HOME" : str (self .cargo_home ),
259+ "CARGO_TARGET_DIR" : str (install_root / "target" ),
260+ ** (
261+ {"CARGO_INSTALL_ROOT" : str (install_root )}
262+ if install_root != self .cargo_home
263+ else {}
264+ ),
265+ },
251266 timeout = timeout ,
252267 )
253268 if proc .returncode != 0 and "did not match any packages" not in proc .stderr :
0 commit comments