Skip to content

Commit 2e89010

Browse files
committed
pre-commit run for modified files
1 parent 2f2bd2f commit 2e89010

File tree

21 files changed

+773
-760
lines changed

21 files changed

+773
-760
lines changed

readthedocs/builds/models.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
import logging
88
import os.path
99
import re
10-
from builtins import object
1110
from shutil import rmtree
1211

12+
from builtins import object
1313
from django.conf import settings
1414
from django.core.urlresolvers import reverse
1515
from django.db import models
1616
from django.utils.encoding import python_2_unicode_compatible
17-
from django.utils.translation import ugettext_lazy as _
1817
from django.utils.translation import ugettext
18+
from django.utils.translation import ugettext_lazy as _
1919
from guardian.shortcuts import assign
2020
from taggit.managers import TaggableManager
2121

@@ -148,7 +148,8 @@ def commit_name(self):
148148

149149
# If we came that far it's not a special version nor a branch or tag.
150150
# Therefore just return the identifier to make a safe guess.
151-
log.debug('TODO: Raise an exception here. Testing what cases it happens')
151+
log.debug(
152+
'TODO: Raise an exception here. Testing what cases it happens')
152153
return self.identifier
153154

154155
def get_absolute_url(self):

readthedocs/builds/syncers.py

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
# -*- coding: utf-8 -*-
12
"""
23
Classes to copy files between build and web servers.
34
45
"Syncers" copy files from the local machine, while "Pullers" copy files to the
56
local machine.
67
"""
78

8-
from __future__ import absolute_import
9+
from __future__ import (
10+
absolute_import, division, print_function, unicode_literals)
911

1012
import getpass
1113
import logging
@@ -15,9 +17,8 @@
1517
from builtins import object
1618
from django.conf import settings
1719

18-
from readthedocs.core.utils.extend import SettingsOverrideObject
1920
from readthedocs.core.utils import safe_makedirs
20-
21+
from readthedocs.core.utils.extend import SettingsOverrideObject
2122

2223
log = logging.getLogger(__name__)
2324

@@ -27,7 +28,7 @@ class LocalSyncer(object):
2728
@classmethod
2829
def copy(cls, path, target, is_file=False, **__):
2930
"""A copy command that works with files or directories."""
30-
log.info("Local Copy %s to %s", path, target)
31+
log.info('Local Copy %s to %s', path, target)
3132
if is_file:
3233
if path == target:
3334
# Don't copy the same file over itself
@@ -53,28 +54,26 @@ def copy(cls, path, target, is_file=False, **__):
5354
sync_user = getattr(settings, 'SYNC_USER', getpass.getuser())
5455
app_servers = getattr(settings, 'MULTIPLE_APP_SERVERS', [])
5556
if app_servers:
56-
log.info("Remote Copy %s to %s on %s", path, target, app_servers)
57+
log.info('Remote Copy %s to %s on %s', path, target, app_servers)
5758
for server in app_servers:
58-
mkdir_cmd = ("ssh %s@%s mkdir -p %s" % (sync_user, server, target))
59+
mkdir_cmd = (
60+
'ssh %s@%s mkdir -p %s' % (sync_user, server, target))
5961
ret = os.system(mkdir_cmd)
6062
if ret != 0:
61-
log.error("Copy error to app servers: cmd=%s", mkdir_cmd)
63+
log.error('Copy error to app servers: cmd=%s', mkdir_cmd)
6264
if is_file:
63-
slash = ""
65+
slash = ''
6466
else:
65-
slash = "/"
67+
slash = '/'
6668
# Add a slash when copying directories
6769
sync_cmd = (
6870
"rsync -e 'ssh -T' -av --delete {path}{slash} {user}@{server}:{target}"
6971
.format(
70-
path=path,
71-
slash=slash,
72-
user=sync_user,
73-
server=server,
72+
path=path, slash=slash, user=sync_user, server=server,
7473
target=target))
7574
ret = os.system(sync_cmd)
7675
if ret != 0:
77-
log.error("Copy error to app servers: cmd=%s", sync_cmd)
76+
log.error('Copy error to app servers: cmd=%s', sync_cmd)
7877

7978

