Skip to content

Commit

Permalink
Make the STABLE and LATEST constants overridable
Browse files Browse the repository at this point in the history
Moving them to settings and making life easier for downstreams
that want to use different labels.
  • Loading branch information
xrmx committed May 16, 2018
1 parent 696a25f commit a3ae8de
Show file tree
Hide file tree
Showing 29 changed files with 148 additions and 140 deletions.
4 changes: 2 additions & 2 deletions readthedocs/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from builtins import object

import redis
from django.conf import settings
from django.conf.urls import url
from django.contrib.auth.models import User
from django.core.cache import cache
Expand All @@ -18,7 +19,6 @@
from tastypie.resources import ModelResource
from tastypie.utils import dict_strip_unicode_keys, trailing_slash

from readthedocs.builds.constants import LATEST
from readthedocs.builds.models import Version
from readthedocs.core.utils import trigger_build
from readthedocs.projects.models import ImportedFile, Project
Expand Down Expand Up @@ -116,7 +116,7 @@ def get_object_list(self, request):

def build_version(self, request, **kwargs):
project = get_object_or_404(Project, slug=kwargs['project_slug'])
version = kwargs.get('version_slug', LATEST)
version = kwargs.get('version_slug', settings.LATEST)
version_obj = project.versions.get(slug=version)
trigger_build(project=project, version=version_obj)
return self.create_response(request, {'building': True})
Expand Down
13 changes: 0 additions & 13 deletions readthedocs/builds/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,3 @@
(TAG, _('Tag')),
(UNKNOWN, _('Unknown')),
)

LATEST = 'latest'
LATEST_VERBOSE_NAME = 'latest'

STABLE = 'stable'
STABLE_VERBOSE_NAME = 'stable'

# Those names are specialcased version names. They do not correspond to
# branches/tags in a project's repository.
NON_REPOSITORY_VERSIONS = (
LATEST,
STABLE,
)
16 changes: 8 additions & 8 deletions readthedocs/builds/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from __future__ import absolute_import

from django.conf import settings
from django.db import models

from .constants import (BRANCH, TAG, LATEST, LATEST_VERBOSE_NAME, STABLE,
STABLE_VERBOSE_NAME)
from .constants import BRANCH, TAG
from .querysets import VersionQuerySet
from readthedocs.core.utils.extend import (SettingsOverrideObject,
get_override_class)
Expand Down Expand Up @@ -36,23 +36,23 @@ def from_queryset(cls, queryset_class, class_name=None):

def create_stable(self, **kwargs):
defaults = {
'slug': STABLE,
'verbose_name': STABLE_VERBOSE_NAME,
'slug': settings.STABLE,
'verbose_name': settings.STABLE_VERBOSE_NAME,
'machine': True,
'active': True,
'identifier': STABLE,
'identifier': settings.STABLE,
'type': TAG,
}
defaults.update(kwargs)
return self.create(**defaults)

def create_latest(self, **kwargs):
defaults = {
'slug': LATEST,
'verbose_name': LATEST_VERBOSE_NAME,
'slug': settings.LATEST,
'verbose_name': settings.LATEST_VERBOSE_NAME,
'machine': True,
'active': True,
'identifier': LATEST,
'identifier': settings.LATEST,
'type': BRANCH,
}
defaults.update(kwargs)
Expand Down
10 changes: 5 additions & 5 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
from readthedocs.projects.models import APIProject, Project

