Repository: readthedocs/readthedocs.org

Issue:
Build using mamba fails due to excessive memory when pip is missing from env
## Details

* Read the Docs project URL: https://readthedocs.org/projects/moaceanparcels/
* Build URL (if applicable): https://readthedocs.org/projects/moaceanparcels/builds/15154894/
* Read the Docs username (if applicable): dlatornell

## Expected Result

A successful docs build

## Actual Result

Build failed at the `mamba env create --quiet --name latest --file envs/environment-rtd.yaml` step with a truncated log showing many identical messages:

> Warning: you have pip-installed dependencies in your environment file, but you do not list pip itself as one of your conda dependencies.  Conda may not use the correct pip to install your packages, and they may end up in the wrong place.  Please add an explicit pip dependency.  I'm adding one for you, but still nagging you.

Build failure message at end of log is:

> Command killed due to excessive memory consumption

## Analysis and Mitigation

The `.readthedocs.yaml` for this project is:
```yaml
version: 2

build:
  os: ubuntu-20.04
  tools:
    python: "mambaforge-4.10"

conda:
  environment: envs/environment-rtd.yaml

# Only build HTML and JSON formats
formats: []
```
The `envs/environment-rts.yaml` file that results in the failed build is:
```yaml
name: rtd-env

channels:
  - conda-forge
  - nodefaults

dependencies:
  - python=3.9

  # readthedocs packages
  - mock
  - pillow
  - sphinx
  - sphinx_rtd_theme
```
I know that the rtd build process injects the packages it needs into the env file. We include them in our file so that we can build a local environment as close as possible to the rtd one to debug build issues locally.

The problem is that the list of rtd pkgs now also includes `recommonmark` and `readthedocs-sphinx-ext` that are installed via `pip`. Despite the builder's warning above about the lack of `pip` as a dependency and its claim that it is "adding one for you, but still nagging you", it does not appear to actually do that, and the build failure I describe is the result. The `cat envs/environment-rtd.yaml` of the build shows that `pip` is not being injected into the env file with the rest of the rtd deps.

When I changed the `envs/environment-rts.yaml` file to:
```yaml
name: rtd-env

channels:
  - conda-forge
  - nodefaults

dependencies:
  - python=3.9

  # readthedocs packages
  - mock
  - pillow
  - pip
  - sphinx
  - sphinx_rtd_theme
  - pip:
      - recommonmark
      - readthedocs-sphinx-ext
```
the build succeeded.



Discussion:
I could reproduce this locally. I think the Read the Docs error is a timeout, rather than a memory error. Reported it upstream at https://github.com/mamba-org/mamba/issues/1293
This is actually a conda issue that was reported and fixed a few months ago https://github.com/conda/conda/issues/10614, should be fixed by upgrading our mambaforge installer to a more recent version. Thanks @douglatornell for reporting.
cc @humitos should I open an issue in https://github.com/readthedocs/readthedocs-docker-images to request an upgrade of mambaforge?
@astrojuanlu I think this issue is enough. I can open a quick PR that we can deploy soon.
@astrojuanlu I just checked the version we have available and it seem they are the latest ones:

Available versions:

```
▶ asdf list all python | grep miniconda3 | tail
miniconda3-4.3.30
miniconda3-4.3.31
miniconda3-4.4.10
miniconda3-4.5.1
miniconda3-4.5.4
miniconda3-4.5.11
miniconda3-4.5.12
miniconda3-4.6.14
miniconda3-4.7.10
miniconda3-4.7.12

~                                                                                                                                                                                     
▶ asdf list all python | grep mamba | tail     
mambaforge-pypy3
mambaforge
mambaforge-4.10.1-4
mambaforge-4.10.1-5
```

Versions allowed in our code:

https://github.com/readthedocs/readthedocs.org/blob/ecda33f2badfcf2c78b983b6bcbdbd68a59c8aad/readthedocs/settings/base.py#L557-L558

Did mamba/conda people already release a new version?
4.10.1-5 (the one we use) seems to be from June https://github.com/conda-forge/miniforge/releases/tag/4.10.1-5 and there is now a 4.10.3-7 from October https://github.com/conda-forge/miniforge/releases/tag/4.10.3-7
Looks like someone has to create a PR like this essentially https://github.com/pyenv/pyenv/pull/1992/files
Yeap, I was about to comment exactly that :)

Once a similar PR gets merged, we can upgrade our versions.
In progress https://github.com/pyenv/pyenv/pull/2184

Resolving patch:
diff --git a/readthedocs/settings/base.py b/readthedocs/settings/base.py
--- a/readthedocs/settings/base.py
+++ b/readthedocs/settings/base.py
@@ -559,7 +559,7 @@ def TEMPLATES(self):
                 '3.10': '3.10.0',
                 'pypy3.7': 'pypy3.7-7.3.5',
                 'miniconda3-4.7': 'miniconda3-4.7.12',
-                'mambaforge-4.10': 'mambaforge-4.10.1-5',
+                'mambaforge-4.10': 'mambaforge-4.10.3-10',
             },
             'nodejs': {
                 '14': '14.17.6',


Test patch: