Skip to content
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

Upgrade all packages using pur #4318

Merged
merged 10 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ matrix:
env: TOXENV=docs
- python: 3.6
env: TOXENV=docs-lint
- python: 2.7
- python: 3.6
env: TOXENV=lint
script: tox
- python: 2.7
Expand Down
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, protocol='http', 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 @@ -199,8 +199,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 @@ -209,8 +209,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do generally prefer explicit disables, though I know that prospector was the one making this easier. For example, prospetor knows that pylint and flake8 (or whatever) throw an error on the same line, but pylint is ignoring -- it will therefore ignore the flake8 error as well. I don't think our pre-commit pass has anything comparable unfortunately.

#noqa becomes a generic exception handler of sorts, where who knows what else we're ignoring when we use #noqa

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is possible. worth making an issue on common?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also like being explicit here. I didn't find how to avoid the checking that was failing, though. It was something related to the import not at the top of the file and it wasn't pylint (I think it was flake --don't remember). That's why I just added # noqa.

application = get_wsgi_application()

# Apply WSGI middleware here.
Expand Down
Loading