from .constants import (
BRANCH, BUILD_STATE, BUILD_STATE_FINISHED, BUILD_TYPES, LATEST,
NON_REPOSITORY_VERSIONS, STABLE, TAG, VERSION_TYPES)
BRANCH, BUILD_STATE, BUILD_STATE_FINISHED, BUILD_TYPES,
TAG, VERSION_TYPES)
from .managers import VersionManager
from .querysets import BuildQuerySet, RelatedBuildQuerySet, VersionQuerySet
from .utils import (
Expand Down Expand Up @@ -119,12 +119,12 @@ def commit_name(self):
"""
# LATEST is special as it is usually a branch but does not contain the
# name in verbose_name.
if self.slug == LATEST:
if self.slug == settings.LATEST:
if self.project.default_branch:
return self.project.default_branch
return self.project.vcs_repo().fallback_branch

if self.slug == STABLE:
if self.slug == settings.STABLE:
if self.type == BRANCH:
# Special case, as we do not store the original branch name
# that the stable version works on. We can only interpolate the
Expand All @@ -136,7 +136,7 @@ def commit_name(self):
return self.identifier

# By now we must have handled all special versions.
assert self.slug not in NON_REPOSITORY_VERSIONS
assert self.slug not in settings.NON_REPOSITORY_VERSIONS

if self.type in (BRANCH, TAG):
# If this version is a branch or a tag, the verbose_name will
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/core/management/commands/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from __future__ import absolute_import
import logging

from django.conf import settings
from django.core.management.base import BaseCommand

from readthedocs.builds.constants import LATEST
from readthedocs.projects import tasks, utils


Expand All @@ -19,7 +19,7 @@ class Command(BaseCommand):
def handle(self, *args, **options):
if args:
for slug in args:
version = utils.version_from_slug(slug, LATEST)
version = utils.version_from_slug(slug, settings.LATEST)
tasks.SyncRepositoryTask().run(
version.pk,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from django.core.management.base import CommandError
from django.conf import settings

from readthedocs.builds.constants import LATEST
from readthedocs.builds.models import Version
from readthedocs.projects.tasks import update_search

Expand Down Expand Up @@ -38,7 +37,7 @@ def handle(self, *args, **options):
'No project with slug: {slug}'.format(slug=project))
log.info("Building all versions for %s", project)
elif getattr(settings, 'INDEX_ONLY_LATEST', True):
queryset = queryset.filter(slug=LATEST)
queryset = queryset.filter(slug=settings.LATEST)

for version in queryset:
log.info("Reindexing %s", version)
Expand Down
3 changes: 1 addition & 2 deletions readthedocs/core/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from future.backports.urllib.parse import urlparse
from celery import group, chord

from readthedocs.builds.constants import LATEST
from readthedocs.doc_builder.constants import DOCKER_LIMITS


Expand Down Expand Up @@ -90,7 +89,7 @@ def trigger_build(project, version=None, record=True, force=False, basic=False):
return None

if not version:
version = project.versions.get(slug=LATEST)
version = project.versions.get(slug=settings.LATEST)

kwargs = dict(
pk=project.pk,
Expand Down
8 changes: 4 additions & 4 deletions readthedocs/core/views/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import json
import re

from django.conf import settings
from django.http import HttpResponse, HttpResponseNotFound
from django.shortcuts import redirect
from django.views.decorators.csrf import csrf_exempt

from readthedocs.core.utils import trigger_build
from readthedocs.builds.constants import LATEST
from readthedocs.projects import constants
from readthedocs.projects.models import Project, Feature
from readthedocs.projects.tasks import SyncRepositoryTask
Expand Down Expand Up @@ -41,7 +41,7 @@ def _build_version(project, slug, already_built=()):
# short circuit versions that are default
# these will build at "latest", and thus won't be
# active
latest_version = project.versions.get(slug=LATEST)
latest_version = project.versions.get(slug=settings.LATEST)
trigger_build(project=project, version=latest_version, force=True)
log.info("(Version build) Building %s:%s",
project.slug, latest_version.slug)
Expand All @@ -51,7 +51,7 @@ def _build_version(project, slug, already_built=()):
trigger_build(project=project, version=slug_version, force=True)
log.info("(Version build) Building %s:%s",
project.slug, slug_version.slug)
return LATEST
return settings.LATEST
elif project.versions.exclude(active=True).filter(slug=slug).exists():
log.info("(Version build) Not Building %s", slug)
return None
Expand Down Expand Up @@ -124,7 +124,7 @@ def _build_url(url, projects, branches):
(built, not_building) = build_branches(project, branches)
if not built:
# Call SyncRepositoryTask to update tag/branch info
version = project.versions.get(slug=LATEST)
version = project.versions.get(slug=settings.LATEST)
sync_repository = SyncRepositoryTask()
sync_repository.apply_async(
args=(version.pk,),
Expand Down
Loading

0 comments on commit a3ae8de

Please sign in to comment.