We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
conda env creation fails if Python 3 selected
I put this in `readthedocs.yml`:

``` yaml
conda:
    file: docs/conda-env.yml
python:
    version: 3
    setup_py_install: true
```

It creates a conda env with Python 3.5, and then tries to install the standard docs machinery. But docutils is pinned to 0.11, and there isn't a build of this for Python 3.5 (there is a package of docutils 0.12). So I see this failure:

```
conda install --yes --name docs-build-w-conda sphinx==1.3.1 Pygments==2.0.2 docutils==0.11 mock==1.0.1 pillow==3.0.0 sphinx_rtd_theme==0.1.7 alabaster>=0.7,<0.8,!=0.7.5
Fetching package metadata: /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
....
Solving package specifications: ..
Error: Unsatisfiable package specifications.
Generating hint: 
[                    ]|                                                  |   0%
[2/8                 ]|############                                      |  25%
[3/8                 ]|##################                                |  37%
[5/8                 ]|###############################                   |  62%
[6/8                 ]|#####################################             |  75%
[      COMPLETE      ]|##################################################| 100%



Hint: the following packages conflict with each other:
  - docutils ==0.11
  - python 3.5*

Use 'conda info docutils' etc. to see the dependencies for each package.
```

The obvious solution is not to pin docutils so it automatically picks the latest version available. If you prefer to keep it pinned, I think that installing dependencies at the same time as you create the environment should work; in this instance, it would fall back to Python 3.4 so it could satisfy the dependencies:

