@@ -56,7 +56,7 @@ def environments(self):
56
56
for env in self ._data ["envs" ]:
57
57
path = Path (env )
58
58
self .logger .debug (f" environment { env } " )
59
- if path == self .root_path :
59
+ if path == self .prefix :
60
60
result .append ("base" )
61
61
self .logger .debug (" --> base" )
62
62
else :
@@ -171,7 +171,9 @@ def _initialize(self):
171
171
# break
172
172
173
173
# self.root_path = root
174
- self .root_path = Path (self ._data ["conda_prefix" ])
174
+ self .root_path = Path (self ._data ["active_prefix" ]).parent
175
+ if self .root_path .name == "envs" :
176
+ self .root_path = self .root_path .parent
175
177
176
178
tmp = "\n \t " .join (self .environments )
177
179
self .logger .info (f"environments:\n \t { tmp } " )
@@ -199,8 +201,7 @@ def create_environment(self, environment_file, name=None, force=False):
199
201
command += " --force"
200
202
if name is not None :
201
203
# Using the name leads to odd paths, so be explicit.
202
- # command += f" --name '{name}'"
203
- path = self .root_path / "envs" / name
204
+ path = self ._resolve_environment_path (name )
204
205
command += f" --prefix '{ str (path )} '"
205
206
self .logger .debug (f"command = { command } " )
206
207
try :
@@ -221,7 +222,7 @@ def delete_environment(self, name):
221
222
The name of the environment.
222
223
"""
223
224
# Using the name leads to odd paths, so be explicit.
224
- path = self .root_path / "envs" / name
225
+ path = self ._resolve_environment_path ( name )
225
226
226
227
command = f"conda env remove --yes --prefix '{ str (path )} '"
227
228
@@ -260,7 +261,8 @@ def export_environment(self, environment, path=None):
260
261
path : str or pathlib.Path = None
261
262
An optional filename to export to
262
263
"""
263
- command = f"conda env export --name '{ environment } '"
264
+ environment_path = self ._resolve_environment_path (environment )
265
+ command = f"conda env export --prefix '{ environment_path } '"
264
266
if path is not None :
265
267
command += f" --file '{ path } '"
266
268
try :
@@ -303,7 +305,7 @@ def install(
303
305
if environment is not None :
304
306
# Using the name leads to odd paths, so be explicit.
305
307
# command += f" --name '{environment}'"
306
- path = self .root_path / "envs" / environment
308
+ path = self ._resolve_environment_path ( environment )
307
309
command += f" --prefix '{ str (path )} '"
308
310
if override_channels :
309
311
command += " --override-channels"
@@ -355,7 +357,8 @@ def list(
355
357
else :
356
358
command = "conda list --json"
357
359
if environment is not None :
358
- command += f" --name '{ environment } '"
360
+ path = self ._resolve_environment_path (environment )
361
+ command += f" --prefix '{ path } '"
359
362
if fullname :
360
363
command += " --full-name"
361
364
if query is not None :
@@ -400,10 +403,10 @@ def path(self, environment):
400
403
The path to the environment.
401
404
"""
402
405
if environment == "base" :
403
- return Path (self .root_path )
406
+ return Path (self .prefix )
404
407
else :
405
408
for env in self ._data ["envs" ]:
406
- if env != self .root_path :
409
+ if env != self .prefix :
407
410
path = Path (env )
408
411
if environment == path .name :
409
412
return path
@@ -417,7 +420,8 @@ def remove_environment(self, environment):
417
420
environment : str
418
421
The name of the environment to remove.
419
422
"""
420
- command = f"conda env remove --name '{ environment } ' --yes --json"
423
+ path = self ._resolve_environment_path (environment )
424
+ command = f"conda env remove --prefix '{ path } ' --yes --json"
421
425
try :
422
426
self ._execute (command )
423
427
except subprocess .CalledProcessError as e :
@@ -547,7 +551,7 @@ def update(
547
551
if environment is not None :
548
552
# Using the name leads to odd paths, so be explicit.
549
553
# command += f" --name '{environment}'"
550
- path = self .root_path / "envs" / environment
554
+ path = self ._resolve_environment_path ( environment )
551
555
command += f" --prefix '{ str (path )} '"
552
556
if override_channels :
553
557
command += " --override-channels"
@@ -602,7 +606,8 @@ def uninstall(
602
606
"""
603
607
command = "conda uninstall --yes "
604
608
if environment is not None :
605
- command += f" --name '{ environment } '"
609
+ path = self ._resolve_environment_path (environment )
610
+ command += f" --prefix '{ path } '"
606
611
if override_channels :
607
612
command += " --override-channels"
608
613
if channels is None :
@@ -639,7 +644,7 @@ def update_environment(self, environment_file, name=None):
639
644
if name is not None :
640
645
# Using the name leads to odd paths, so be explicit.
641
646
# command += f" --name '{name}'"
642
- path = self .root_path / "envs" / name
647
+ path = self ._resolve_environment_path ( name )
643
648
command += f" --prefix '{ str (path )} '"
644
649
print (f"command = { command } " )
645
650
self .logger .debug (f"command = { command } " )
@@ -712,3 +717,11 @@ def _execute(
712
717
if update is None :
713
718
print ("" )
714
719
return result , stdout , stderr
720
+
721
+ def _resolve_environment_path (self , pathname ):
722
+ """Get the path given either a name or path for an environment."""
723
+ if Path (pathname ).is_absolute :
724
+ path = Path (pathname )
725
+ else :
726
+ path = self .root_path / "envs" / pathname
727
+ return path
0 commit comments