Skip to content

Commit ac7001d

Browse files
Using STABLE constant instead of string 'stable' where applicable.
1 parent 3f7a96d commit ac7001d

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

readthedocs/builds/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@
2424
('tag', _('Tag')),
2525
('unknown', _('Unknown')),
2626
)
27+
28+
STABLE = 'stable'
29+
STABLE_VERBOSE_NAME = 'stable'

readthedocs/projects/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ def save(self, *args, **kwargs):
292292
if not self.versions.filter(slug='latest').exists():
293293
self.versions.create(
294294
slug='latest', verbose_name='latest', machine=True, type='branch', active=True, identifier=branch)
295-
# if not self.versions.filter(slug='stable').exists():
296-
# self.versions.create(slug='stable', verbose_name='stable', type='branch', active=True, identifier=branch)
295+
# if not self.versions.filter(slug=STABLE).exists():
296+
# self.versions.create_stable(type='branch', identifier=branch)
297297
except Exception:
298298
log.error('Error creating default branches', exc_info=True)
299299

readthedocs/projects/tasks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from projects.models import ImportedFile, Project
2626
from projects.utils import run, make_api_version, make_api_project
2727
from projects.constants import LOG_TEMPLATE
28+
from builds.constants import STABLE
2829
from projects import symlinks
2930
from privacy.loader import Syncer
3031
from tastyapi import api, apiv2
@@ -650,7 +651,7 @@ def finish_build(version_pk, build_pk, hostname=None, html=False,
650651
update_static_metadata.delay(version.project.pk)
651652
fileify.delay(version.pk, commit=build.commit)
652653
update_search.delay(version.pk, commit=build.commit)
653-
if not html and version.slug != 'stable' and build.exit_code != 423:
654+
if not html and version.slug != STABLE and build.exit_code != 423:
654655
send_notifications.delay(version.pk, build_pk=build.pk)
655656

656657

readthedocs/projects/templatetags/projects_tags.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from distutils2.version import NormalizedVersion
44
from projects.utils import mkversion
5+
from builds.constants import STABLE
56

67
register = template.Library()
78

@@ -11,7 +12,7 @@ def make_version(version):
1112
if not ver:
1213
if version.slug == 'latest':
1314
return NormalizedVersion('99999.0', error_on_huge_major_num=False)
14-
elif version.slug == 'stable':
15+
elif version.slug == STABLE:
1516
return NormalizedVersion('9999.0', error_on_huge_major_num=False)
1617
else:
1718
return NormalizedVersion('999.0', error_on_huge_major_num=False)

readthedocs/restapi/views/model_views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from builds.models import Build, Version
1212
from core.utils import trigger_build
1313
from oauth import utils as oauth_utils
14+
from builds.constants import STABLE
1415
from projects.filters import ProjectFilter
1516
from projects.models import Project, EmailHook
1617
from restapi.permissions import APIPermission
@@ -111,7 +112,7 @@ def sync_versions(self, request, **kwargs):
111112
new_stable = project.versions.get(verbose_name=new_stable_slug)
112113

113114
# Update stable version
114-
stable = project.versions.filter(slug='stable').first()
115+
stable = project.versions.filter(slug=STABLE).first()
115116
if stable:
116117
if (new_stable.identifier != stable.identifier) and (stable.machine is True):
117118
stable.identifier = new_stable.identifier
@@ -120,7 +121,7 @@ def sync_versions(self, request, **kwargs):
120121
trigger_build(project=project, version=stable)
121122
else:
122123
log.info("Creating new stable version: {project}:{version}".format(project=project.slug, version=new_stable.identifier))
123-
version = project.versions.create(slug='stable', verbose_name='stable', machine=True, type=new_stable.type, active=True, identifier=new_stable.identifier)
124+
version = project.versions.create(slug=STABLE, verbose_name=STABLE_VERBOSE_NAME, machine=True, type=new_stable.type, active=True, identifier=new_stable.identifier)
124125
trigger_build(project=project, version=version)
125126

126127
# Build new tag if enabled

readthedocs/rtd_tests/tests/test_sync_versions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.test import TestCase
44

55
from builds.models import Version
6+
from builds.constants import STABLE
67
from projects.models import Project
78

89

@@ -69,14 +70,14 @@ def test_stable_versions(self):
6970
self.assertRaises(
7071
Version.DoesNotExist,
7172
Version.objects.get,
72-
slug='stable'
73+
slug=STABLE
7374
)
7475
self.client.post(
7576
'/api/v2/project/%s/sync_versions/' % self.pip.pk,
7677
data=json.dumps(version_post_data),
7778
content_type='application/json',
7879
)
79-
version_stable = Version.objects.get(slug='stable')
80+
version_stable = Version.objects.get(slug=STABLE)
8081
self.assertTrue(version_stable.active)
8182
self.assertEqual(version_stable.identifier, '0.9')
8283

0 commit comments

Comments
 (0)