```
conda create --yes --name docs-build-w-conda python=3 sphinx==1.3.1 Pygments==2.0.2 docutils==0.11 ...
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `readthedocs/doc_builder/python_environments.py`
Content:
```
1 import logging
2 import os
3 import shutil
4 
5 from django.conf import settings
6 
7 from readthedocs.doc_builder.config import ConfigWrapper
8 from readthedocs.doc_builder.loader import get_builder_class
9 from readthedocs.projects.constants import LOG_TEMPLATE
10 
11 log = logging.getLogger(__name__)
12 
13 
14 class PythonEnvironment(object):
15 
16     def __init__(self, version, build_env, config=None):
17         self.version = version
18         self.project = version.project
19         self.build_env = build_env
20         if config:
21             self.config = config
22         else:
23             self.config = ConfigWrapper(version=version, yaml_config={})
24         # Compute here, since it's used a lot
25         self.checkout_path = self.project.checkout_path(self.version.slug)
26 
27     def _log(self, msg):
28         log.info(LOG_TEMPLATE
29                  .format(project=self.project.slug,
30                          version=self.version.slug,
31                          msg=msg))
32 
33     def delete_existing_build_dir(self):
34 
35         # Handle deleting old build dir
36         build_dir = os.path.join(
37             self.venv_path(),
38             'build')
39         if os.path.exists(build_dir):
40             self._log('Removing existing build directory')
41             shutil.rmtree(build_dir)
42 
43     def install_package(self):
44         setup_path = os.path.join(self.checkout_path, 'setup.py')
45         if os.path.isfile(setup_path) and self.config.install_project:
46             if getattr(settings, 'USE_PIP_INSTALL', False):
47                 self.build_env.run(
48                     'python',
49                     self.venv_bin(filename='pip'),
50                     'install',
51                     '--ignore-installed',
52                     '--cache-dir',
53                     self.project.pip_cache_path,
54                     '.',
55                     cwd=self.checkout_path,
56                     bin_path=self.venv_bin()
57                 )
58             else:
59                 self.build_env.run(
60                     'python',
61                     'setup.py',
62                     'install',
63                     '--force',
64                     cwd=self.checkout_path,
65                     bin_path=self.venv_bin()
66                 )
67 
68     def venv_bin(self, filename=None):
69         """Return path to the virtualenv bin path, or a specific binary
70 
71         :param filename: If specified, add this filename to the path return
72         :returns: Path to virtualenv bin or filename in virtualenv bin
73         """
74         parts = [self.venv_path(), 'bin']
75         if filename is not None:
76             parts.append(filename)
77         return os.path.join(*parts)
78 
79 
80 class Virtualenv(PythonEnvironment):
81 
82     def venv_path(self):
83         return os.path.join(self.project.doc_path, 'envs', self.version.slug)
84 
85     def setup_base(self):
86         site_packages = '--no-site-packages'
87         if self.config.use_system_site_packages:
88             site_packages = '--system-site-packages'
89         env_path = self.venv_path()
90         self.build_env.run(
91             self.config.python_interpreter,
92             '-mvirtualenv',
93             site_packages,
94             env_path,
95             bin_path=None,  # Don't use virtualenv bin that doesn't exist yet
96         )
97 
98     def install_core_requirements(self):
99         requirements = [
100             'sphinx==1.3.1',
101             'Pygments==2.0.2',
102             'setuptools==18.6.1',
103             'docutils==0.11',
104             'mkdocs==0.14.0',
105             'mock==1.0.1',
106             'pillow==2.6.1',
107             'readthedocs-sphinx-ext==0.5.4',
108             'sphinx-rtd-theme==0.1.9',
109             'alabaster>=0.7,<0.8,!=0.7.5',
110             'commonmark==0.5.4',
111             'recommonmark==0.1.1',
112         ]
113 
114         cmd = [
115             'python',
116             self.venv_bin(filename='pip'),
117             'install',
118             '--use-wheel',
119             '-U',
120             '--cache-dir',
121             self.project.pip_cache_path,
122         ]
123         if self.config.use_system_site_packages:
124             # Other code expects sphinx-build to be installed inside the
125             # virtualenv.  Using the -I option makes sure it gets installed
126             # even if it is already installed system-wide (and
127             # --system-site-packages is used)
128             cmd.append('-I')
129         cmd.extend(requirements)
130         self.build_env.run(
131             *cmd,
132             bin_path=self.venv_bin()
133         )
134 
135     def install_user_requirements(self):
136         requirements_file_path = self.config.requirements_file
137         if not requirements_file_path:
138             builder_class = get_builder_class(self.project.documentation_type)
139             docs_dir = (builder_class(build_env=self.build_env, python_env=self)
140                         .docs_dir())
141             for path in [docs_dir, '']:
142                 for req_file in ['pip_requirements.txt', 'requirements.txt']:
143                     test_path = os.path.join(self.checkout_path, path, req_file)
144                     if os.path.exists(test_path):
145                         requirements_file_path = test_path
146                         break
147 
148         if requirements_file_path:
149             self.build_env.run(
150                 'python',
151                 self.venv_bin(filename='pip'),
152                 'install',
153                 '--exists-action=w',
154                 '--cache-dir',
155                 self.project.pip_cache_path,
156                 '-r{0}'.format(requirements_file_path),
157                 cwd=self.checkout_path,
158                 bin_path=self.venv_bin()
159             )
160 
161 
162 class Conda(PythonEnvironment):
163 
164     def venv_path(self):
165         return os.path.join(self.project.doc_path, 'conda', self.version.slug)
166 
167     def setup_base(self):
168         conda_env_path = os.path.join(self.project.doc_path, 'conda')
169         version_path = os.path.join(conda_env_path, self.version.slug)
170 
171         if os.path.exists(version_path):
172             # Re-create conda directory each time to keep fresh state
173             self._log('Removing existing conda directory')
174             shutil.rmtree(version_path)
175         self.build_env.run(
176             'conda',
177             'create',
178             '--yes',
179             '--name',
180             self.version.slug,
181             'python={python_version}'.format(python_version=self.config.python_version),
182             bin_path=None,  # Don't use conda bin that doesn't exist yet
183         )
184 
185     def install_core_requirements(self):
186         conda_env_path = os.path.join(self.project.doc_path, 'conda')
187 
188         # Use conda for requirements it packages
189         requirements = [
190             'sphinx==1.3.1',
191             'Pygments==2.0.2',
192             'docutils==0.11',
193             'mock==1.0.1',
194             'pillow==3.0.0',
195             'sphinx_rtd_theme==0.1.7',
196             'alabaster>=0.7,<0.8,!=0.7.5',
197         ]
198 
199         cmd = [
200             'conda',
201             'install',
202             '--yes',
203             '--name',
204             self.version.slug,
205         ]
206         cmd.extend(requirements)
207         self.build_env.run(
208             *cmd
209         )
210 
211         # Install pip-only things.
212         pip_requirements = [
213             'mkdocs==0.14.0',
214             'readthedocs-sphinx-ext==0.5.4',
215             'commonmark==0.5.4',
216             'recommonmark==0.1.1',
217         ]
218 
219         pip_cmd = [
220             'python',
221             self.venv_bin(filename='pip'),
222             'install',
223             '-U',
224             '--cache-dir',
225             self.project.pip_cache_path,
226         ]
227         pip_cmd.extend(pip_requirements)
228         self.build_env.run(
229             *pip_cmd,
230             bin_path=self.venv_bin()
231         )
232 
233     def install_user_requirements(self):
234         conda_env_path = os.path.join(self.project.doc_path, 'conda')
235         self.build_env.run(
236             'conda',
237             'env',
238             'update',
239             '--name',
240             self.version.slug,
241             '--file',
242             self.config.conda_file,
243         )
244
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/readthedocs/doc_builder/python_environments.py b/readthedocs/doc_builder/python_environments.py
--- a/readthedocs/doc_builder/python_environments.py
+++ b/readthedocs/doc_builder/python_environments.py
@@ -100,7 +100,7 @@
             'sphinx==1.3.1',
             'Pygments==2.0.2',
             'setuptools==18.6.1',
