We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Pip install failing to install sphinx when PYTHON_HOME is set
If the env variable PYTHON_HOME exists, pip install is failing to install spinx into the virtualenv.


--- 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/projects/utils.py`
Content:
```
1 """Utility functions used by projects.
2 """
3 import fnmatch
4 import os
5 import re
6 import subprocess
7 import traceback
8 import logging
9 from httplib2 import Http
10 
11 from django.conf import settings
12 from distutils2.version import NormalizedVersion, suggest_normalized_version
13 import redis
14 
15 from builds.constants import LATEST
16 
17 
18 log = logging.getLogger(__name__)
19 
20 def version_from_slug(slug, version):
21     from projects import tasks
22     from builds.models import Version
23     from tastyapi import apiv2 as api
24     if getattr(settings, 'DONT_HIT_DB', True):
25         version_data = api.version().get(project=slug, slug=version)['results'][0]
26         v = tasks.make_api_version(version_data)
27     else:
28         v = Version.objects.get(project__slug=slug, slug=version)
29     return v
30 
31 def symlink(project, version=LATEST):
32     from projects import symlinks
33     v = version_from_slug(project, version)
34     log.info("Symlinking %s" % v)
35     symlinks.symlink_subprojects(v)
36     symlinks.symlink_cnames(v)
37     symlinks.symlink_translations(v)
38 
39 def update_static_metadata(project_pk):
40     """
41     This is here to avoid circular imports in models.py
42     """
43     from projects import tasks
44     tasks.update_static_metadata.delay(project_pk)
45 
46 def find_file(file):
47     """Find matching filenames in the current directory and its subdirectories,
48     and return a list of matching filenames.
49     """
50     matches = []
51     for root, dirnames, filenames in os.walk('.'):
52         for filename in fnmatch.filter(filenames, file):
53             matches.append(os.path.join(root, filename))
54     return matches
55 
56 
57 def run(*commands, **kwargs):
58     """
59     Run one or more commands, and return ``(status, out, err)``.
60     If more than one command is given, then this is equivalent to
61     chaining them together with ``&&``; if all commands succeed, then
62     ``(status, out, err)`` will represent the last successful command.
63     If one command failed, then ``(status, out, err)`` will represent
64     the failed command.
65     """
66     environment = os.environ.copy()
67     environment['READTHEDOCS'] = 'True'
68     if 'DJANGO_SETTINGS_MODULE' in environment:
69         del environment['DJANGO_SETTINGS_MODULE']
70     if 'PYTHONPATH' in environment:
71         del environment['PYTHONPATH']
72     cwd = os.getcwd()
73     if not commands:
74         raise ValueError("run() requires one or more command-line strings")
75     shell = kwargs.get('shell', False)
76 
77     for command in commands:
78         if shell:
79             log.info("Running commands in a shell")
80             run_command = command
81         else:
82             run_command = command.split()
83         log.info("Running: '%s' [%s]" % (command, cwd))
84         try:
85             p = subprocess.Popen(run_command, shell=shell, cwd=cwd,
86                                  stdout=subprocess.PIPE,
87                                  stderr=subprocess.PIPE, env=environment)
88 
89             out, err = p.communicate()
90             ret = p.returncode
91         except:
92             out = ''
93             err = traceback.format_exc()
94             ret = -1
95             log.error("Command failed", exc_info=True)
96 
97     return (ret, out, err)
98 
99 
100 def safe_write(filename, contents):
101     """Write ``contents`` to the given ``filename``. If the filename's
102     directory does not exist, it is created. Contents are written as UTF-8,
103     ignoring any characters that cannot be encoded as UTF-8.
104     """
105     dirname = os.path.dirname(filename)
106     if not os.path.exists(dirname):
107         os.makedirs(dirname)
108     with open(filename, 'w') as fh:
109         fh.write(contents.encode('utf-8', 'ignore'))
110         fh.close()
111 
112 
113 def mkversion(version_obj):
114     try:
115         if hasattr(version_obj, 'slug'):
116             ver = NormalizedVersion(
117                 suggest_normalized_version(version_obj.slug)
118             )
119         else:
120             ver = NormalizedVersion(
121                 suggest_normalized_version(version_obj['slug'])
122             )
123         return ver
124     except TypeError:
125         return None
126 
127 
128 def highest_version(version_list):
129     highest = [None, None]
130     for version in version_list:
131         ver = mkversion(version)
132         if not ver:
133             continue
134         elif highest[1] and ver:
135             # If there's a highest, and no version, we don't need to set
136             # anything
137             if ver > highest[1]:
138                 highest = [version, ver]
139         else:
140             highest = [version, ver]
141     return highest
142 
143 
144 def purge_version(version, mainsite=False, subdomain=False, cname=False):
145     varnish_servers = getattr(settings, 'VARNISH_SERVERS', None)
146     h = Http()
147     if varnish_servers:
148         for server in varnish_servers:
149             if subdomain:
150                 #Send a request to the Server, to purge the URL of the Host.
151                 host = "%s.readthedocs.org" % version.project.slug
152                 headers = {'Host': host}
153                 url = "/en/%s/*" % version.slug
154                 to_purge = "http://%s%s" % (server, url)
155                 log.info("Purging %s on %s" % (url, host))
156                 h.request(to_purge, method="PURGE", headers=headers)
157             if mainsite:
158                 headers = {'Host': "readthedocs.org"}
159                 url = "/docs/%s/en/%s/*" % (version.project.slug, version.slug)
160                 to_purge = "http://%s%s" % (server, url)
161                 log.info("Purging %s on readthedocs.org" % url)
162                 h.request(to_purge, method="PURGE", headers=headers)
163                 root_url = "/docs/%s/" % version.project.slug
164                 to_purge = "http://%s%s" % (server, root_url)
165                 log.info("Purging %s on readthedocs.org" % root_url)
166                 h.request(to_purge, method="PURGE", headers=headers)
167             if cname:
168                 redis_conn = redis.Redis(**settings.REDIS)
169                 for cnamed in redis_conn.smembers('rtd_slug:v1:%s'
170                                                   % version.project.slug):
171                     headers = {'Host': cnamed}
172                     url = "/en/%s/*" % version.slug
173                     to_purge = "http://%s%s" % (server, url)
174                     log.info("Purging %s on %s" % (url, cnamed))
175                     h.request(to_purge, method="PURGE", headers=headers)
176                     root_url = "/"
177                     to_purge = "http://%s%s" % (server, root_url)
178                     log.info("Purging %s on %s" % (root_url, cnamed))
179                     h.request(to_purge, method="PURGE", headers=headers)
180 
181 
182 class DictObj(object):
183     def __getattr__(self, attr):
184         return self.__dict__.get(attr)
185 
186 # Prevent saving the temporary Project instance
187 def _new_save(*args, **kwargs):
188     log.warning("Called save on a non-real object.")
189     return 0
190 
191 def make_api_version(version_data):
192     from builds.models import Version
193     for key in ['resource_uri', 'absolute_url', 'downloads']:
194         if key in version_data:
195             del version_data[key]
196     project_data = version_data['project']
197     project = make_api_project(project_data)
198     version_data['project'] = project
199     ver = Version(**version_data)
200     ver.save = _new_save
201 
202     return ver
203 
204 
205 def make_api_project(project_data):
206     from projects.models import Project
207     for key in ['users', 'resource_uri', 'absolute_url', 'downloads', 'main_language_project', 'related_projects']:
208         if key in project_data:
209             del project_data[key]
210     project = Project(**project_data)
211     project.save = _new_save
212     return project
213 
214 
215 def github_paginate(client, url):
216     """
217     Scans trough all github paginates results and returns the concatenated
218     list of results.
219 
220     :param client: requests client instance
221     :param url: start url to get the data from.
222 
223     See https://developer.github.com/v3/#pagination
224     """
225     result = []
226     while url:
227         r = session.get(url)
228         result.extend(r.json())
229         url = r.links.get('next')
230     return result
231
```
--- 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/projects/utils.py b/readthedocs/projects/utils.py
--- a/readthedocs/projects/utils.py
+++ b/readthedocs/projects/utils.py
@@ -69,6 +69,10 @@
         del environment['DJANGO_SETTINGS_MODULE']
     if 'PYTHONPATH' in environment:
         del environment['PYTHONPATH']
+    # Remove PYTHONHOME env variable if set, otherwise pip install of requirements
+    # into virtualenv will install incorrectly
+    if 'PYTHONHOME' in environment:
+        del environment['PYTHONHOME']
     cwd = os.getcwd()
     if not commands:
         raise ValueError("run() requires one or more command-line strings")

{"golden_diff": "diff --git a/readthedocs/projects/utils.py b/readthedocs/projects/utils.py\n--- a/readthedocs/projects/utils.py\n+++ b/readthedocs/projects/utils.py\n@@ -69,6 +69,10 @@\n         del environment['DJANGO_SETTINGS_MODULE']\n     if 'PYTHONPATH' in environment:\n         del environment['PYTHONPATH']\n+    # Remove PYTHONHOME env variable if set, otherwise pip install of requirements\n+    # into virtualenv will install incorrectly\n+    if 'PYTHONHOME' in environment:\n+        del environment['PYTHONHOME']\n     cwd = os.getcwd()\n     if not commands:\n         raise ValueError(\"run() requires one or more command-line strings\")\n", "issue": "Pip install failing to install sphinx when PYTHON_HOME is set\nIf the env variable PYTHON_HOME exists, pip install is failing to install spinx into the virtualenv.\n\n", "before_files": [{"content": "\"\"\"Utility functions used by projects.\n\"\"\"\nimport fnmatch\nimport os\nimport re\nimport subprocess\nimport traceback\nimport logging\nfrom httplib2 import Http\n\nfrom django.conf import settings\nfrom distutils2.version import NormalizedVersion, suggest_normalized_version\nimport redis\n\nfrom builds.constants import LATEST\n\n\nlog = logging.getLogger(__name__)\n\ndef version_from_slug(slug, version):\n    from projects import tasks\n    from builds.models import Version\n    from tastyapi import apiv2 as api\n    if getattr(settings, 'DONT_HIT_DB', True):\n        version_data = api.version().get(project=slug, slug=version)['results'][0]\n        v = tasks.make_api_version(version_data)\n    else:\n        v = Version.objects.get(project__slug=slug, slug=version)\n    return v\n\ndef symlink(project, version=LATEST):\n    from projects import symlinks\n    v = version_from_slug(project, version)\n    log.info(\"Symlinking %s\" % v)\n    symlinks.symlink_subprojects(v)\n    symlinks.symlink_cnames(v)\n    symlinks.symlink_translations(v)\n\ndef update_static_metadata(project_pk):\n    \"\"\"\n    This is here to avoid circular imports in models.py\n    \"\"\"\n    from projects import tasks\n    tasks.update_static_metadata.delay(project_pk)\n\ndef find_file(file):\n    \"\"\"Find matching filenames in the current directory and its subdirectories,\n    and return a list of matching filenames.\n    \"\"\"\n    matches = []\n    for root, dirnames, filenames in os.walk('.'):\n        for filename in fnmatch.filter(filenames, file):\n            matches.append(os.path.join(root, filename))\n    return matches\n\n\ndef run(*commands, **kwargs):\n    \"\"\"\n    Run one or more commands, and return ``(status, out, err)``.\n    If more than one command is given, then this is equivalent to\n    chaining them together with ``&&``; if all commands succeed, then\n    ``(status, out, err)`` will represent the last successful command.\n    If one command failed, then ``(status, out, err)`` will represent\n    the failed command.\n    \"\"\"\n    environment = os.environ.copy()\n    environment['READTHEDOCS'] = 'True'\n    if 'DJANGO_SETTINGS_MODULE' in environment:\n        del environment['DJANGO_SETTINGS_MODULE']\n    if 'PYTHONPATH' in environment:\n        del environment['PYTHONPATH']\n    cwd = os.getcwd()\n    if not commands:\n        raise ValueError(\"run() requires one or more command-line strings\")\n    shell = kwargs.get('shell', False)\n\n    for command in commands:\n        if shell:\n            log.info(\"Running commands in a shell\")\n            run_command = command\n        else:\n            run_command = command.split()\n        log.info(\"Running: '%s' [%s]\" % (command, cwd))\n        try:\n            p = subprocess.Popen(run_command, shell=shell, cwd=cwd,\n                                 stdout=subprocess.PIPE,\n                                 stderr=subprocess.PIPE, env=environment)\n\n            out, err = p.communicate()\n            ret = p.returncode\n        except:\n            out = ''\n            err = traceback.format_exc()\n            ret = -1\n            log.error(\"Command failed\", exc_info=True)\n\n    return (ret, out, err)\n\n\ndef safe_write(filename, contents):\n    \"\"\"Write ``contents`` to the given ``filename``. If the filename's\n    directory does not exist, it is created. Contents are written as UTF-8,\n    ignoring any characters that cannot be encoded as UTF-8.\n    \"\"\"\n    dirname = os.path.dirname(filename)\n    if not os.path.exists(dirname):\n        os.makedirs(dirname)\n    with open(filename, 'w') as fh:\n        fh.write(contents.encode('utf-8', 'ignore'))\n        fh.close()\n\n\ndef mkversion(version_obj):\n    try:\n        if hasattr(version_obj, 'slug'):\n            ver = NormalizedVersion(\n                suggest_normalized_version(version_obj.slug)\n            )\n        else:\n            ver = NormalizedVersion(\n                suggest_normalized_version(version_obj['slug'])\n            )\n        return ver\n    except TypeError:\n        return None\n\n\ndef highest_version(version_list):\n    highest = [None, None]\n    for version in version_list:\n        ver = mkversion(version)\n        if not ver:\n            continue\n        elif highest[1] and ver:\n            # If there's a highest, and no version, we don't need to set\n            # anything\n            if ver > highest[1]:\n                highest = [version, ver]\n        else:\n            highest = [version, ver]\n    return highest\n\n\ndef purge_version(version, mainsite=False, subdomain=False, cname=False):\n    varnish_servers = getattr(settings, 'VARNISH_SERVERS', None)\n    h = Http()\n    if varnish_servers:\n        for server in varnish_servers:\n            if subdomain:\n                #Send a request to the Server, to purge the URL of the Host.\n                host = \"%s.readthedocs.org\" % version.project.slug\n                headers = {'Host': host}\n                url = \"/en/%s/*\" % version.slug\n                to_purge = \"http://%s%s\" % (server, url)\n                log.info(\"Purging %s on %s\" % (url, host))\n                h.request(to_purge, method=\"PURGE\", headers=headers)\n            if mainsite:\n                headers = {'Host': \"readthedocs.org\"}\n                url = \"/docs/%s/en/%s/*\" % (version.project.slug, version.slug)\n                to_purge = \"http://%s%s\" % (server, url)\n                log.info(\"Purging %s on readthedocs.org\" % url)\n                h.request(to_purge, method=\"PURGE\", headers=headers)\n                root_url = \"/docs/%s/\" % version.project.slug\n                to_purge = \"http://%s%s\" % (server, root_url)\n                log.info(\"Purging %s on readthedocs.org\" % root_url)\n                h.request(to_purge, method=\"PURGE\", headers=headers)\n            if cname:\n                redis_conn = redis.Redis(**settings.REDIS)\n                for cnamed in redis_conn.smembers('rtd_slug:v1:%s'\n                                                  % version.project.slug):\n                    headers = {'Host': cnamed}\n                    url = \"/en/%s/*\" % version.slug\n                    to_purge = \"http://%s%s\" % (server, url)\n                    log.info(\"Purging %s on %s\" % (url, cnamed))\n                    h.request(to_purge, method=\"PURGE\", headers=headers)\n                    root_url = \"/\"\n                    to_purge = \"http://%s%s\" % (server, root_url)\n                    log.info(\"Purging %s on %s\" % (root_url, cnamed))\n                    h.request(to_purge, method=\"PURGE\", headers=headers)\n\n\nclass DictObj(object):\n    def __getattr__(self, attr):\n        return self.__dict__.get(attr)\n\n# Prevent saving the temporary Project instance\ndef _new_save(*args, **kwargs):\n    log.warning(\"Called save on a non-real object.\")\n    return 0\n\ndef make_api_version(version_data):\n    from builds.models import Version\n    for key in ['resource_uri', 'absolute_url', 'downloads']:\n        if key in version_data:\n            del version_data[key]\n    project_data = version_data['project']\n    project = make_api_project(project_data)\n    version_data['project'] = project\n    ver = Version(**version_data)\n    ver.save = _new_save\n\n    return ver\n\n\ndef make_api_project(project_data):\n    from projects.models import Project\n    for key in ['users', 'resource_uri', 'absolute_url', 'downloads', 'main_language_project', 'related_projects']:\n        if key in project_data:\n            del project_data[key]\n    project = Project(**project_data)\n    project.save = _new_save\n    return project\n\n\ndef github_paginate(client, url):\n    \"\"\"\n    Scans trough all github paginates results and returns the concatenated\n    list of results.\n\n    :param client: requests client instance\n    :param url: start url to get the data from.\n\n    See https://developer.github.com/v3/#pagination\n    \"\"\"\n    result = []\n    while url:\n        r = session.get(url)\n        result.extend(r.json())\n        url = r.links.get('next')\n    return result\n", "path": "readthedocs/projects/utils.py"}], "after_files": [{"content": "\"\"\"Utility functions used by projects.\n\"\"\"\nimport fnmatch\nimport os\nimport re\nimport subprocess\nimport traceback\nimport logging\nfrom httplib2 import Http\n\nfrom django.conf import settings\nfrom distutils2.version import NormalizedVersion, suggest_normalized_version\nimport redis\n\nfrom builds.constants import LATEST\n\n\nlog = logging.getLogger(__name__)\n\ndef version_from_slug(slug, version):\n    from projects import tasks\n    from builds.models import Version\n    from tastyapi import apiv2 as api\n    if getattr(settings, 'DONT_HIT_DB', True):\n        version_data = api.version().get(project=slug, slug=version)['results'][0]\n        v = tasks.make_api_version(version_data)\n    else:\n        v = Version.objects.get(project__slug=slug, slug=version)\n    return v\n\ndef symlink(project, version=LATEST):\n    from projects import symlinks\n    v = version_from_slug(project, version)\n    log.info(\"Symlinking %s\" % v)\n    symlinks.symlink_subprojects(v)\n    symlinks.symlink_cnames(v)\n    symlinks.symlink_translations(v)\n\ndef update_static_metadata(project_pk):\n    \"\"\"\n    This is here to avoid circular imports in models.py\n    \"\"\"\n    from projects import tasks\n    tasks.update_static_metadata.delay(project_pk)\n\ndef find_file(file):\n    \"\"\"Find matching filenames in the current directory and its subdirectories,\n    and return a list of matching filenames.\n    \"\"\"\n    matches = []\n    for root, dirnames, filenames in os.walk('.'):\n        for filename in fnmatch.filter(filenames, file):\n            matches.append(os.path.join(root, filename))\n    return matches\n\n\ndef run(*commands, **kwargs):\n    \"\"\"\n    Run one or more commands, and return ``(status, out, err)``.\n    If more than one command is given, then this is equivalent to\n    chaining them together with ``&&``; if all commands succeed, then\n    ``(status, out, err)`` will represent the last successful command.\n    If one command failed, then ``(status, out, err)`` will represent\n    the failed command.\n    \"\"\"\n    environment = os.environ.copy()\n    environment['READTHEDOCS'] = 'True'\n    if 'DJANGO_SETTINGS_MODULE' in environment:\n        del environment['DJANGO_SETTINGS_MODULE']\n    if 'PYTHONPATH' in environment:\n        del environment['PYTHONPATH']\n    # Remove PYTHONHOME env variable if set, otherwise pip install of requirements\n    # into virtualenv will install incorrectly\n    if 'PYTHONHOME' in environment:\n        del environment['PYTHONHOME']\n    cwd = os.getcwd()\n    if not commands:\n        raise ValueError(\"run() requires one or more command-line strings\")\n    shell = kwargs.get('shell', False)\n\n    for command in commands:\n        if shell:\n            log.info(\"Running commands in a shell\")\n            run_command = command\n        else:\n            run_command = command.split()\n        log.info(\"Running: '%s' [%s]\" % (command, cwd))\n        try:\n            p = subprocess.Popen(run_command, shell=shell, cwd=cwd,\n                                 stdout=subprocess.PIPE,\n                                 stderr=subprocess.PIPE, env=environment)\n\n            out, err = p.communicate()\n            ret = p.returncode\n        except:\n            out = ''\n            err = traceback.format_exc()\n            ret = -1\n            log.error(\"Command failed\", exc_info=True)\n\n    return (ret, out, err)\n\n\ndef safe_write(filename, contents):\n    \"\"\"Write ``contents`` to the given ``filename``. If the filename's\n    directory does not exist, it is created. Contents are written as UTF-8,\n    ignoring any characters that cannot be encoded as UTF-8.\n    \"\"\"\n    dirname = os.path.dirname(filename)\n    if not os.path.exists(dirname):\n        os.makedirs(dirname)\n    with open(filename, 'w') as fh:\n        fh.write(contents.encode('utf-8', 'ignore'))\n        fh.close()\n\n\ndef mkversion(version_obj):\n    try:\n        if hasattr(version_obj, 'slug'):\n            ver = NormalizedVersion(\n                suggest_normalized_version(version_obj.slug)\n            )\n        else:\n            ver = NormalizedVersion(\n                suggest_normalized_version(version_obj['slug'])\n            )\n        return ver\n    except TypeError:\n        return None\n\n\ndef highest_version(version_list):\n    highest = [None, None]\n    for version in version_list:\n        ver = mkversion(version)\n        if not ver:\n            continue\n        elif highest[1] and ver:\n            # If there's a highest, and no version, we don't need to set\n            # anything\n            if ver > highest[1]:\n                highest = [version, ver]\n        else:\n            highest = [version, ver]\n    return highest\n\n\ndef purge_version(version, mainsite=False, subdomain=False, cname=False):\n    varnish_servers = getattr(settings, 'VARNISH_SERVERS', None)\n    h = Http()\n    if varnish_servers:\n        for server in varnish_servers:\n            if subdomain:\n                #Send a request to the Server, to purge the URL of the Host.\n                host = \"%s.readthedocs.org\" % version.project.slug\n                headers = {'Host': host}\n                url = \"/en/%s/*\" % version.slug\n                to_purge = \"http://%s%s\" % (server, url)\n                log.info(\"Purging %s on %s\" % (url, host))\n                h.request(to_purge, method=\"PURGE\", headers=headers)\n            if mainsite:\n                headers = {'Host': \"readthedocs.org\"}\n                url = \"/docs/%s/en/%s/*\" % (version.project.slug, version.slug)\n                to_purge = \"http://%s%s\" % (server, url)\n                log.info(\"Purging %s on readthedocs.org\" % url)\n                h.request(to_purge, method=\"PURGE\", headers=headers)\n                root_url = \"/docs/%s/\" % version.project.slug\n                to_purge = \"http://%s%s\" % (server, root_url)\n                log.info(\"Purging %s on readthedocs.org\" % root_url)\n                h.request(to_purge, method=\"PURGE\", headers=headers)\n            if cname:\n                redis_conn = redis.Redis(**settings.REDIS)\n                for cnamed in redis_conn.smembers('rtd_slug:v1:%s'\n                                                  % version.project.slug):\n                    headers = {'Host': cnamed}\n                    url = \"/en/%s/*\" % version.slug\n                    to_purge = \"http://%s%s\" % (server, url)\n                    log.info(\"Purging %s on %s\" % (url, cnamed))\n                    h.request(to_purge, method=\"PURGE\", headers=headers)\n                    root_url = \"/\"\n                    to_purge = \"http://%s%s\" % (server, root_url)\n                    log.info(\"Purging %s on %s\" % (root_url, cnamed))\n                    h.request(to_purge, method=\"PURGE\", headers=headers)\n\n\nclass DictObj(object):\n    def __getattr__(self, attr):\n        return self.__dict__.get(attr)\n\n# Prevent saving the temporary Project instance\ndef _new_save(*args, **kwargs):\n    log.warning(\"Called save on a non-real object.\")\n    return 0\n\ndef make_api_version(version_data):\n    from builds.models import Version\n    for key in ['resource_uri', 'absolute_url', 'downloads']:\n        if key in version_data:\n            del version_data[key]\n    project_data = version_data['project']\n    project = make_api_project(project_data)\n    version_data['project'] = project\n    ver = Version(**version_data)\n    ver.save = _new_save\n\n    return ver\n\n\ndef make_api_project(project_data):\n    from projects.models import Project\n    for key in ['users', 'resource_uri', 'absolute_url', 'downloads', 'main_language_project', 'related_projects']:\n        if key in project_data:\n            del project_data[key]\n    project = Project(**project_data)\n    project.save = _new_save\n    return project\n\n\ndef github_paginate(client, url):\n    \"\"\"\n    Scans trough all github paginates results and returns the concatenated\n    list of results.\n\n    :param client: requests client instance\n    :param url: start url to get the data from.\n\n    See https://developer.github.com/v3/#pagination\n    \"\"\"\n    result = []\n    while url:\n        r = session.get(url)\n        result.extend(r.json())\n        url = r.links.get('next')\n    return result\n", "path": "readthedocs/projects/utils.py"}]}