@@ -484,6 +484,23 @@ class Conda(PythonEnvironment):
484
484
def venv_path (self ):
485
485
return os .path .join (self .project .doc_path , 'conda' , self .version .slug )
486
486
487
+ def conda_bin_name (self ):
488
+ """
489
+ Decide whether use ``mamba`` or ``conda`` to create the environment.
490
+
491
+ Return ``mamba`` if the project has ``CONDA_USES_MAMBA`` feature and
492
+ ``conda`` otherwise. This will be the executable name to be used when
493
+ creating the conda environment.
494
+
495
+ ``mamba`` is really fast to solve dependencies and download channel
496
+ metadata on startup.
497
+
498
+ See https://github.com/QuantStack/mamba
499
+ """
500
+ if self .project .has_feature (Feature .CONDA_USES_MAMBA ):
501
+ return 'mamba'
502
+ return 'conda'
503
+
487
504
def _update_conda_startup (self ):
488
505
"""
489
506
Update ``conda`` before use it for the first time.
@@ -492,6 +509,8 @@ def _update_conda_startup(self):
492
509
independently the version of Miniconda that it has installed.
493
510
"""
494
511
self .build_env .run (
512
+ # TODO: use ``self.conda_bin_name()`` once ``mamba`` is installed in
513
+ # the Docker image
495
514
'conda' ,
496
515
'update' ,
497
516
'--yes' ,
@@ -502,6 +521,18 @@ def _update_conda_startup(self):
502
521
cwd = self .checkout_path ,
503
522
)
504
523
524
+ def _install_mamba (self ):
525
+ self .build_env .run (
526
+ 'conda' ,
527
+ 'install' ,
528
+ '--yes' ,
529
+ '--quiet' ,
530
+ '--name=base' ,
531
+ '--channel=conda-forge' ,
532
+ 'mamba' ,
533
+ cwd = self .checkout_path ,
534
+ )
535
+
505
536
def setup_base (self ):
506
537
conda_env_path = os .path .join (self .project .doc_path , 'conda' )
507
538
version_path = os .path .join (conda_env_path , self .version .slug )
@@ -525,8 +556,12 @@ def setup_base(self):
525
556
self ._append_core_requirements ()
526
557
self ._show_environment_yaml ()
527
558
559
+ # TODO: remove it when ``mamba`` is installed in the Docker image
560
+ if self .project .has_feature (Feature .CONDA_USES_MAMBA ):
561
+ self ._install_mamba ()
562
+
528
563
self .build_env .run (
529
- 'conda' ,
564
+ self . conda_bin_name () ,
530
565
'env' ,
531
566
'create' ,
532
567
'--quiet' ,
@@ -612,6 +647,9 @@ def _get_core_requirements(self):
612
647
'pillow' ,
613
648
]
614
649
650
+ if self .project .has_feature (Feature .CONDA_USES_MAMBA ):
651
+ conda_requirements .append ('pip' )
652
+
615
653
# Install pip-only things.
616
654
pip_requirements = [
617
655
'recommonmark' ,
@@ -639,7 +677,7 @@ def install_core_requirements(self):
639
677
# Install requirements via ``conda install`` command if they were
640
678
# not appended to the ``environment.yml`` file.
641
679
cmd = [
642
- 'conda' ,
680
+ self . conda_bin_name () ,
643
681
'install' ,
644
682
'--yes' ,
645
683
'--quiet' ,
0 commit comments