-            'docutils==0.11',
+            'docutils==0.12',
             'mkdocs==0.14.0',
             'mock==1.0.1',
             'pillow==2.6.1',
@@ -174,22 +174,22 @@
             shutil.rmtree(version_path)
         self.build_env.run(
             'conda',
+            'env',
             'create',
-            '--yes',
             '--name',
             self.version.slug,
-            'python={python_version}'.format(python_version=self.config.python_version),
+            '--file',
+            self.config.conda_file,
             bin_path=None,  # Don't use conda bin that doesn't exist yet
         )
 
     def install_core_requirements(self):
-        conda_env_path = os.path.join(self.project.doc_path, 'conda')
 
         # Use conda for requirements it packages
         requirements = [
             'sphinx==1.3.1',
             'Pygments==2.0.2',
-            'docutils==0.11',
+            'docutils==0.12',
             'mock==1.0.1',
             'pillow==3.0.0',
             'sphinx_rtd_theme==0.1.7',
@@ -231,7 +231,6 @@
         )
 
     def install_user_requirements(self):
-        conda_env_path = os.path.join(self.project.doc_path, 'conda')
         self.build_env.run(
             'conda',
             'env',

{"golden_diff": "diff --git a/readthedocs/doc_builder/python_environments.py b/readthedocs/doc_builder/python_environments.py\n--- a/readthedocs/doc_builder/python_environments.py\n+++ b/readthedocs/doc_builder/python_environments.py\n@@ -100,7 +100,7 @@\n             'sphinx==1.3.1',\n             'Pygments==2.0.2',\n             'setuptools==18.6.1',\n-            'docutils==0.11',\n+            'docutils==0.12',\n             'mkdocs==0.14.0',\n             'mock==1.0.1',\n             'pillow==2.6.1',\n@@ -174,22 +174,22 @@\n             shutil.rmtree(version_path)\n         self.build_env.run(\n             'conda',\n+            'env',\n             'create',\n-            '--yes',\n             '--name',\n             self.version.slug,\n-            'python={python_version}'.format(python_version=self.config.python_version),\n+            '--file',\n+            self.config.conda_file,\n             bin_path=None,  # Don't use conda bin that doesn't exist yet\n         )\n \n     def install_core_requirements(self):\n-        conda_env_path = os.path.join(self.project.doc_path, 'conda')\n \n         # Use conda for requirements it packages\n         requirements = [\n             'sphinx==1.3.1',\n             'Pygments==2.0.2',\n-            'docutils==0.11',\n+            'docutils==0.12',\n             'mock==1.0.1',\n             'pillow==3.0.0',\n             'sphinx_rtd_theme==0.1.7',\n@@ -231,7 +231,6 @@\n         )\n \n     def install_user_requirements(self):\n-        conda_env_path = os.path.join(self.project.doc_path, 'conda')\n         self.build_env.run(\n             'conda',\n             'env',\n", "issue": "conda env creation fails if Python 3 selected\nI put this in `readthedocs.yml`:\n\n``` yaml\nconda:\n    file: docs/conda-env.yml\npython:\n    version: 3\n    setup_py_install: true\n```\n\nIt creates a conda env with Python 3.5, and then tries to install the standard docs machinery. But docutils is pinned to 0.11, and there isn't a build of this for Python 3.5 (there is a package of docutils 0.12). So I see this failure:\n\n```\nconda install --yes --name docs-build-w-conda sphinx==1.3.1 Pygments==2.0.2 docutils==0.11 mock==1.0.1 pillow==3.0.0 sphinx_rtd_theme==0.1.7 alabaster>=0.7,<0.8,!=0.7.5\nFetching package metadata: /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.\n  SNIMissingWarning\n/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n  InsecurePlatformWarning\n....\nSolving package specifications: ..\nError: Unsatisfiable package specifications.\nGenerating hint: \n[                    ]|                                                  |   0%\n[2/8                 ]|############                                      |  25%\n[3/8                 ]|##################                                |  37%\n[5/8                 ]|###############################                   |  62%\n[6/8                 ]|#####################################             |  75%\n[      COMPLETE      ]|##################################################| 100%\n\n\n\nHint: the following packages conflict with each other:\n  - docutils ==0.11\n  - python 3.5*\n\nUse 'conda info docutils' etc. to see the dependencies for each package.\n```\n\nThe obvious solution is not to pin docutils so it automatically picks the latest version available. If you prefer to keep it pinned, I think that installing dependencies at the same time as you create the environment should work; in this instance, it would fall back to Python 3.4 so it could satisfy the dependencies:\n\n```\nconda create --yes --name docs-build-w-conda python=3 sphinx==1.3.1 Pygments==2.0.2 docutils==0.11 ...\n```\n\n", "before_files": [{"content": "import logging\nimport os\nimport shutil\n\nfrom django.conf import settings\n\nfrom readthedocs.doc_builder.config import ConfigWrapper\nfrom readthedocs.doc_builder.loader import get_builder_class\nfrom readthedocs.projects.constants import LOG_TEMPLATE\n\nlog = logging.getLogger(__name__)\n\n\nclass PythonEnvironment(object):\n\n    def __init__(self, version, build_env, config=None):\n        self.version = version\n        self.project = version.project\n        self.build_env = build_env\n        if config:\n            self.config = config\n        else:\n            self.config = ConfigWrapper(version=version, yaml_config={})\n        # Compute here, since it's used a lot\n        self.checkout_path = self.project.checkout_path(self.version.slug)\n\n    def _log(self, msg):\n        log.info(LOG_TEMPLATE\n                 .format(project=self.project.slug,\n                         version=self.version.slug,\n                         msg=msg))\n\n    def delete_existing_build_dir(self):\n\n        # Handle deleting old build dir\n        build_dir = os.path.join(\n            self.venv_path(),\n            'build')\n        if os.path.exists(build_dir):\n            self._log('Removing existing build directory')\n            shutil.rmtree(build_dir)\n\n    def install_package(self):\n        setup_path = os.path.join(self.checkout_path, 'setup.py')\n        if os.path.isfile(setup_path) and self.config.install_project:\n            if getattr(settings, 'USE_PIP_INSTALL', False):\n                self.build_env.run(\n                    'python',\n                    self.venv_bin(filename='pip'),\n                    'install',\n                    '--ignore-installed',\n                    '--cache-dir',\n                    self.project.pip_cache_path,\n                    '.',\n                    cwd=self.checkout_path,\n                    bin_path=self.venv_bin()\n                )\n            else:\n                self.build_env.run(\n                    'python',\n                    'setup.py',\n                    'install',\n                    '--force',\n                    cwd=self.checkout_path,\n                    bin_path=self.venv_bin()\n                )\n\n    def venv_bin(self, filename=None):\n        \"\"\"Return path to the virtualenv bin path, or a specific binary\n\n        :param filename: If specified, add this filename to the path return\n        :returns: Path to virtualenv bin or filename in virtualenv bin\n        \"\"\"\n        parts = [self.venv_path(), 'bin']\n        if filename is not None:\n            parts.append(filename)\n        return os.path.join(*parts)\n\n\nclass Virtualenv(PythonEnvironment):\n\n    def venv_path(self):\n        return os.path.join(self.project.doc_path, 'envs', self.version.slug)\n\n    def setup_base(self):\n        site_packages = '--no-site-packages'\n        if self.config.use_system_site_packages:\n            site_packages = '--system-site-packages'\n        env_path = self.venv_path()\n        self.build_env.run(\n            self.config.python_interpreter,\n            '-mvirtualenv',\n            site_packages,\n            env_path,\n            bin_path=None,  # Don't use virtualenv bin that doesn't exist yet\n        )\n\n    def install_core_requirements(self):\n        requirements = [\n            'sphinx==1.3.1',\n            'Pygments==2.0.2',\n            'setuptools==18.6.1',\n            'docutils==0.11',\n            'mkdocs==0.14.0',\n            'mock==1.0.1',\n            'pillow==2.6.1',\n            'readthedocs-sphinx-ext==0.5.4',\n            'sphinx-rtd-theme==0.1.9',\n            'alabaster>=0.7,<0.8,!=0.7.5',\n            'commonmark==0.5.4',\n            'recommonmark==0.1.1',\n        ]\n\n        cmd = [\n            'python',\n            self.venv_bin(filename='pip'),\n            'install',\n            '--use-wheel',\n            '-U',\n            '--cache-dir',\n            self.project.pip_cache_path,\n        ]\n        if self.config.use_system_site_packages:\n            # Other code expects sphinx-build to be installed inside the\n            # virtualenv.  Using the -I option makes sure it gets installed\n            # even if it is already installed system-wide (and\n            # --system-site-packages is used)\n            cmd.append('-I')\n        cmd.extend(requirements)\n        self.build_env.run(\n            *cmd,\n            bin_path=self.venv_bin()\n        )\n\n    def install_user_requirements(self):\n        requirements_file_path = self.config.requirements_file\n        if not requirements_file_path:\n            builder_class = get_builder_class(self.project.documentation_type)\n            docs_dir = (builder_class(build_env=self.build_env, python_env=self)\n                        .docs_dir())\n            for path in [docs_dir, '']:\n                for req_file in ['pip_requirements.txt', 'requirements.txt']:\n                    test_path = os.path.join(self.checkout_path, path, req_file)\n                    if os.path.exists(test_path):\n                        requirements_file_path = test_path\n                        break\n\n        if requirements_file_path:\n            self.build_env.run(\n                'python',\n                self.venv_bin(filename='pip'),\n                'install',\n                '--exists-action=w',\n                '--cache-dir',\n                self.project.pip_cache_path,\n                '-r{0}'.format(requirements_file_path),\n                cwd=self.checkout_path,\n                bin_path=self.venv_bin()\n            )\n\n\nclass Conda(PythonEnvironment):\n\n    def venv_path(self):\n        return os.path.join(self.project.doc_path, 'conda', self.version.slug)\n\n    def setup_base(self):\n        conda_env_path = os.path.join(self.project.doc_path, 'conda')\n        version_path = os.path.join(conda_env_path, self.version.slug)\n\n        if os.path.exists(version_path):\n            # Re-create conda directory each time to keep fresh state\n            self._log('Removing existing conda directory')\n            shutil.rmtree(version_path)\n        self.build_env.run(\n            'conda',\n            'create',\n            '--yes',\n            '--name',\n            self.version.slug,\n            'python={python_version}'.format(python_version=self.config.python_version),\n            bin_path=None,  # Don't use conda bin that doesn't exist yet\n        )\n\n    def install_core_requirements(self):\n        conda_env_path = os.path.join(self.project.doc_path, 'conda')\n\n        # Use conda for requirements it packages\n        requirements = [\n            'sphinx==1.3.1',\n            'Pygments==2.0.2',\n            'docutils==0.11',\n            'mock==1.0.1',\n            'pillow==3.0.0',\n            'sphinx_rtd_theme==0.1.7',\n            'alabaster>=0.7,<0.8,!=0.7.5',\n        ]\n\n        cmd = [\n            'conda',\n            'install',\n            '--yes',\n            '--name',\n            self.version.slug,\n        ]\n        cmd.extend(requirements)\n        self.build_env.run(\n            *cmd\n        )\n\n        # Install pip-only things.\n        pip_requirements = [\n            'mkdocs==0.14.0',\n            'readthedocs-sphinx-ext==0.5.4',\n            'commonmark==0.5.4',\n            'recommonmark==0.1.1',\n        ]\n\n        pip_cmd = [\n            'python',\n            self.venv_bin(filename='pip'),\n            'install',\n            '-U',\n            '--cache-dir',\n            self.project.pip_cache_path,\n        ]\n        pip_cmd.extend(pip_requirements)\n        self.build_env.run(\n            *pip_cmd,\n            bin_path=self.venv_bin()\n        )\n\n    def install_user_requirements(self):\n        conda_env_path = os.path.join(self.project.doc_path, 'conda')\n        self.build_env.run(\n            'conda',\n            'env',\n            'update',\n            '--name',\n            self.version.slug,\n            '--file',\n            self.config.conda_file,\n        )\n", "path": "readthedocs/doc_builder/python_environments.py"}], "after_files": [{"content": "import logging\nimport os\nimport shutil\n\nfrom django.conf import settings\n\nfrom readthedocs.doc_builder.config import ConfigWrapper\nfrom readthedocs.doc_builder.loader import get_builder_class\nfrom readthedocs.projects.constants import LOG_TEMPLATE\n\nlog = logging.getLogger(__name__)\n\n\nclass PythonEnvironment(object):\n\n    def __init__(self, version, build_env, config=None):\n        self.version = version\n        self.project = version.project\n        self.build_env = build_env\n        if config:\n            self.config = config\n        else:\n            self.config = ConfigWrapper(version=version, yaml_config={})\n        # Compute here, since it's used a lot\n        self.checkout_path = self.project.checkout_path(self.version.slug)\n\n    def _log(self, msg):\n        log.info(LOG_TEMPLATE\n                 .format(project=self.project.slug,\n                         version=self.version.slug,\n                         msg=msg))\n\n    def delete_existing_build_dir(self):\n\n        # Handle deleting old build dir\n        build_dir = os.path.join(\n            self.venv_path(),\n            'build')\n        if os.path.exists(build_dir):\n            self._log('Removing existing build directory')\n            shutil.rmtree(build_dir)\n\n    def install_package(self):\n        setup_path = os.path.join(self.checkout_path, 'setup.py')\n        if os.path.isfile(setup_path) and self.config.install_project:\n            if getattr(settings, 'USE_PIP_INSTALL', False):\n                self.build_env.run(\n                    'python',\n                    self.venv_bin(filename='pip'),\n                    'install',\n                    '--ignore-installed',\n                    '--cache-dir',\n                    self.project.pip_cache_path,\n                    '.',\n                    cwd=self.checkout_path,\n                    bin_path=self.venv_bin()\n                )\n            else:\n                self.build_env.run(\n                    'python',\n                    'setup.py',\n                    'install',\n                    '--force',\n                    cwd=self.checkout_path,\n                    bin_path=self.venv_bin()\n                )\n\n    def venv_bin(self, filename=None):\n        \"\"\"Return path to the virtualenv bin path, or a specific binary\n\n        :param filename: If specified, add this filename to the path return\n        :returns: Path to virtualenv bin or filename in virtualenv bin\n        \"\"\"\n        parts = [self.venv_path(), 'bin']\n        if filename is not None:\n            parts.append(filename)\n        return os.path.join(*parts)\n\n\nclass Virtualenv(PythonEnvironment):\n\n    def venv_path(self):\n        return os.path.join(self.project.doc_path, 'envs', self.version.slug)\n\n    def setup_base(self):\n        site_packages = '--no-site-packages'\n        if self.config.use_system_site_packages:\n            site_packages = '--system-site-packages'\n        env_path = self.venv_path()\n        self.build_env.run(\n            self.config.python_interpreter,\n            '-mvirtualenv',\n            site_packages,\n            env_path,\n            bin_path=None,  # Don't use virtualenv bin that doesn't exist yet\n        )\n\n    def install_core_requirements(self):\n        requirements = [\n            'sphinx==1.3.1',\n            'Pygments==2.0.2',\n            'setuptools==18.6.1',\n            'docutils==0.12',\n            'mkdocs==0.14.0',\n            'mock==1.0.1',\n            'pillow==2.6.1',\n            'readthedocs-sphinx-ext==0.5.4',\n            'sphinx-rtd-theme==0.1.9',\n            'alabaster>=0.7,<0.8,!=0.7.5',\n            'commonmark==0.5.4',\n            'recommonmark==0.1.1',\n        ]\n\n        cmd = [\n            'python',\n            self.venv_bin(filename='pip'),\n            'install',\n            '--use-wheel',\n            '-U',\n            '--cache-dir',\n            self.project.pip_cache_path,\n        ]\n        if self.config.use_system_site_packages:\n            # Other code expects sphinx-build to be installed inside the\n            # virtualenv.  Using the -I option makes sure it gets installed\n            # even if it is already installed system-wide (and\n            # --system-site-packages is used)\n            cmd.append('-I')\n        cmd.extend(requirements)\n        self.build_env.run(\n            *cmd,\n            bin_path=self.venv_bin()\n        )\n\n    def install_user_requirements(self):\n        requirements_file_path = self.config.requirements_file\n        if not requirements_file_path:\n            builder_class = get_builder_class(self.project.documentation_type)\n            docs_dir = (builder_class(build_env=self.build_env, python_env=self)\n                        .docs_dir())\n            for path in [docs_dir, '']:\n                for req_file in ['pip_requirements.txt', 'requirements.txt']:\n                    test_path = os.path.join(self.checkout_path, path, req_file)\n                    if os.path.exists(test_path):\n                        requirements_file_path = test_path\n                        break\n\n        if requirements_file_path:\n            self.build_env.run(\n                'python',\n                self.venv_bin(filename='pip'),\n                'install',\n                '--exists-action=w',\n                '--cache-dir',\n                self.project.pip_cache_path,\n                '-r{0}'.format(requirements_file_path),\n                cwd=self.checkout_path,\n                bin_path=self.venv_bin()\n            )\n\n\nclass Conda(PythonEnvironment):\n\n    def venv_path(self):\n        return os.path.join(self.project.doc_path, 'conda', self.version.slug)\n\n    def setup_base(self):\n        conda_env_path = os.path.join(self.project.doc_path, 'conda')\n        version_path = os.path.join(conda_env_path, self.version.slug)\n\n        if os.path.exists(version_path):\n            # Re-create conda directory each time to keep fresh state\n            self._log('Removing existing conda directory')\n            shutil.rmtree(version_path)\n        self.build_env.run(\n            'conda',\n            'env',\n            'create',\n            '--name',\n            self.version.slug,\n            '--file',\n            self.config.conda_file,\n            bin_path=None,  # Don't use conda bin that doesn't exist yet\n        )\n\n    def install_core_requirements(self):\n\n        # Use conda for requirements it packages\n        requirements = [\n            'sphinx==1.3.1',\n            'Pygments==2.0.2',\n            'docutils==0.12',\n            'mock==1.0.1',\n            'pillow==3.0.0',\n            'sphinx_rtd_theme==0.1.7',\n            'alabaster>=0.7,<0.8,!=0.7.5',\n        ]\n\n        cmd = [\n            'conda',\n            'install',\n            '--yes',\n            '--name',\n            self.version.slug,\n        ]\n        cmd.extend(requirements)\n        self.build_env.run(\n            *cmd\n        )\n\n        # Install pip-only things.\n        pip_requirements = [\n            'mkdocs==0.14.0',\n            'readthedocs-sphinx-ext==0.5.4',\n            'commonmark==0.5.4',\n            'recommonmark==0.1.1',\n        ]\n\n        pip_cmd = [\n            'python',\n            self.venv_bin(filename='pip'),\n            'install',\n            '-U',\n            '--cache-dir',\n            self.project.pip_cache_path,\n        ]\n        pip_cmd.extend(pip_requirements)\n        self.build_env.run(\n            *pip_cmd,\n            bin_path=self.venv_bin()\n        )\n\n    def install_user_requirements(self):\n        self.build_env.run(\n            'conda',\n            'env',\n            'update',\n            '--name',\n            self.version.slug,\n            '--file',\n            self.config.conda_file,\n        )\n", "path": "readthedocs/doc_builder/python_environments.py"}]}