Skip to content

Commit

Permalink
Autolint cleanup for #3821
Browse files Browse the repository at this point in the history
Pre PR autolinting
  • Loading branch information
agjohnson committed Mar 20, 2018
1 parent 673bfc7 commit 661d213
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ indent=' '
multi_line_output=4
default_section=THIRDPARTY
known_first_party=readthedocs,readthedocsinc
known_third_party=mock
known_third_party=mock,builtins
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
add_imports=from __future__ import division, from __future__ import print_function, from __future__ import unicode_literals
46 changes: 30 additions & 16 deletions readthedocs/vcs_support/backends/git.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
"""Git-related utilities."""

from __future__ import absolute_import
from __future__ import (
absolute_import, division, print_function, unicode_literals)

import csv
import logging
Expand All @@ -13,7 +15,6 @@
from readthedocs.projects.exceptions import RepositoryError
from readthedocs.vcs_support.base import BaseVCS, VCSVersion


log = logging.getLogger(__name__)


Expand All @@ -39,9 +40,8 @@ def _get_clone_url(self):
clone_url = 'https://%s@%s' % (self.token, hacked_url)
return clone_url
# Don't edit URL because all hosts aren't the same

# else:
# clone_url = 'git://%s' % (hacked_url)
# clone_url = 'git://%s' % (hacked_url)
return self.repo_url

def set_remote_url(self, url):
Expand Down Expand Up @@ -69,22 +69,24 @@ def checkout_revision(self, revision=None):
branch = self.default_branch or self.fallback_branch
revision = 'origin/%s' % branch

code, out, err = self.run(
'git', 'checkout', '--force', revision)
code, out, err = self.run('git', 'checkout', '--force', revision)
if code != 0:
log.warning("Failed to checkout revision '%s': %s",
revision, code)
log.warning("Failed to checkout revision '%s': %s", revision, code)
return [code, out, err]

def clone(self):
code, _, _ = self.run(
'git', 'clone', '--recursive', self.repo_url, '.')
code, _, _ = self.run('git', 'clone', '--recursive', self.repo_url, '.')
if code != 0:
raise RepositoryError

@property
def tags(self):
retcode, stdout, _ = self.run('git', 'show-ref', '--tags', record_as_success=True)
retcode, stdout, _ = self.run(
'git',
'show-ref',
'--tags',
record_as_success=True,
)
# error (or no tags found)
if retcode != 0:
return []
Expand Down Expand Up @@ -122,15 +124,20 @@ def parse_tags(self, data):
@property
def branches(self):
# Only show remote branches
retcode, stdout, _ = self.run('git', 'branch', '-r', record_as_success=True)
retcode, stdout, _ = self.run(
'git',
'branch',
'-r',
record_as_success=True,
)
# error (or no branches found)
if retcode != 0:
return []
return self.parse_branches(stdout)

def parse_branches(self, data):
"""
Parse output of git branch -r
Parse output of git branch -r.
e.g.:
Expand All @@ -155,7 +162,8 @@ def parse_branches(self, data):
verbose_name = branch.replace('origin/', '')
if verbose_name in ['HEAD']:
continue
clean_branches.append(VCSVersion(self, branch, verbose_name))
clean_branches.append(
VCSVersion(self, branch, verbose_name))
else:
clean_branches.append(VCSVersion(self, branch, branch))
return clean_branches
Expand Down Expand Up @@ -193,8 +201,14 @@ def checkout(self, identifier=None):
# Update submodules
if self.submodules_exists():
self.run('git', 'submodule', 'sync')
self.run('git', 'submodule', 'update',
'--init', '--recursive', '--force')
self.run(
'git',
'submodule',
'update',
'--init',
'--recursive',
'--force',
)

return code, out, err

Expand Down
13 changes: 7 additions & 6 deletions readthedocs/vcs_support/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-

"""Base classes for VCS backends."""
from __future__ import absolute_import
from builtins import object
from __future__ import (
absolute_import, division, print_function, unicode_literals)

import logging
import os
import shutil

from builtins import object

log = logging.getLogger(__name__)

Expand All @@ -28,8 +29,8 @@ def __init__(self, repository, identifier, verbose_name):
self.verbose_name = verbose_name

def __repr__(self):
return "<VCSVersion: %s:%s" % (self.repository.repo_url,
self.verbose_name)
return '<VCSVersion: %s:%s' % (
self.repository.repo_url, self.verbose_name)


class BaseVCS(object):
Expand Down Expand Up @@ -66,7 +67,7 @@ def check_working_dir(self):
os.makedirs(self.working_dir)

def make_clean_working_dir(self):
"""Ensures that the working dir exists and is empty"""
"""Ensures that the working dir exists and is empty."""
shutil.rmtree(self.working_dir, ignore_errors=True)
self.check_working_dir()

Expand Down

0 comments on commit 661d213

Please sign in to comment.