Skip to content

Commit e99673a

Browse files
committed
Minor refactor
1 parent 05c2aed commit e99673a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

readthedocs/doc_builder/python_environments.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from builtins import object
1212

1313
from django.conf import settings
14-
from packaging.version import Version
1514

1615
from readthedocs.doc_builder.config import ConfigWrapper
16+
from readthedocs.doc_builder.constants import DOCKER_IMAGE
1717
from readthedocs.doc_builder.loader import get_builder_class
1818
from readthedocs.projects.constants import LOG_TEMPLATE
1919
from readthedocs.projects.models import Feature
@@ -51,7 +51,7 @@ def delete_existing_build_dir(self):
5151
self._log('Removing existing build directory')
5252
shutil.rmtree(build_dir)
5353

54-
def delete_existing_env_dir(self):
54+
def delete_existing_venv_dir(self):
5555
venv_dir = self.venv_path()
5656
# Handle deleting old venv dir
5757
if os.path.exists(venv_dir):
@@ -130,32 +130,37 @@ def is_obsolete(self):
130130
try:
131131
with open(self.environment_json_path(), 'r') as fpath:
132132
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']
135135
except (TypeError, KeyError, ValueError):
136+
log.error('Unable to read/parse environment.json file')
136137
return False
137138

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+
138142
# If the user define the Python version just as a major version
139143
# (e.g. ``2`` or ``3``) we won't know exactly which exact version was
140144
# used to create the venv but we can still compare it against the new
141145
# one coming from the project version config.
142146
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,
146149
])
147150

148151
def save_environment_json(self):
149152
"""
150153
Save on disk Python and build image versions used to create the venv.
151154
"""
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+
152158
data = {
153159
'python': {
154160
'version': self.config.python_version,
155161
},
156162
'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,
159164
},
160165
}
161166
with open(self.environment_json_path(), 'w') as fpath:

0 commit comments

Comments
 (0)