-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pre-commit command ran for humitos/log/sentry branch #3898
Closed
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
readthedocs-common/style.yapf |
Submodule readthedocs-common
updated
from 9d766e to 16c20b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Classes to copy files between build and web servers. | ||
|
||
"Syncers" copy files from the local machine, while "Pullers" copy files to the | ||
local machine. | ||
""" | ||
|
||
from __future__ import absolute_import | ||
from __future__ import ( | ||
absolute_import, division, print_function, unicode_literals) | ||
|
||
import getpass | ||
import logging | ||
|
@@ -15,9 +17,8 @@ | |
from builtins import object | ||
from django.conf import settings | ||
|
||
from readthedocs.core.utils.extend import SettingsOverrideObject | ||
from readthedocs.core.utils import safe_makedirs | ||
|
||
from readthedocs.core.utils.extend import SettingsOverrideObject | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
@@ -27,7 +28,7 @@ class LocalSyncer(object): | |
@classmethod | ||
def copy(cls, path, target, is_file=False, **__): | ||
"""A copy command that works with files or directories.""" | ||
log.info("Local Copy %s to %s", path, target) | ||
log.info('Local Copy %s to %s', path, target) | ||
if is_file: | ||
if path == target: | ||
# Don't copy the same file over itself | ||
|
@@ -53,30 +54,26 @@ def copy(cls, path, target, is_file=False, **__): | |
sync_user = getattr(settings, 'SYNC_USER', getpass.getuser()) | ||
app_servers = getattr(settings, 'MULTIPLE_APP_SERVERS', []) | ||
if app_servers: | ||
log.info("Remote Copy %s to %s on %s", path, target, app_servers) | ||
log.info('Remote Copy %s to %s on %s', path, target, app_servers) | ||
for server in app_servers: | ||
mkdir_cmd = ("ssh %s@%s mkdir -p %s" % (sync_user, server, target)) | ||
mkdir_cmd = ( | ||
'ssh %s@%s mkdir -p %s' % (sync_user, server, target)) | ||
ret = os.system(mkdir_cmd) | ||
if ret != 0: | ||
log.info("COPY ERROR to app servers:") | ||
log.info(mkdir_cmd) | ||
log.error('Copy error to app servers: cmd=%s', mkdir_cmd) | ||
if is_file: | ||
slash = "" | ||
slash = '' | ||
else: | ||
slash = "/" | ||
slash = '/' | ||
# Add a slash when copying directories | ||
sync_cmd = ( | ||
"rsync -e 'ssh -T' -av --delete {path}{slash} {user}@{server}:{target}" | ||
.format( | ||
path=path, | ||
slash=slash, | ||
user=sync_user, | ||
server=server, | ||
path=path, slash=slash, user=sync_user, server=server, | ||
target=target)) | ||
ret = os.system(sync_cmd) | ||
if ret != 0: | ||
log.info("COPY ERROR to app servers.") | ||
log.info(sync_cmd) | ||
log.error('Copy error to app servers: cmd=%s', sync_cmd) | ||
|
||
|
||
class DoubleRemotePuller(object): | ||
|
@@ -91,31 +88,25 @@ def copy(cls, path, target, host, is_file=False, **__): | |
sync_user = getattr(settings, 'SYNC_USER', getpass.getuser()) | ||
app_servers = getattr(settings, 'MULTIPLE_APP_SERVERS', []) | ||
if not is_file: | ||
path += "/" | ||
log.info("Remote Copy %s to %s", path, target) | ||
path += '/' | ||
log.info('Remote Copy %s to %s', path, target) | ||
for server in app_servers: | ||
if not is_file: | ||
mkdir_cmd = "ssh {user}@{server} mkdir -p {target}".format( | ||
user=sync_user, server=server, target=target | ||
) | ||
mkdir_cmd = 'ssh {user}@{server} mkdir -p {target}'.format( | ||
user=sync_user, server=server, target=target) | ||
ret = os.system(mkdir_cmd) | ||
if ret != 0: | ||
log.info("MKDIR ERROR to app servers:") | ||
log.info(mkdir_cmd) | ||
log.error('MkDir error to app servers: cmd=%s', mkdir_cmd) | ||
# Add a slash when copying directories | ||
sync_cmd = ( | ||
"ssh {user}@{server} 'rsync -av " | ||
"--delete --exclude projects {user}@{host}:{path} {target}'" | ||
.format( | ||
host=host, | ||
path=path, | ||
user=sync_user, | ||
server=server, | ||
host=host, path=path, user=sync_user, server=server, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Squashed continuation here |
||
target=target)) | ||
ret = os.system(sync_cmd) | ||
if ret != 0: | ||
log.info("COPY ERROR to app servers.") | ||
log.info(sync_cmd) | ||
log.error('Copy error to app servers: cmd=%s', sync_cmd) | ||
|
||
|
||
class RemotePuller(object): | ||
|
@@ -129,8 +120,8 @@ def copy(cls, path, target, host, is_file=False, **__): | |
""" | ||
sync_user = getattr(settings, 'SYNC_USER', getpass.getuser()) | ||
if not is_file: | ||
path += "/" | ||
log.info("Remote Pull %s to %s", path, target) | ||
path += '/' | ||
log.info('Remote Pull %s to %s', path, target) | ||
if not is_file and not os.path.exists(target): | ||
safe_makedirs(target) | ||
# Add a slash when copying directories | ||
|
@@ -142,7 +133,11 @@ def copy(cls, path, target, host, is_file=False, **__): | |
) | ||
ret = os.system(sync_cmd) | ||
if ret != 0: | ||
log.error("COPY ERROR to app servers. Command: [{}] Return: [{}]".format(sync_cmd, ret)) | ||
log.error( | ||
'Copy error to app servers. Command: [%s] Return: [%s]', | ||
sync_cmd, | ||
ret, | ||
) | ||
|
||
|
||
class Syncer(SettingsOverrideObject): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
"""Clean up stable build paths per project version""" | ||
# -*- coding: utf-8 -*- | ||
"""Clean up stable build paths per project version.""" | ||
|
||
from __future__ import ( | ||
absolute_import, division, print_function, unicode_literals) | ||
|
||
from __future__ import absolute_import | ||
from datetime import datetime, timedelta | ||
import logging | ||
from datetime import datetime, timedelta | ||
from optparse import make_option | ||
|
||
from django.core.management.base import BaseCommand | ||
|
@@ -18,40 +21,41 @@ class Command(BaseCommand): | |
help = __doc__ | ||
|
||
option_list = BaseCommand.option_list + ( | ||
make_option('--days', | ||
dest='days', | ||
type='int', | ||
default=365, | ||
help='Find builds older than DAYS days, default: 365'), | ||
make_option('--dryrun', | ||
action='store_true', | ||
dest='dryrun', | ||
help='Perform dry run on build cleanup'), | ||
make_option( | ||
'--days', dest='days', type='int', default=365, | ||
help='Find builds older than DAYS days, default: 365'), | ||
make_option( | ||
'--dryrun', action='store_true', dest='dryrun', | ||
help='Perform dry run on build cleanup'), | ||
) | ||
|
||
def handle(self, *args, **options): | ||
"""Find stale builds and remove build paths""" | ||
"""Find stale builds and remove build paths.""" | ||
max_date = datetime.now() - timedelta(days=options['days']) | ||
queryset = (Build.objects | ||
.values('project', 'version') | ||
.annotate(max_date=Max('date')) | ||
.filter(max_date__lt=max_date) | ||
.order_by('-max_date')) | ||
queryset = ( | ||
Build.objects.values('project', | ||
'version').annotate(max_date=Max('date')) | ||
.filter(max_date__lt=max_date).order_by('-max_date')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous continuation style was better |
||
for build in queryset: | ||
try: | ||
# Get version from build version id, perform sanity check on | ||
# latest build date | ||
version = Version.objects.get(id=build['version']) | ||
latest_build = version.builds.latest('date') | ||
if latest_build.date > max_date: | ||
log.warning('{0} is newer than {1}'.format( | ||
latest_build, max_date)) | ||
log.warning( | ||
'%s is newer than %s', | ||
latest_build, | ||
max_date, | ||
) | ||
path = version.get_build_path() | ||
if path is not None: | ||
log.info( | ||
('Found stale build path for {0} ' | ||
'at {1}, last used on {2}').format( | ||
version, path, latest_build.date)) | ||
'Found stale build path for %s at %s, last used on %s', | ||
version, | ||
path, | ||
latest_build.date, | ||
) | ||
if not options['dryrun']: | ||
version.clean_build_path() | ||
except Version.DoesNotExist: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This squashed the continuation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had sent a comment here, but my internet connection didn't help me:
By adding a
,
after thetarget
here, we get a one attribute per line formatting automatically by yapf.There are many changes on these files were we can apply this fix to get the more readable way, but I don't want to do it manually for now.
I think we can easily add the trailing comman once we start using pre-commit in a daily basis.
Anyway, I think we can use this PR to discuss/tweak yapf a little more.
There are things that need manual work. Although, for this particular issue that the trailling comma is missing we could add automatically before calling yapf with this hook: https://github.com/asottile/add-trailing-comma