Skip to content

Commit

Permalink
Upgrade all packages using pur (#4318)
Browse files Browse the repository at this point in the history
* Upgrade all packages using pur

for reqs in `ls requirements`;
do
  pur
  --skip django-tastypie,django,docker,elasticsearch,pyelasticsearch,commonmark,stripe,djangorestframework,mkdocs,django-allauth,django-filter,mercurial
  --requirement requirements/$reqs;
done

* Run lint with Python 3.6

* Downgrade gitpython to 2.1.10

* Linting error fixed

* Upgrade common

Branch: readthedocs/common#17

* Remove old note for testing

* Add note for django-filter

* no-else-return fixed in all the files

Some block needed to be re-idented to fulfill this check.

Basically, if you have a "if something: return another" the "else"
clause is not needed since it will be the common case for the flow to
continue if the condition is not met.

* Only # noqa comment

* Note about gitpython
  • Loading branch information
humitos authored and agjohnson committed Sep 5, 2018
1 parent ef6a059 commit 8b7c279
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 113 deletions.
20 changes: 10 additions & 10 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,11 @@ def get_github_url(

if not docroot:
return ''
else:
if docroot[0] != '/':
docroot = '/{}'.format(docroot)
if docroot[-1] != '/':
docroot = '{}/'.format(docroot)

if docroot[0] != '/':
docroot = '/{}'.format(docroot)
if docroot[-1] != '/':
docroot = '{}/'.format(docroot)

if action == 'view':
action_string = 'blob'
Expand Down Expand Up @@ -320,11 +320,11 @@ def get_gitlab_url(

if not docroot:
return ''
else:
if docroot[0] != '/':
docroot = '/{}'.format(docroot)
if docroot[-1] != '/':
docroot = '{}/'.format(docroot)

if docroot[0] != '/':
docroot = '/{}'.format(docroot)
if docroot[-1] != '/':
docroot = '{}/'.format(docroot)

if action == 'view':
action_string = 'blob'
Expand Down
4 changes: 3 additions & 1 deletion readthedocs/core/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ def resolve_domain(self, project, private=None):
domain = self._get_project_custom_domain(canonical_project)
if domain:
return domain.domain
elif self._use_subdomain():

if self._use_subdomain():
return self._get_project_subdomain(canonical_project)

return getattr(settings, 'PRODUCTION_DOMAIN')

def resolve(self, project, require_https=False, filename='', private=None,
Expand Down
17 changes: 11 additions & 6 deletions readthedocs/core/views/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,20 @@ def _build_version(project, slug, already_built=()):
log.info("(Version build) Building %s:%s",
project.slug, slug_version.slug)
return LATEST
elif project.versions.exclude(active=True).filter(slug=slug).exists():

if project.versions.exclude(active=True).filter(slug=slug).exists():
log.info("(Version build) Not Building %s", slug)
return None
elif slug not in already_built:

if slug not in already_built:
version = project.versions.get(slug=slug)
trigger_build(project=project, version=version, force=True)
log.info("(Version build) Building %s:%s",
project.slug, version.slug)
return slug
else:
log.info("(Version build) Not Building %s", slug)
return None

log.info("(Version build) Not Building %s", slug)
return None


def build_branches(project, branch_list):
Expand Down Expand Up @@ -305,16 +307,19 @@ def bitbucket_build(request):
branches,
)
log.debug('Bitbucket webhook payload:\n\n%s\n\n', data)

projects = get_project_from_url(search_url)
if projects and branches:
return _build_url(search_url, projects, branches)
elif not branches:

if not branches:
log.error(
'Commit/branch not found url=%s branches=%s',
search_url,
branches,
)
return HttpResponseNotFound('Commit/branch not found')

log.info('Project match not found: url=%s', search_url)
return HttpResponseNotFound('Project match not found')
return HttpResponse('Method not allowed, POST is required', status=405)
Expand Down
42 changes: 21 additions & 21 deletions readthedocs/core/views/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,23 @@ def _serve_file(request, filename, basepath):
if settings.DEBUG or getattr(settings, 'PYTHON_MEDIA', False):
# Serve from Python
return serve(request, filename, basepath)
else:
# Serve from Nginx
content_type, encoding = mimetypes.guess_type(
os.path.join(basepath, filename))
content_type = content_type or 'application/octet-stream'
response = HttpResponse(content_type=content_type)
if encoding:
response['Content-Encoding'] = encoding
try:
response['X-Accel-Redirect'] = os.path.join(
basepath[len(settings.SITE_ROOT):],
filename,
)
except UnicodeEncodeError:
raise Http404

return response

# Serve from Nginx
content_type, encoding = mimetypes.guess_type(
os.path.join(basepath, filename))
content_type = content_type or 'application/octet-stream'
response = HttpResponse(content_type=content_type)
if encoding:
response['Content-Encoding'] = encoding
try:
response['X-Accel-Redirect'] = os.path.join(
basepath[len(settings.SITE_ROOT):],
filename,
)
except UnicodeEncodeError:
raise Http404

return response


@map_project_slug
Expand Down Expand Up @@ -200,8 +200,8 @@ def _serve_symlink_docs(request, project, privacy_level, filename=''):
basepath = public_symlink.project_root
if os.path.exists(os.path.join(basepath, filename)):
return _serve_file(request, filename, basepath)
else:
files_tried.append(os.path.join(basepath, filename))

files_tried.append(os.path.join(basepath, filename))

if (settings.DEBUG or constants.PRIVATE in serve_docs) and privacy_level == constants.PRIVATE: # yapf: disable # noqa
# Handle private
Expand All @@ -210,8 +210,8 @@ def _serve_symlink_docs(request, project, privacy_level, filename=''):

if os.path.exists(os.path.join(basepath, filename)):
return _serve_file(request, filename, basepath)
else:
files_tried.append(os.path.join(basepath, filename))

files_tried.append(os.path.join(basepath, filename))

raise Http404(
'File not found. Tried these files: %s' % ','.join(files_tried))
10 changes: 5 additions & 5 deletions readthedocs/doc_builder/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def create_index(self, extension='md', **__):
docs_dir, 'README.{ext}'.format(ext=extension))
if os.path.exists(readme_filename):
return 'README'
else:
index_file = open(index_filename, 'w+')
index_text = """

index_file = open(index_filename, 'w+')
index_text = """
Welcome to Read the Docs
------------------------
Expand All @@ -122,8 +122,8 @@ def create_index(self, extension='md', **__):
familiar with Read the Docs.
"""

index_file.write(index_text.format(dir=docs_dir, ext=extension))
index_file.close()
index_file.write(index_text.format(dir=docs_dir, ext=extension))
index_file.close()
return 'index'

def run(self, *args, **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion readthedocs/doc_builder/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,8 @@ def container_id(self):
"""Return id of container if it is valid."""
if self.container_name:
return self.container_name
elif self.container:

if self.container:
return self.container.get('Id')

def container_state(self):
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/gold/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ def clean(self):
cleaned_data = super(GoldProjectForm, self).clean()
if self.projects.count() < self.user.num_supported_projects:
return cleaned_data
else:
self.add_error(None, 'You already have the max number of supported projects.')

self.add_error(None, 'You already have the max number of supported projects.')
4 changes: 2 additions & 2 deletions readthedocs/notifications/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def get_template_names(self, backend_name, source_format=constants.HTML):
source_format=source_format,
))
return names
else:
raise AttributeError()

raise AttributeError()

def render(self, backend_name, source_format=constants.HTML):
return render_to_string(
Expand Down
12 changes: 7 additions & 5 deletions readthedocs/oauth/services/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def create_repository(self, fields, privacy=None, organization=None):
log.debug('Not importing %s because mismatched orgs',
fields['name'])
return None
else:
repo.organization = organization

repo.organization = organization
repo.users.add(self.user)
repo.name = fields['name']
repo.description = fields['description']
Expand Down Expand Up @@ -141,9 +141,11 @@ def create_repository(self, fields, privacy=None, organization=None):
repo.json = json.dumps(fields)
repo.save()
return repo
else:
log.debug('Not importing %s because mismatched type',
fields['name'])

log.debug(
'Not importing %s because mismatched type',
fields['name'],
)

def create_organization(self, fields):
"""
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/oauth/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def create_repository(self, fields, privacy=None, organization=None):
log.debug('Not importing %s because mismatched orgs',
fields['name'])
return None
else:
repo.organization = organization

repo.organization = organization
repo.name = fields['name']
repo.description = fields['description']
repo.ssh_url = fields['ssh_url']
Expand Down
3 changes: 1 addition & 2 deletions readthedocs/oauth/services/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ def create_repository(self, fields, privacy=None, organization=None):
fields['name'],
)
return None
else:
repo.organization = organization

repo.organization = organization
repo.name = fields['name']
repo.description = fields['description']
repo.ssh_url = fields['ssh_url_to_repo']
Expand Down
6 changes: 3 additions & 3 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class ProjectRelationshipBaseForm(forms.ModelForm):

class Meta(object):
model = ProjectRelationship
exclude = []
fields = '__all__'

def __init__(self, *args, **kwargs):
self.project = kwargs.pop('project')
Expand Down Expand Up @@ -634,7 +634,7 @@ class DomainForm(forms.ModelForm):

class Meta(object):
model = Domain
exclude = ['machine', 'cname', 'count']
exclude = ['machine', 'cname', 'count'] # pylint: disable=modelform-uses-exclude

def __init__(self, *args, **kwargs):
self.project = kwargs.pop('project', None)
Expand Down Expand Up @@ -674,7 +674,7 @@ class IntegrationForm(forms.ModelForm):

class Meta(object):
model = Integration
exclude = ['provider_data', 'exchanges']
exclude = ['provider_data', 'exchanges'] # pylint: disable=modelform-uses-exclude

def __init__(self, *args, **kwargs):
self.project = kwargs.pop('project', None)
Expand Down
9 changes: 6 additions & 3 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ def full_json_path(self, version=LATEST):
"""The path to the build json docs in the project."""
if 'sphinx' in self.documentation_type:
return os.path.join(self.conf_dir(version), '_build', 'json')
elif 'mkdocs' in self.documentation_type:

if 'mkdocs' in self.documentation_type:
return os.path.join(self.checkout_path(version), '_build', 'json')

def full_singlehtml_path(self, version=LATEST):
Expand All @@ -555,11 +556,13 @@ def conf_file(self, version=LATEST):
if self.conf_py_file:
conf_path = os.path.join(
self.checkout_path(version), self.conf_py_file,)

if os.path.exists(conf_path):
log.info('Inserting conf.py file path from model')
return conf_path
else:
log.warning("Conf file specified on model doesn't exist")

log.warning("Conf file specified on model doesn't exist")

files = self.find('conf.py', version)
if not files:
files = self.full_find('conf.py', version)
Expand Down
6 changes: 3 additions & 3 deletions readthedocs/projects/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def __call__(self, value):
elif self.re_git_user.search(value) or url.scheme in private_schemes:
if allow_private_repos:
return value
else:
# Throw a more helpful error message
raise ValidationError('Manual cloning via SSH is not supported')

# Throw a more helpful error message
raise ValidationError('Manual cloning via SSH is not supported')

# No more valid URLs without supported URL schemes
raise ValidationError(_('Invalid scheme for URL'))
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/projects/version_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def prune_point(self, num_latest):
try:
self._state[major][minor] = sorted(
set(self._state[major][minor]))[-num_latest:]
except TypeError:
except TypeError: # pylint: disable=try-except-raise
# Raise these for now.
raise

Expand Down
34 changes: 17 additions & 17 deletions readthedocs/projects/views/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,23 @@ def project_download_media(request, project_slug, type_, version_slug):
settings.MEDIA_URL, type_, project_slug, version_slug,
'%s.%s' % (project_slug, type_.replace('htmlzip', 'zip')))
return HttpResponseRedirect(path)
else:
# Get relative media path
path = (
version.project.get_production_media_path(
type_=type_, version_slug=version_slug)
.replace(settings.PRODUCTION_ROOT, '/prod_artifacts'))
content_type, encoding = mimetypes.guess_type(path)
content_type = content_type or 'application/octet-stream'
response = HttpResponse(content_type=content_type)
if encoding:
response['Content-Encoding'] = encoding
response['X-Accel-Redirect'] = path
# Include version in filename; this fixes a long-standing bug
filename = '%s-%s.%s' % (
project_slug, version_slug, path.split('.')[-1])
response['Content-Disposition'] = 'filename=%s' % filename
return response

