Skip to content

Commit

Permalink
Save Docker image data in JSON file only for DockerBuildEnvironment (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
humitos authored and agjohnson committed Apr 5, 2018
1 parent 5cb3ba6 commit 2c9e62d
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions readthedocs/doc_builder/python_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import logging
import os
import shutil
import six
from builtins import object, open

import six
from django.conf import settings

from readthedocs.doc_builder.config import ConfigWrapper
from readthedocs.doc_builder.constants import DOCKER_IMAGE
from readthedocs.doc_builder.environments import DockerBuildEnvironment
from readthedocs.doc_builder.loader import get_builder_class
from readthedocs.projects.constants import LOG_TEMPLATE
from readthedocs.projects.models import Feature
Expand Down Expand Up @@ -147,30 +148,41 @@ def is_obsolete(self):
env_build_image = env_build.get('image', None)
env_build_hash = env_build.get('hash', None)

build_image = self.config.build_image or DOCKER_IMAGE
if isinstance(self.build_env, DockerBuildEnvironment):
build_image = self.config.build_image or DOCKER_IMAGE
image_hash = self.build_env.image_hash
else:
# e.g. LocalBuildEnvironment
build_image = None
image_hash = None

# If the user define the Python version just as a major version
# (e.g. ``2`` or ``3``) we won't know exactly which exact version was
# used to create the venv but we can still compare it against the new
# one coming from the project version config.
return any([
env_python_version != self.config.python_full_version,
env_build_image != build_image,
env_build_hash != self.build_env.image_hash,
env_build_hash != image_hash,
])

def save_environment_json(self):
"""Save on disk Python and build image versions used to create the venv."""
build_image = self.config.build_image or DOCKER_IMAGE
data = {
'python': {
'version': self.config.python_full_version,
},
'build': {
'image': build_image,
'hash': self.build_env.image_hash,
},
}

if isinstance(self.build_env, DockerBuildEnvironment):
build_image = self.config.build_image or DOCKER_IMAGE
data.update({
'build': {
'image': build_image,
'hash': self.build_env.image_hash,
},
})

with open(self.environment_json_path(), 'w') as fpath:
# Compatibility for Py2 and Py3. ``io.TextIOWrapper`` expects
# unicode but ``json.dumps`` returns str in Py2.
Expand Down

0 comments on commit 2c9e62d

Please sign in to comment.