8079
class DoubleRemotePuller(object):
@@ -89,29 +88,25 @@ def copy(cls, path, target, host, is_file=False, **__):
8988
sync_user = getattr(settings, 'SYNC_USER', getpass.getuser())
9089
app_servers = getattr(settings, 'MULTIPLE_APP_SERVERS', [])
9190
if not is_file:
92-
path += "/"
93-
log.info("Remote Copy %s to %s", path, target)
91+
path += '/'
92+
log.info('Remote Copy %s to %s', path, target)
9493
for server in app_servers:
9594
if not is_file:
96-
mkdir_cmd = "ssh {user}@{server} mkdir -p {target}".format(
97-
user=sync_user, server=server, target=target
98-
)
95+
mkdir_cmd = 'ssh {user}@{server} mkdir -p {target}'.format(
96+
user=sync_user, server=server, target=target)
9997
ret = os.system(mkdir_cmd)
10098
if ret != 0:
101-
log.error("MkDir error to app servers: cmd=%s", mkdir_cmd)
99+
log.error('MkDir error to app servers: cmd=%s', mkdir_cmd)
102100
# Add a slash when copying directories
103101
sync_cmd = (
104102
"ssh {user}@{server} 'rsync -av "
105103
"--delete --exclude projects {user}@{host}:{path} {target}'"
106104
.format(
107-
host=host,
108-
path=path,
109-
user=sync_user,
110-
server=server,
105+
host=host, path=path, user=sync_user, server=server,
111106
target=target))
112107
ret = os.system(sync_cmd)
113108
if ret != 0:
114-
log.error("Copy error to app servers: cmd=%s", sync_cmd)
109+
log.error('Copy error to app servers: cmd=%s', sync_cmd)
115110

116111

117112
class RemotePuller(object):
@@ -125,8 +120,8 @@ def copy(cls, path, target, host, is_file=False, **__):
125120
"""
126121
sync_user = getattr(settings, 'SYNC_USER', getpass.getuser())
127122
if not is_file:
128-
path += "/"
129-
log.info("Remote Pull %s to %s", path, target)
123+
path += '/'
124+
log.info('Remote Pull %s to %s', path, target)
130125
if not is_file and not os.path.exists(target):
131126
safe_makedirs(target)
132127
# Add a slash when copying directories
@@ -139,7 +134,7 @@ def copy(cls, path, target, host, is_file=False, **__):
139134
ret = os.system(sync_cmd)
140135
if ret != 0:
141136
log.error(
142-
"Copy error to app servers. Command: [%s] Return: [%s]",
137+
'Copy error to app servers. Command: [%s] Return: [%s]',
143138
sync_cmd,
144139
ret,
145140
)

readthedocs/core/management/commands/clean_builds.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
"""Clean up stable build paths per project version"""
1+
# -*- coding: utf-8 -*-
2+
"""Clean up stable build paths per project version."""
3+
4+
from __future__ import (
5+
absolute_import, division, print_function, unicode_literals)
26

3-
from __future__ import absolute_import
4-
from datetime import datetime, timedelta
57
import logging
8+
from datetime import datetime, timedelta
69
from optparse import make_option
710

811
from django.core.management.base import BaseCommand
@@ -18,25 +21,21 @@ class Command(BaseCommand):
1821
help = __doc__
1922

2023
option_list = BaseCommand.option_list + (
21-
make_option('--days',
22-
dest='days',
23-
type='int',
24-
default=365,
25-
help='Find builds older than DAYS days, default: 365'),
26-
make_option('--dryrun',
27-
action='store_true',
28-
dest='dryrun',
29-
help='Perform dry run on build cleanup'),
24+
make_option(
25+
'--days', dest='days', type='int', default=365,
26+
help='Find builds older than DAYS days, default: 365'),
27+
make_option(
28+
'--dryrun', action='store_true', dest='dryrun',
29+
help='Perform dry run on build cleanup'),
3030
)
3131

3232
def handle(self, *args, **options):
33-
"""Find stale builds and remove build paths"""
33+
"""Find stale builds and remove build paths."""
3434
max_date = datetime.now() - timedelta(days=options['days'])
35-
queryset = (Build.objects
36-
.values('project', 'version')
37-
.annotate(max_date=Max('date'))
38-
.filter(max_date__lt=max_date)
39-
.order_by('-max_date'))
35+
queryset = (
36+
Build.objects.values('project',
37+
'version').annotate(max_date=Max('date'))
38+
.filter(max_date__lt=max_date).order_by('-max_date'))
4039
for build in queryset:
4140
try:
4241
# Get version from build version id, perform sanity check on
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
"""Reindex Elastic Search indexes"""
1+
# -*- coding: utf-8 -*-
2+
"""Reindex Elastic Search indexes."""
3+
4+
from __future__ import (
5+
absolute_import, division, print_function, unicode_literals)
26

3-
from __future__ import absolute_import
47
import logging
58
from optparse import make_option
69

7-
from django.core.management.base import BaseCommand
8-
from django.core.management.base import CommandError
910
from django.conf import settings
11+
from django.core.management.base import BaseCommand, CommandError
1012

1113
from readthedocs.builds.constants import LATEST
1214
from readthedocs.builds.models import Version
@@ -19,14 +21,10 @@ class Command(BaseCommand):
1921

2022
help = __doc__
2123
option_list = BaseCommand.option_list + (
22-
make_option('-p',
23-
dest='project',
24-
default='',
25-
help='Project to index'),
26-
)
24+
make_option('-p', dest='project', default='', help='Project to index'),)
2725

2826
def handle(self, *args, **options):
29-
"""Build/index all versions or a single project's version"""
27+
"""Build/index all versions or a single project's version."""
3028
project = options['project']
3129

