Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

flake8 vcs_support #367

Merged
merged 1 commit into from

1 participant

@wraithan
Owner

This makes it so vcs_support passes flake8 without 0 errors. Sent as PR because it is 3:45am and I am not certain I didn't muck something up.

@wraithan
Owner

Tests pass, played with it locally, merging.

@wraithan wraithan merged commit 181948e into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 6, 2013
  1. @wraithan

    flake8 vcs_support

    wraithan authored
This page is out of date. Refresh to see the latest.
View
3  readthedocs/vcs_support/backends/__init__.py
@@ -1,4 +1,3 @@
-
from . import bzr, hg, git, svn
backend_cls = {
@@ -7,4 +6,4 @@
'svn': svn.Backend,
'git': git.Backend,
'hg': hg.Backend,
- }
+}
View
9 readthedocs/vcs_support/backends/bzr.py
@@ -21,12 +21,14 @@ def up(self):
retcode = self.run('bzr', 'revert')[0]
if retcode != 0:
raise ProjectImportError(
- "Failed to get code from '%s' (bzr revert): %s" % (self.repo_url, retcode)
+ ("Failed to get code from '%s' (bzr revert): %s"
+ % (self.repo_url, retcode))
)
up_output = self.run('bzr', 'up')
if up_output[0] != 0:
raise ProjectImportError(
- "Failed to get code from '%s' (bzr up): %s" % (self.repo_url, retcode)
+ ("Failed to get code from '%s' (bzr up): %s"
+ % (self.repo_url, retcode))
)
return up_output
@@ -34,7 +36,8 @@ def clone(self):
retcode = self.run('bzr', 'checkout', self.repo_url, '.')[0]
if retcode != 0:
raise ProjectImportError(
- "Failed to get code from '%s' (bzr checkout): %s" % (self.repo_url, retcode)
+ ("Failed to get code from '%s' (bzr checkout): %s"
+ % (self.repo_url, retcode))
)
@property
View
3  readthedocs/vcs_support/backends/git.py
@@ -11,11 +11,12 @@
log = logging.getLogger(__name__)
+
class Backend(BaseVCS):
supports_tags = True
supports_branches = True
contribution_backends = [GithubContributionBackend]
- fallback_branch = 'master' # default branch
+ fallback_branch = 'master' # default branch
def check_working_dir(self):
if exists(self.working_dir):
View
17 readthedocs/vcs_support/backends/github.py
@@ -79,11 +79,10 @@ def set_branch_file(self, branch, filename, contents, comment=''):
self.run('git', 'checkout', branch)
def push_branch(self, branch, title='', comment=''):
- """
- Pushes a branch upstream.
+ """Pushes a branch upstream.
- Since the python github API libraries don't support pull requests, we'll
- have to do it manually using urllib2 :(
+ Since the python github API libraries don't support pull requests,
+ we'll have to do it manually using urllib2 :(
"""
identifier = self.get_branch_identifier(branch)
log.info('pushing branch %s in %s' % (identifier, self._gh_name()))
@@ -107,8 +106,8 @@ def pull_request(self, identifier, title, comment):
url = 'https://github.com/api/v2/json/pulls/%s' % self._gh_name()
log.debug(url)
request = urllib2.Request(url)
- auth = base64.encodestring('%s/token:%s' % (
- GITHUB_USERNAME, GITHUB_TOKEN))[:-1]
+ auth = base64.encodestring('%s/token:%s' % (GITHUB_USERNAME,
+ GITHUB_TOKEN))[:-1]
request.add_header("Authorization", 'Basic %s' % auth)
branch = self.fallback_branch
if self.default_branch:
@@ -140,7 +139,8 @@ def gh_reponame(self):
def check_remote(self):
"""
- Check if the RTD remote is available in this repository, if not, add it.
+ Check if the RTD remote is available in this repository, if not,
+ add it.
"""
log.info('checking remote')
if not self.has_fork():
@@ -162,7 +162,8 @@ def push_remote(self, identifier):
"""
push a local branch to the RTD remote
"""
- log.info('pushing %s to remote %s' % (identifier, self.get_remote_name()))
+ log.info('pushing %s to remote %s' % (identifier,
+ self.get_remote_name()))
self.run('git', 'push', 'rtd', identifier)
def has_fork(self):
View
9 readthedocs/vcs_support/backends/hg.py
@@ -22,12 +22,14 @@ def pull(self):
pull_output = self.run('hg', 'pull')
if pull_output[0] != 0:
raise ProjectImportError(
- "Failed to get code from '%s' (hg pull): %s" % (self.repo_url, pull_output[0])
+ ("Failed to get code from '%s' (hg pull): %s"
+ % (self.repo_url, pull_output[0]))
)
update_output = self.run('hg', 'update', '-C')[0]
if update_output[0] != 0:
raise ProjectImportError(
- "Failed to get code from '%s' (hg update): %s" % (self.repo_url, pull_output[0])
+ ("Failed to get code from '%s' (hg update): %s"
+ % (self.repo_url, pull_output[0]))
)
return update_output
@@ -35,7 +37,8 @@ def clone(self):
output = self.run('hg', 'clone', self.repo_url, '.')
if output[0] != 0:
raise ProjectImportError(
- "Failed to get code from '%s' (hg clone): %s" % (self.repo_url, output[0])
+ ("Failed to get code from '%s' (hg clone): %s"
+ % (self.repo_url, output[0]))
)
return output
View
3  readthedocs/vcs_support/backends/launchpad.py
@@ -22,7 +22,8 @@ def branches(self):
def get_project(self):
if self.lp_project is None:
lp = self.get_launchpad()
- self.lp_project = lp.projects[self.slug] # Probably need to improve this
+ # Probably need to improve this
+ self.lp_project = lp.projects[self.slug]
return self.lp_project
def get_launchpad(self):
View
19 readthedocs/vcs_support/backends/svn.py
@@ -22,8 +22,8 @@ def __init__(self, project, version):
def update(self):
super(Backend, self).update()
- # For some reason `svn status` gives me retcode 0 in non-svn directories
- # that's why I use `svn info` here.
+ # For some reason `svn status` gives me retcode 0 in non-svn
+ # directories that's why I use `svn info` here.
retcode = self.run('svn', 'info')[0]
if retcode == 0:
self.up()
@@ -34,12 +34,15 @@ def up(self):
retcode = self.run('svn', 'revert', '--recursive', '.')[0]
if retcode != 0:
raise ProjectImportError(
- "Failed to get code from '%s' (svn revert): %s" % (self.repo_url, retcode)
+ ("Failed to get code from '%s' (svn revert): %s"
+ % (self.repo_url, retcode))
)
- retcode = self.run('svn', 'up', '--accept', 'theirs-full', '--trust-server-cert', '--non-interactive')[0]
+ retcode = self.run('svn', 'up', '--accept', 'theirs-full',
+ '--trust-server-cert', '--non-interactive')[0]
if retcode != 0:
raise ProjectImportError(
- "Failed to get code from '%s' (svn up): %s" % (self.repo_url, retcode)
+ "Failed to get code from '%s' (svn up): %s" % (self.repo_url,
+ retcode)
)
def co(self, identifier=None):
@@ -50,12 +53,14 @@ def co(self, identifier=None):
retcode = self.run('svn', 'checkout', '--quiet', url, '.')[0]
if retcode != 0:
raise ProjectImportError(
- "Failed to get code from '%s' (svn checkout): %s" % (url, retcode)
+ "Failed to get code from '%s' (svn checkout): %s" % (url,
+ retcode)
)
@property
def tags(self):
- retcode, stdout = self.run('svn', 'list', '%s/tags/' % self.base_url)[:2]
+ retcode, stdout = self.run('svn', 'list', '%s/tags/'
+ % self.base_url)[:2]
# error (or no tags found)
if retcode != 0:
return []
View
29 readthedocs/vcs_support/base.py
@@ -8,6 +8,7 @@
log = logging.getLogger(__name__)
+
class VCSVersion(object):
"""
Represents a Version (tag or branch) in a VCS.
@@ -28,7 +29,7 @@ def __repr__(self):
class VCSProject(namedtuple("VCSProject",
- "name default_branch working_dir repo_url")):
+ "name default_branch working_dir repo_url")):
"""Transient object to encapsulate a projects stuff"""
pass
@@ -51,10 +52,10 @@ def run(self, *args):
cwd=self.working_dir, shell=False,
env=self.env)
log.info(self.log_tmpl.format(ident=basename(self.working_dir),
- args=' '.join(args)))
+ args=' '.join(args)))
stdout, stderr = process.communicate()
log.info(self.log_tmpl.format(ident=basename(self.working_dir),
- args=stdout))
+ args=stdout))
return (process.returncode, stdout, stderr)
@property
@@ -67,13 +68,13 @@ class BaseVCS(BaseCLI):
Base for VCS Classes.
Built on top of the BaseCLI.
"""
- supports_tags = False # Whether this VCS supports tags or not.
- supports_branches = False # Whether this VCS supports branches or not.
+ supports_tags = False # Whether this VCS supports tags or not.
+ supports_branches = False # Whether this VCS supports branches or not.
contribution_backends = []
- #===========================================================================
+ #==========================================================================
# General methods
- #===========================================================================
+ #==========================================================================
def __init__(self, project, version):
self.default_branch = project.default_branch
@@ -92,23 +93,25 @@ def update(self):
"""
self.check_working_dir()
- #===========================================================================
+ #==========================================================================
# Tag / Branch related methods
# These methods only apply if supports_tags = True and/or
# support_branches = True
- #===========================================================================
+ #==========================================================================
@property
def tags(self):
"""
- Returns a list of VCSVersion objects. See VCSVersion for more information.
+ Returns a list of VCSVersion objects. See VCSVersion for more
+ information.
"""
raise NotImplementedError
@property
def branches(self):
"""
- Returns a list of VCSVersion objects. See VCSVersion for more information.
+ Returns a list of VCSVersion objects. See VCSVersion for more
+ information.
"""
raise NotImplementedError
@@ -123,10 +126,10 @@ def checkout(self, identifier=None):
"""
self.check_working_dir()
- #===========================================================================
+ #==========================================================================
# Contribution related methods
# These methods only apply if supports_contribution = True
- #===========================================================================
+ #==========================================================================
def get_contribution_backend(self):
"""
View
11 readthedocs/vcs_support/utils.py
@@ -4,6 +4,7 @@
log = logging.getLogger(__name__)
+
class Lock(object):
"""
A simple file based lock with timeout
@@ -27,11 +28,12 @@ def __enter__(self):
time.sleep(self.polling_interval)
timesince = time.time() - start
if timesince > self.timeout:
- log.info("Lock (%s): Force unlock, timeout reached" % self.name)
+ log.info("Lock (%s): Force unlock, timeout reached" %
+ self.name)
os.remove(self.fpath)
break
- log.info("%s still locked after %.2f seconds; retry for %.2f seconds"
- % (self.name, timesince, self.timeout))
+ log.info(("%s still locked after %.2f seconds; retry for %.2f"
+ " seconds") % (self.name, timesince, self.timeout))
open(self.fpath, 'w').close()
log.info("Lock (%s): Lock aquired" % self.name)
@@ -40,4 +42,5 @@ def __exit__(self, exc, value, tb):
log.info("Lock (%s): Releasing" % self.name)
os.remove(self.fpath)
except:
- log.error("Lock (%s): Failed to release, ignoring..." % self.name, exc_info=True)
+ log.error("Lock (%s): Failed to release, ignoring..." % self.name,
+ exc_info=True)
Something went wrong with that request. Please try again.