# Get relative media path
path = (
version.project.get_production_media_path(
type_=type_, version_slug=version_slug)
.replace(settings.PRODUCTION_ROOT, '/prod_artifacts'))
content_type, encoding = mimetypes.guess_type(path)
content_type = content_type or 'application/octet-stream'
response = HttpResponse(content_type=content_type)
if encoding:
response['Content-Encoding'] = encoding
response['X-Accel-Redirect'] = path
# Include version in filename; this fixes a long-standing bug
filename = '%s-%s.%s' % (
project_slug, version_slug, path.split('.')[-1])
response['Content-Disposition'] = 'filename=%s' % filename
return response


def elastic_project_search(request, project_slug):
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/vcs_support/backends/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def parse_branches(self, data):
delimiter = str(' ').encode('utf-8') if PY2 else str(' ')
raw_branches = csv.reader(StringIO(data), delimiter=delimiter)
for branch in raw_branches:
branch = [f for f in branch if f != '' and f != '*']
branch = [f for f in branch if f not in ('', '*')]
# Handle empty branches
if branch:
branch = branch[0]
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application # pylint: disable=wrong-import-position
from django.core.wsgi import get_wsgi_application # noqa
application = get_wsgi_application()

# Apply WSGI middleware here.
Expand Down
Loading

0 comments on commit 8b7c279

Please sign in to comment.