3230
queryset = Version.objects.all()
@@ -36,12 +34,12 @@ def handle(self, *args, **options):
3634
if not queryset.exists():
3735
raise CommandError(
3836
'No project with slug: {slug}'.format(slug=project))
39-
log.info("Building all versions for %s", project)
37+
log.info('Building all versions for %s', project)
4038
elif getattr(settings, 'INDEX_ONLY_LATEST', True):
4139
queryset = queryset.filter(slug=LATEST)
4240

4341
for version in queryset:
44-
log.info("Reindexing %s", version)
42+
log.info('Reindexing %s', version)
4543
try:
4644
commit = version.project.vcs_repo(version.slug).commit
4745
except: # pylint: disable=bare-except
@@ -50,7 +48,6 @@ def handle(self, *args, **options):
5048
commit = None
5149

5250
try:
53-
update_search(version.pk, commit,
54-
delete_non_commit_files=False)
51+
update_search(version.pk, commit, delete_non_commit_files=False)
5552
except Exception:
5653
log.exception('Reindex failed for %s', version)

readthedocs/core/signals.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1+
# -*- coding: utf-8 -*-
12
"""Signal handling for core app."""
23

3-
from __future__ import absolute_import
4+
from __future__ import (
5+
absolute_import, division, print_function, unicode_literals)
46

57
import logging
68

79
from corsheaders import signals
810
from django.conf import settings
11+
from django.db.models import Count, Q
912
from django.db.models.signals import pre_delete
10-
from django.dispatch import Signal
11-
from django.db.models import Q, Count
12-
from django.dispatch import receiver
13+
from django.dispatch import Signal, receiver
1314
from future.backports.urllib.parse import urlparse
1415

15-
from readthedocs.projects.models import Project, Domain
16+
from readthedocs.projects.models import Domain, Project
1617

1718
log = logging.getLogger(__name__)
1819

@@ -23,7 +24,6 @@
2324
'/api/v2/sustainability',
2425
]
2526

26-
2727
webhook_github = Signal(providing_args=['project', 'data', 'event'])
2828
webhook_gitlab = Signal(providing_args=['project', 'data', 'event'])
2929
webhook_bitbucket = Signal(providing_args=['project', 'data', 'event'])
@@ -65,8 +65,7 @@ def decide_if_cors(sender, request, **kwargs): # pylint: disable=unused-argumen
6565

6666
domain = Domain.objects.filter(
6767
Q(domain__icontains=host),
68-
Q(project=project) | Q(project__subprojects__child=project)
69-
)
68+
Q(project=project) | Q(project__subprojects__child=project))
7069
if domain.exists():
7170
return True
7271

@@ -77,12 +76,14 @@ def decide_if_cors(sender, request, **kwargs): # pylint: disable=unused-argumen
7776
def delete_projects_and_organizations(sender, instance, *args, **kwargs):
7877
# Here we count the owner list from the projects that the user own
7978
# Then exclude the projects where there are more than one owner
80-
projects = instance.projects.all().annotate(num_users=Count('users')).exclude(num_users__gt=1)
79+
projects = instance.projects.all().annotate(
80+
num_users=Count('users')).exclude(num_users__gt=1)
8181

8282
# Here we count the users list from the organization that the user belong
8383
# Then exclude the organizations where there are more than one user
84-
oauth_organizations = (instance.oauth_organizations.annotate(num_users=Count('users'))
85-
.exclude(num_users__gt=1))
84+
oauth_organizations = (
85+
instance.oauth_organizations.annotate(num_users=Count('users'))
86+
.exclude(num_users__gt=1))
8687

8788
projects.delete()
8889
oauth_organizations.delete()

0 commit comments

Comments
 (0)