|
11 | 11 | from builtins import object
|
12 | 12 |
|
13 | 13 | from django.conf import settings
|
14 |
| -from packaging.version import Version |
15 | 14 |
|
16 | 15 | from readthedocs.doc_builder.config import ConfigWrapper
|
| 16 | +from readthedocs.doc_builder.constants import DOCKER_IMAGE |
17 | 17 | from readthedocs.doc_builder.loader import get_builder_class
|
18 | 18 | from readthedocs.projects.constants import LOG_TEMPLATE
|
19 | 19 | from readthedocs.projects.models import Feature
|
@@ -51,7 +51,7 @@ def delete_existing_build_dir(self):
|
51 | 51 | self._log('Removing existing build directory')
|
52 | 52 | shutil.rmtree(build_dir)
|
53 | 53 |
|
54 |
| - def delete_existing_env_dir(self): |
| 54 | + def delete_existing_venv_dir(self): |
55 | 55 | venv_dir = self.venv_path()
|
56 | 56 | # Handle deleting old venv dir
|
57 | 57 | if os.path.exists(venv_dir):
|
@@ -130,32 +130,37 @@ def is_obsolete(self):
|
130 | 130 | try:
|
131 | 131 | with open(self.environment_json_path(), 'r') as fpath:
|
132 | 132 | environment_conf = json.load(fpath)
|
133 |
| - env_python_version = Version(environment_conf['python']['version']) |
134 |
| - env_build_image = Version(environment_conf['build']['image']) |
| 133 | + env_python_version = environment_conf['python']['version'] |
| 134 | + env_build_image = environment_conf['build']['image'] |
135 | 135 | except (TypeError, KeyError, ValueError):
|
| 136 | + log.error('Unable to read/parse environment.json file') |
136 | 137 | return False
|
137 | 138 |
|
| 139 | + # TODO: remove getattr when https://github.com/rtfd/readthedocs.org/pull/3339 got merged |
| 140 | + build_image = getattr(self.config, 'build_image', self.version.project.container_image) or DOCKER_IMAGE |
| 141 | + |
138 | 142 | # If the user define the Python version just as a major version
|
139 | 143 | # (e.g. ``2`` or ``3``) we won't know exactly which exact version was
|
140 | 144 | # used to create the venv but we can still compare it against the new
|
141 | 145 | # one coming from the project version config.
|
142 | 146 | return any([
|
143 |
| - env_python_version != Version(self.config.python_version), |
144 |
| - # TODO: remove getattr when https://github.com/rtfd/readthedocs.org/pull/3339 got merged |
145 |
| - env_build_image != getattr(self.config, 'build_image', self.version.project.container_image), |
| 147 | + env_python_version != self.config.python_version, |
| 148 | + env_build_image != build_image, |
146 | 149 | ])
|
147 | 150 |
|
148 | 151 | def save_environment_json(self):
|
149 | 152 | """
|
150 | 153 | Save on disk Python and build image versions used to create the venv.
|
151 | 154 | """
|
| 155 | + # TODO: remove getattr when https://github.com/rtfd/readthedocs.org/pull/3339 got merged |
| 156 | + build_image = getattr(self.config, 'build_image', self.version.project.container_image) or DOCKER_IMAGE |
| 157 | + |
152 | 158 | data = {
|
153 | 159 | 'python': {
|
154 | 160 | 'version': self.config.python_version,
|
155 | 161 | },
|
156 | 162 | 'build': {
|
157 |
| - # TODO: remove getattr when https://github.com/rtfd/readthedocs.org/pull/3339 got merged |
158 |
| - 'image': getattr(self.config, 'build_image', self.version.project.container_image), |
| 163 | + 'image': build_image, |
159 | 164 | },
|
160 | 165 | }
|
161 | 166 | with open(self.environment_json_path(), 'w') as fpath:
|
|
0 commit comments