From 2bbd1f7a313180d997a101659f9dcb27be779182 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 6 Jul 2020 13:41:25 -0500 Subject: [PATCH 1/2] CI: fix linter Linter is failing for some dependency with isort somewhere. The latest version of prospector already pins the compatible versions of its dependencies. --- prospector-more.yml | 48 +----------------------- readthedocs/analytics/models.py | 8 ++-- readthedocs/api/v2/utils.py | 32 ++++++++-------- readthedocs/api/v2/views/integrations.py | 2 +- readthedocs/api/v3/urls.py | 1 + readthedocs/builds/version_slug.py | 4 +- readthedocs/core/models.py | 6 +-- readthedocs/core/resolver.py | 2 +- readthedocs/doc_builder/environments.py | 30 +++++++-------- readthedocs/gold/forms.py | 5 +-- readthedocs/gold/models.py | 6 +-- readthedocs/oauth/services/github.py | 10 ++--- readthedocs/oauth/services/gitlab.py | 12 +++--- readthedocs/organizations/models.py | 8 ++-- readthedocs/projects/forms.py | 8 ++-- readthedocs/projects/models.py | 6 +-- readthedocs/projects/tasks.py | 2 +- readthedocs/projects/validators.py | 8 ++-- readthedocs/search/utils.py | 4 +- readthedocs/search/views.py | 3 -- requirements/lint.txt | 11 +----- 21 files changed, 77 insertions(+), 139 deletions(-) mode change 100644 => 120000 prospector-more.yml diff --git a/prospector-more.yml b/prospector-more.yml deleted file mode 100644 index d2563bc3451..00000000000 --- a/prospector-more.yml +++ /dev/null @@ -1,47 +0,0 @@ -inherits: prospector - -strictness: high - -ignore-paths: - - constants.py - - urls.py - - wsgi.py - - acl - - api - - betterversion - - builds - - cdn - - comments - - core - - djangome - - doc_builder - - donate - - gold - - integrations - - locale - - notifications - - oauth - - payments - - privacy - - profiles - - projects - - redirects - - restapi - - rtd_tests - - search - - settings - - tastyapi - - templates - - vcs_support - -pylint: - options: - docstring-min-length: 20 - dummy-variables-rgx: '_$|__$|dummy' - max-line-length: 100 - disable: - - logging-format-interpolation - - too-many-arguments - -pep257: - run: true diff --git a/prospector-more.yml b/prospector-more.yml new file mode 120000 index 00000000000..f21e968a5ee --- /dev/null +++ b/prospector-more.yml @@ -0,0 +1 @@ +common/prospector-more.yml \ No newline at end of file diff --git a/readthedocs/analytics/models.py b/readthedocs/analytics/models.py index c813b21b43e..520367dd90a 100644 --- a/readthedocs/analytics/models.py +++ b/readthedocs/analytics/models.py @@ -62,7 +62,7 @@ def top_viewed_pages(cls, project, since=None): if since is None: since = timezone.now().date() - timezone.timedelta(days=30) - qs = ( + queryset = ( cls.objects .filter(project=project, date__gte=since) .values_list('path') @@ -74,7 +74,7 @@ def top_viewed_pages(cls, project, since=None): pages = [] view_counts = [] - for data in qs.iterator(): + for data in queryset.iterator(): pages.append(data[0]) view_counts.append(data[1]) @@ -102,13 +102,13 @@ def page_views_by_date(cls, project_slug, since=None): if since is None: since = timezone.now().date() - timezone.timedelta(days=30) - qs = cls.objects.filter( + queryset = cls.objects.filter( project__slug=project_slug, date__gt=since, ).values('date').annotate(total_views=Sum('view_count')).order_by('date') count_dict = dict( - qs.order_by('date').values_list('date', 'total_views') + queryset.order_by('date').values_list('date', 'total_views') ) # This fills in any dates where there is no data diff --git a/readthedocs/api/v2/utils.py b/readthedocs/api/v2/utils.py index 4632694607e..507727aaa57 100644 --- a/readthedocs/api/v2/utils.py +++ b/readthedocs/api/v2/utils.py @@ -73,22 +73,22 @@ def sync_versions_to_db(project, versions, type): # pylint: disable=redefined-b if version_id == old_versions[version_name]: # Version is correct continue - else: - # Update slug with new identifier - Version.objects.filter( - project=project, - verbose_name=version_name, - ).update( - identifier=version_id, - type=type, - machine=False, - ) # noqa - - log.info( - '(Sync Versions) Updated Version: [%s=%s] ', - version_name, - version_id, - ) + + # Update slug with new identifier + Version.objects.filter( + project=project, + verbose_name=version_name, + ).update( + identifier=version_id, + type=type, + machine=False, + ) # noqa + + log.info( + '(Sync Versions) Updated Version: [%s=%s] ', + version_name, + version_id, + ) else: # New Version created_version = Version.objects.create( diff --git a/readthedocs/api/v2/views/integrations.py b/readthedocs/api/v2/views/integrations.py index 4c482661970..adda9ea6399 100644 --- a/readthedocs/api/v2/views/integrations.py +++ b/readthedocs/api/v2/views/integrations.py @@ -189,7 +189,7 @@ def get_response_push(self, project, branches): project, branches, ) - triggered = True if to_build else False + triggered = bool(to_build) return { 'build_triggered': triggered, 'project': project.slug, diff --git a/readthedocs/api/v3/urls.py b/readthedocs/api/v3/urls.py index c52da4fb062..f1e5e09162a 100644 --- a/readthedocs/api/v3/urls.py +++ b/readthedocs/api/v3/urls.py @@ -16,6 +16,7 @@ # allows /api/v3/projects/ # allows /api/v3/projects/pip/ # allows /api/v3/projects/pip/superproject/ +# pylint: disable=assignment-from-no-return projects = router.register( r'projects', ProjectsViewSet, diff --git a/readthedocs/builds/version_slug.py b/readthedocs/builds/version_slug.py index b840ff6e487..b74cd959792 100644 --- a/readthedocs/builds/version_slug.py +++ b/readthedocs/builds/version_slug.py @@ -70,8 +70,8 @@ def __init__(self, *args, **kwargs): populate_from = kwargs.pop('populate_from', None) if populate_from is None: raise ValueError("missing 'populate_from' argument") - else: - self._populate_from = populate_from + + self._populate_from = populate_from super().__init__(*args, **kwargs) def get_queryset(self, model_cls, slug_field): diff --git a/readthedocs/core/models.py b/readthedocs/core/models.py index 433e694202d..a7d3257762c 100644 --- a/readthedocs/core/models.py +++ b/readthedocs/core/models.py @@ -1,15 +1,13 @@ -# -*- coding: utf-8 -*- - """Models for the core app.""" import logging from annoying.fields import AutoOneToOneField +from django.contrib.auth.models import User from django.db import models from django.urls import reverse from django.utils.translation import ugettext from django.utils.translation import ugettext_lazy as _ - log = logging.getLogger(__name__) @@ -18,7 +16,7 @@ class UserProfile(models.Model): """Additional information about a User.""" user = AutoOneToOneField( - 'auth.User', + User, verbose_name=_('User'), related_name='profile', on_delete=models.CASCADE, diff --git a/readthedocs/core/resolver.py b/readthedocs/core/resolver.py index 7c62b2e6684..00e3bee8eb2 100644 --- a/readthedocs/core/resolver.py +++ b/readthedocs/core/resolver.py @@ -339,7 +339,7 @@ def _use_custom_domain(self, custom_domain): :param custom_domain: Domain instance or ``None`` :type custom_domain: readthedocs.projects.models.Domain """ - return True if custom_domain is not None else False + return custom_domain is not None def _use_subdomain(self): """Make decision about whether to use a subdomain to serve docs.""" diff --git a/readthedocs/doc_builder/environments.py b/readthedocs/doc_builder/environments.py index 3abb9310cb5..9f9c6e14672 100644 --- a/readthedocs/doc_builder/environments.py +++ b/readthedocs/doc_builder/environments.py @@ -838,21 +838,21 @@ def __enter__(self): if self.build: self.build['state'] = BUILD_STATE_FINISHED raise exc - else: - log.warning( - LOG_TEMPLATE, - { - 'project': self.project.slug, - 'version': self.version.slug, - 'msg': ( - 'Removing stale container {}'.format( - self.container_id, - ) - ), - } - ) - client = self.get_client() - client.remove_container(self.container_id) + + log.warning( + LOG_TEMPLATE, + { + 'project': self.project.slug, + 'version': self.version.slug, + 'msg': ( + 'Removing stale container {}'.format( + self.container_id, + ) + ), + } + ) + client = self.get_client() + client.remove_container(self.container_id) except (DockerAPIError, ConnectionError): # If there is an exception here, we swallow the exception as this # was just during a sanity check anyways. diff --git a/readthedocs/gold/forms.py b/readthedocs/gold/forms.py index 45416027b11..fb02828aacc 100644 --- a/readthedocs/gold/forms.py +++ b/readthedocs/gold/forms.py @@ -112,10 +112,9 @@ def clean_project(self): if not project_instance.exists(): raise forms.ValidationError(_('No project found.')) - elif project_instance.first() in self.projects: + if project_instance.first() in self.projects: raise forms.ValidationError(_('This project is already Ad-Free.')) - else: - return project_slug + return project_slug def clean(self): cleaned_data = super().clean() diff --git a/readthedocs/gold/models.py b/readthedocs/gold/models.py index bd18babe0fe..ed676093d8a 100644 --- a/readthedocs/gold/models.py +++ b/readthedocs/gold/models.py @@ -2,13 +2,13 @@ import math from datetime import datetime +import pytz +from django.contrib.auth.models import User from django.db import models from django.utils.translation import ugettext_lazy as _ -import pytz from readthedocs.projects.models import Project - #: The membership options that are currently available LEVEL_CHOICES = ( ('v1-org-5', '$5/mo'), @@ -31,7 +31,7 @@ class GoldUser(models.Model): modified_date = models.DateTimeField(_('Modified date'), auto_now=True) user = models.ForeignKey( - 'auth.User', + User, verbose_name=_('User'), unique=True, related_name='gold', diff --git a/readthedocs/oauth/services/github.py b/readthedocs/oauth/services/github.py index 64cd95994a8..cc18aa6df7f 100644 --- a/readthedocs/oauth/services/github.py +++ b/readthedocs/oauth/services/github.py @@ -136,11 +136,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): """ diff --git a/readthedocs/oauth/services/gitlab.py b/readthedocs/oauth/services/gitlab.py index 83a1d3be252..df7ee2a7ed5 100644 --- a/readthedocs/oauth/services/gitlab.py +++ b/readthedocs/oauth/services/gitlab.py @@ -195,12 +195,12 @@ def create_repository(self, fields, privacy=None, organization=None): repo.json = json.dumps(fields) repo.save() return repo - else: - log.info( - 'Not importing %s because mismatched type: visibility=%s', - fields['name_with_namespace'], - fields['visibility'], - ) + + log.info( + 'Not importing %s because mismatched type: visibility=%s', + fields['name_with_namespace'], + fields['visibility'], + ) def create_organization(self, fields): """ diff --git a/readthedocs/organizations/models.py b/readthedocs/organizations/models.py index 7b5f909184f..53d9a528b10 100644 --- a/readthedocs/organizations/models.py +++ b/readthedocs/organizations/models.py @@ -7,8 +7,8 @@ from django.utils.crypto import salted_hmac from django.utils.translation import ugettext_lazy as _ -from readthedocs.core.utils import slugify from readthedocs.core.permissions import AdminPermission +from readthedocs.core.utils import slugify from . import constants from .managers import TeamManager, TeamMemberManager @@ -99,7 +99,7 @@ def users(self): def members(self): return AdminPermission.members(self) - def save(self, *args, **kwargs): # pylint: disable=arguments-differ + def save(self, *args, **kwargs): # pylint: disable=signature-differs if not self.slug: self.slug = slugify(self.name) @@ -204,7 +204,7 @@ def __str__(self): team=self.name, ) - def save(self, *args, **kwargs): # pylint: disable=arguments-differ + def save(self, *args, **kwargs): # pylint: disable=signature-differs if not self.slug: self.slug = slugify(self.name) super().save(*args, **kwargs) @@ -245,7 +245,7 @@ def __str__(self): team=self.team, ) - def save(self, *args, **kwargs): # pylint: disable=arguments-differ + def save(self, *args, **kwargs): # pylint: disable=signature-differs hash_ = salted_hmac( # HMAC key per applications '.'.join([self.__module__, self.__class__.__name__]), diff --git a/readthedocs/projects/forms.py b/readthedocs/projects/forms.py index 86d1ecfd11d..4406fabb86f 100644 --- a/readthedocs/projects/forms.py +++ b/readthedocs/projects/forms.py @@ -742,21 +742,21 @@ def clean_name(self): raise forms.ValidationError( _("Variable name can't start with __ (double underscore)"), ) - elif name.startswith('READTHEDOCS'): + if name.startswith('READTHEDOCS'): raise forms.ValidationError( _("Variable name can't start with READTHEDOCS"), ) - elif self.project.environmentvariable_set.filter(name=name).exists(): + if self.project.environmentvariable_set.filter(name=name).exists(): raise forms.ValidationError( _( 'There is already a variable with this name for this project', ), ) - elif ' ' in name: + if ' ' in name: raise forms.ValidationError( _("Variable name can't contain spaces"), ) - elif not fullmatch('[a-zA-Z0-9_]+', name): + if not fullmatch('[a-zA-Z0-9_]+', name): raise forms.ValidationError( _('Only letters, numbers and underscore are allowed'), ) diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py index b1c564413dd..42acdf33564 100644 --- a/readthedocs/projects/models.py +++ b/readthedocs/projects/models.py @@ -67,13 +67,13 @@ class ProjectRelationship(models.Model): """ parent = models.ForeignKey( - 'Project', + 'projects.Project', verbose_name=_('Parent'), related_name='subprojects', on_delete=models.CASCADE, ) child = models.ForeignKey( - 'Project', + 'projects.Project', verbose_name=_('Child'), related_name='superprojects', on_delete=models.CASCADE, @@ -1330,7 +1330,7 @@ class ImportedFile(models.Model): """ project = models.ForeignKey( - 'Project', + Project, verbose_name=_('Project'), related_name='imported_files', on_delete=models.CASCADE, diff --git a/readthedocs/projects/tasks.py b/readthedocs/projects/tasks.py index f11abafcc42..4df043c0096 100644 --- a/readthedocs/projects/tasks.py +++ b/readthedocs/projects/tasks.py @@ -1411,7 +1411,7 @@ def warn(self, msg): 'Error while getting sphinx domain information for %s:%s:%s. Skipping.', version.project.slug, version.slug, - f'domain->name', + f'{domain}->{name}', ) continue diff --git a/readthedocs/projects/validators.py b/readthedocs/projects/validators.py index c30509d0e0e..6156f8e4443 100644 --- a/readthedocs/projects/validators.py +++ b/readthedocs/projects/validators.py @@ -72,19 +72,19 @@ def __call__(self, value): # Malicious characters go first if '&&' in value or '|' in value: raise ValidationError(_('Invalid character in the URL')) - elif url.scheme in valid_schemes: + if url.scheme in valid_schemes: return value # Repo URL is not a supported scheme at this point, but there are # several cases where we might support it # Launchpad - elif value.startswith('lp:'): + if value.startswith('lp:'): return value # Relative paths are conditionally supported - elif value.startswith('.') and not self.disallow_relative_url: + if value.startswith('.') and not self.disallow_relative_url: return value # SSH cloning and ``git@github.com:user/project.git`` - elif self.re_git_user.search(value) or url.scheme in private_schemes: + if self.re_git_user.search(value) or url.scheme in private_schemes: if settings.ALLOW_PRIVATE_REPOS: return value diff --git a/readthedocs/search/utils.py b/readthedocs/search/utils.py index 70b0e5f0e80..95f7dd316ba 100644 --- a/readthedocs/search/utils.py +++ b/readthedocs/search/utils.py @@ -4,12 +4,10 @@ from operator import attrgetter from django.utils import timezone -from django.shortcuts import get_object_or_404 from django_elasticsearch_dsl.apps import DEDConfig from django_elasticsearch_dsl.registries import registry -from readthedocs.builds.models import Version -from readthedocs.projects.models import HTMLFile, Project +from readthedocs.projects.models import HTMLFile log = logging.getLogger(__name__) diff --git a/readthedocs/search/views.py b/readthedocs/search/views.py index 4cb3033bb46..50ba0b65101 100644 --- a/readthedocs/search/views.py +++ b/readthedocs/search/views.py @@ -1,14 +1,11 @@ """Search views.""" import collections -import itertools import logging -from operator import attrgetter from django.shortcuts import get_object_or_404, render from readthedocs.builds.constants import LATEST from readthedocs.projects.models import Project -from readthedocs.search import utils from readthedocs.search.faceted_search import ( ALL_FACETS, PageSearch, diff --git a/requirements/lint.txt b/requirements/lint.txt index d74535d4b7e..aaa7c68d712 100644 --- a/requirements/lint.txt +++ b/requirements/lint.txt @@ -1,13 +1,4 @@ # Packages required for doing linting -r pip.txt -# prospector 1.1.6.2 is not compatible with 2.1.0 -astroid<=2.0.4 # pyup: ignore -# prospector 1.1.6.2 is not compatible with 2.2.2 -pylint<=2.1.1 # pyup: ignore -# prospector 1.1.6.2 is not compatible with 2.0.3 -pylint-django==2.0.2 # pyup: ignore -pylint-celery==0.3 -prospector==1.1.6.4 # pyup: ignore -# prospector 1.1.6.2 is not compatible with 2.0.0 -pyflakes<2.0.0 # pyup: ignore +prospector==1.3.0 From 7a9f9f619655cb789ba320f7acb5a229722f88ec Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Tue, 7 Jul 2020 09:47:51 -0500 Subject: [PATCH 2/2] Update common --- common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common b/common index aa711563ca2..1111aee4525 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit aa711563ca288dd9a5860d283a78ed7b54425b9d +Subproject commit 1111aee4525b1eacd87e94382ec975a6523764ce