Commit 384781fa authored by Raphaël Hertzog's avatar Raphaël Hertzog

Enable flake8 plugin flake8-import-order and document the convention

parent 30cb1bd1
......@@ -8,9 +8,9 @@
# including this file, may be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
"""Views for the :mod:`distro_tracker.accounts` app."""
from django.db.models import Prefetch
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db.models import Prefetch
from django.http import Http404, HttpResponseBadRequest, HttpResponseForbidden
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse_lazy
......@@ -22,6 +22,7 @@ from distro_tracker.core.utils import (
distro_tracker_render_to_string,
render_to_json_response
)
from django_email_accounts import views as email_accounts_views
from django_email_accounts.views import LoginRequiredMixin
......
......@@ -11,12 +11,13 @@
Settings for the admin panel for the models defined in the
:mod:`distro_tracker.core` app.
"""
import requests
from django import forms
from django.contrib import admin
from django.core.exceptions import ValidationError
from django.core.validators import URLValidator
import requests
from distro_tracker.core.models import (
Architecture,
RepositoryFlag,
......
......@@ -20,10 +20,11 @@ from email.utils import getaddresses, parseaddr
from debian import changelog as debian_changelog
from debian.debian_support import AptPkgVersion
from django.conf import settings
from django.core.exceptions import ValidationError, ObjectDoesNotExist
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.files.base import ContentFile
from django.db import models, connection
from django.db import connection, models
from django.db.models import Q
from django.db.utils import IntegrityError
from django.template.defaultfilters import slugify
......@@ -34,6 +35,7 @@ from django.utils.encoding import force_text
from django.utils.functional import cached_property
from django.utils.html import escape
from django.utils.safestring import mark_safe
from jsonfield import JSONField
from distro_tracker import vendor
......@@ -49,10 +51,11 @@ from distro_tracker.core.utils.email_messages import (
get_decoded_message_payload,
message_from_bytes
)
from distro_tracker.core.utils.misc import get_data_checksum
from distro_tracker.core.utils.linkify import linkify
from distro_tracker.core.utils.misc import get_data_checksum
from distro_tracker.core.utils.packages import package_hashdir
from distro_tracker.core.utils.plugins import PluginRegistry
from django_email_accounts.models import UserEmail
DISTRO_TRACKER_CONFIRMATION_EXPIRATION_DAYS = \
......
......@@ -8,12 +8,12 @@
# including this file, may be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
"""Implements the core package tables shown on team pages."""
import logging
import importlib
import logging
from django.db.models import Prefetch
from django.conf import settings
from django.template import Template, Context
from django.db.models import Prefetch
from django.template import Context, Template
from django.template.loader import get_template
from distro_tracker import vendor
......@@ -22,7 +22,7 @@ from distro_tracker.core.models import (
PackageData,
PackageName,
)
from distro_tracker.core.utils import get_vcs_name, add_developer_extras
from distro_tracker.core.utils import add_developer_extras, get_vcs_name
from distro_tracker.core.utils.plugins import PluginRegistry
logger = logging.getLogger(__name__)
......
......@@ -13,6 +13,7 @@ import logging
from collections import defaultdict
from debian.debian_support import AptPkgVersion
from django.conf import settings
from django.utils.functional import cached_property
from django.utils.safestring import mark_safe
......@@ -29,8 +30,8 @@ from distro_tracker.core.models import (
)
from distro_tracker.core.templatetags.distro_tracker_extras import octicon
from distro_tracker.core.utils import (
get_vcs_name,
add_developer_extras
add_developer_extras,
get_vcs_name
)
from distro_tracker.core.utils.plugins import PluginRegistry
......
......@@ -12,11 +12,13 @@ import itertools
import logging
import re
import requests
from debian import deb822
from django.conf import settings
from django.db import models, transaction
import requests
from distro_tracker import vendor
from distro_tracker.accounts.models import UserEmail
from distro_tracker.core.models import (
......
......@@ -13,8 +13,8 @@ Base class to implement Tasks.
Tasks are used to execute (possibly long-running) operations that need
to happen regularly to update distro-tracker's data.
"""
import logging
import importlib
import logging
from datetime import timedelta
from django.conf import settings
......
......@@ -14,6 +14,7 @@ Mixins to combine to create powerful tasks.
import logging
from debian.debian_support import version_compare
from django.db import transaction
from distro_tracker.core.models import (
......
......@@ -13,29 +13,31 @@
"""
Tests for the Distro Tracker core package tables.
"""
from unittest.mock import patch, mock_open
from unittest.mock import mock_open, patch
from bs4 import BeautifulSoup as soup
from django.template import Context
from distro_tracker.core.models import (
PackageData,
PackageBugStats,
PackageData,
SourcePackageName,
Team,
SourcePackageName
)
from django_email_accounts.models import User
from distro_tracker.core.package_tables import (
create_table,
ArchiveTableField,
BasePackageTable,
GeneralTeamPackageTable,
BugStatsTableField,
GeneralInformationTableField,
GeneralTeamPackageTable,
VcsTableField,
ArchiveTableField,
BugStatsTableField
create_table,
)
from distro_tracker.test import TemplateTestsMixin, TestCase
from django_email_accounts.models import User
class TestPackageTable(BasePackageTable):
table_fields = (GeneralInformationTableField, ArchiveTableField)
......
......@@ -14,6 +14,7 @@
Tests for the Distro Tracker core panels.
"""
from bs4 import BeautifulSoup as soup
from django.conf import settings
from django.urls import reverse
......
......@@ -38,12 +38,12 @@ from distro_tracker.core.models import (
Team
)
from distro_tracker.core.retrieve_data import (
TagPackagesWithBugs,
UpdatePackageGeneralInformation,
UpdateRepositoriesTask,
UpdateSourceToBinariesInformation,
UpdateTeamPackagesTask,
UpdateVersionInformation,
TagPackagesWithBugs,
retrieve_repository_info
)
from distro_tracker.test import TestCase
......
......@@ -37,14 +37,14 @@ from distro_tracker.core.tasks.base import (
)
from distro_tracker.core.tasks.mixins import (
ProcessItems,
ProcessModel,
ProcessSourcePackage,
ProcessMainRepoEntry,
ProcessModel,
ProcessRepositoryUpdates,
ProcessSourcePackage,
ProcessSrcRepoEntry,
ProcessSrcRepoEntryInDefaultRepository,
)
from distro_tracker.core.tasks.schedulers import Scheduler, IntervalScheduler
from distro_tracker.core.tasks.schedulers import IntervalScheduler, Scheduler
from distro_tracker.core.utils import now
from distro_tracker.core.utils.misc import get_data_checksum
from distro_tracker.test import TestCase
......
......@@ -15,6 +15,7 @@ Tests for the Distro Tracker template tags.
"""
from bs4 import BeautifulSoup as soup
from django.template import Context, Template
from distro_tracker.test import SimpleTestCase
......
......@@ -25,6 +25,7 @@ from email.mime.multipart import MIMEMultipart
from unittest import mock
from debian import deb822
from django.core import mail
from django.test.utils import override_settings
from django.urls import reverse
......
......@@ -8,14 +8,16 @@
# including this file, may be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
"""Various utilities for the distro-tracker project."""
from django.template.loader import render_to_string
from django.http import HttpResponse
from django.db import models
from django.conf import settings
import os
import datetime
import json
import os
from django.conf import settings
from django.db import models
from django.http import HttpResponse
from django.template.loader import render_to_string
import gpg
import datetime
from distro_tracker import vendor
......
......@@ -16,10 +16,11 @@ import os
import time
from hashlib import md5
import requests
from django.conf import settings
from django.utils import timezone
from django.utils.http import parse_http_date
import requests
from requests.structures import CaseInsensitiveDict
from .compression import get_uncompressed_stream, guess_compression_method
......
......@@ -15,12 +15,15 @@ import subprocess
import tarfile
import apt
import apt_pkg
from debian import deb822
from django.conf import settings
from django.urls import reverse
from django.utils.encoding import force_bytes
import apt_pkg
from distro_tracker.core.utils.email_messages import \
name_and_address_from_string as parse_address
from distro_tracker.core.utils.email_messages import \
......
......@@ -43,10 +43,8 @@ from distro_tracker.core.models import (
TeamMembership,
get_web_package
)
from distro_tracker.core.package_tables import create_table
from distro_tracker.core.panels import get_panels_for_package
from distro_tracker.core.package_tables import (
create_table,
)
from distro_tracker.core.utils import (
distro_tracker_render_to_string,
get_or_none,
......
......@@ -10,24 +10,23 @@
"""
Module implementing the processing of email control messages.
"""
import logging
import re
from email.iterators import typed_subpart_iterator
from django.conf import settings
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
from distro_tracker.core.utils import distro_tracker_render_to_string
from distro_tracker.core.utils import extract_email_address_from_header
from distro_tracker.core.utils import get_decoded_message_payload
from distro_tracker.core.utils.email_messages import decode_header
from distro_tracker.core.utils.email_messages import unfold_header
from distro_tracker.mail.control.commands import CommandFactory
from distro_tracker.mail.control.commands import CommandProcessor
from distro_tracker.mail.models import CommandConfirmation
import re
import logging
from django.conf import settings
DISTRO_TRACKER_CONTACT_EMAIL = settings.DISTRO_TRACKER_CONTACT_EMAIL
DISTRO_TRACKER_BOUNCES_EMAIL = settings.DISTRO_TRACKER_BOUNCES_EMAIL
......
......@@ -12,10 +12,10 @@
Defines and implements all Distro Tracker control commands.
"""
from django.conf import settings
import sys
import inspect
import sys
from django.conf import settings
from distro_tracker.core.utils import distro_tracker_render_to_string
from distro_tracker.mail.control.commands.base import Command
......
......@@ -18,6 +18,7 @@ from distro_tracker.core.models import (
ConfirmationManager,
UserEmail
)
from django_email_accounts.models import UserEmailManager
......
......@@ -18,9 +18,10 @@ from datetime import timedelta
from itertools import chain
from multiprocessing import Pool
import pyinotify
from django.conf import settings
import pyinotify
import distro_tracker.mail.control
import distro_tracker.mail.dispatch
from distro_tracker.core.utils import message_from_bytes
......
......@@ -19,11 +19,12 @@ from datetime import datetime, timedelta
from email.message import Message
from unittest import mock
import pyinotify
from django.conf import settings
from django.test.utils import override_settings
from django.utils.encoding import force_bytes
import pyinotify
from distro_tracker.core.utils.email_messages import message_from_bytes
from distro_tracker.mail.processor import (
ConflictingDeliveryAddresses,
......
......@@ -120,13 +120,14 @@ of those settings.
More settings:
"""
import django
from django.core.exceptions import ImproperlyConfigured
import os.path
import socket
from os.path import dirname
import django
from django.contrib.messages import constants as message_constants
from django.core.exceptions import ImproperlyConfigured
import socket
import os.path
if django.VERSION < (1, 11):
raise ImproperlyConfigured("Distro Tracker needs Django >= 1.11")
......
......@@ -19,8 +19,8 @@ from django.shortcuts import redirect
from django.views.generic import TemplateView
from distro_tracker.accounts.views import (
AccountMergeConfirmedView,
AccountMergeConfirmView,
AccountMergeConfirmedView,
AccountMergeFinalize,
AccountProfile,
ChangePersonalInfoView,
......@@ -60,16 +60,16 @@ from distro_tracker.core.views import (
PackageAutocompleteView,
PackageNews,
PackageSearchView,
TeamAutocompleteView,
TeamSearchView,
RemovePackageFromTeamView,
RemoveTeamMember,
SetMembershipKeywords,
SetMuteTeamView,
TeamAutocompleteView,
TeamDetailsView,
TeamListView,
UpdateTeamView,
TeamPackagesTableView,
TeamSearchView,
UpdateTeamView,
legacy_package_url_redirect,
legacy_rss_redirect,
news_page,
......
......@@ -14,6 +14,7 @@ Distro Tracker tasks for the :mod:`distro_tracker.stdver_warnings` app.
"""
from debian.debian_support import version_compare
from django.db import transaction
from django.db.models import Prefetch
......
......@@ -14,30 +14,32 @@
Distro Tracker test infrastructure.
"""
import shutil
import tempfile
import inspect
import os
import os.path
import inspect
import shutil
import tempfile
from bs4 import BeautifulSoup as soup
import django.test
from django.conf import settings
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
import django.test
from django.test.signals import setting_changed
from bs4 import BeautifulSoup as soup
from django_email_accounts.models import User
from distro_tracker.accounts.models import UserEmail
from distro_tracker.core.models import (
Architecture,
BinaryPackageName,
ContributorName,
Repository,
SourcePackage,
SourcePackageName,
Repository,
)
from distro_tracker.core.utils.packages import package_hashdir
from django_email_accounts.models import User
class TempDirsMixin(object):
"""
......
......@@ -19,7 +19,7 @@ import os.path
from django.conf import settings
from distro_tracker.core.models import PackageName, SourcePackage, Repository
from distro_tracker.core.models import PackageName, Repository, SourcePackage
from distro_tracker.test import (
SimpleTestCase,
TempDirsMixin,
......
......@@ -19,6 +19,7 @@ import re
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.utils.http import urlencode
from jsonfield import JSONField
from distro_tracker.core.models import (
......
......@@ -8,18 +8,17 @@
# including this file, may be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
import os.path
import re
import requests
from django import forms
from distro_tracker.core.package_tables import create_table
from django.conf import settings
from django.db.models import Prefetch
from django.utils.http import urlencode, urlquote_plus
from django.utils.safestring import mark_safe
import requests
from distro_tracker.core.models import (
ActionItem,
EmailNews,
......@@ -28,13 +27,14 @@ from distro_tracker.core.models import (
SourcePackageName,
UserEmail
)
from distro_tracker.core.package_tables import create_table
from distro_tracker.core.utils import get_decoded_message_payload, get_or_none
from distro_tracker.core.utils.http import HttpCache
from distro_tracker.mail import mail_news
from distro_tracker.vendor.common import PluginProcessingError
from distro_tracker.vendor.debian.tracker_tasks import UpdateNewQueuePackages
from .models import DebianContributor, DebianBugDisplayManager
from .models import DebianBugDisplayManager, DebianContributor
from .tracker_package_tables import UpstreamTableField
......
......@@ -14,16 +14,15 @@
Tests for Debian-specific modules/functionality of Distro Tracker.
"""
import gzip
import io
import json
import os
import yaml
import gzip
from email.message import Message
from unittest import mock
from bs4 import BeautifulSoup as soup
from django.core import mail
from django.core.management import call_command
from django.test.utils import override_settings
......@@ -31,6 +30,8 @@ from django.urls import reverse
from django.utils.encoding import force_bytes
from django.utils.functional import curry
import yaml
from distro_tracker.accounts.models import User, UserEmail
from distro_tracker.core.models import (
ActionItem,
......@@ -69,12 +70,12 @@ from distro_tracker.vendor.debian.models import (
UbuntuPackage
)
from distro_tracker.vendor.debian.rules import (
additional_prefetch_related_lookups,
classify_message,
get_developer_information_url,
get_maintainer_extra,
get_package_information_site_url,
get_uploader_extra,
additional_prefetch_related_lookups,
get_vcs_data,
)
from distro_tracker.vendor.debian.sso_auth import DebianSsoUserBackend
......@@ -91,9 +92,9 @@ from distro_tracker.vendor.debian.tracker_tasks import (
UpdateAutoRemovalsStatsTask,
UpdateBuildLogCheckStats,
UpdateBuildReproducibilityTask,
UpdateDependencySatisfactionTask,
UpdateDebciStatusTask,
UpdateDebianDuckTask,
UpdateDependencySatisfactionTask,
UpdateExcusesTask,
UpdateLintianStatsTask,
UpdateNewQueuePackages,
......
......@@ -11,6 +11,7 @@
# except according to the terms contained in the LICENSE file.
from django.db.models import Prefetch
from distro_tracker.core.models import (
PackageData,
)
......
......@@ -21,16 +21,20 @@ import os
import re
from enum import Enum
import debianbts
import yaml
from bs4 import BeautifulSoup as soup
from debian import deb822, debian_support
from debian.debian_support import AptPkgVersion
import debianbts
from django.conf import settings
from django.db import transaction
from django.db.models import Prefetch
from django.utils.http import urlencode
import yaml
from distro_tracker import vendor
from distro_tracker.accounts.models import UserEmail
from distro_tracker.core.models import (
......@@ -49,13 +53,13 @@ from distro_tracker.core.models import (
from distro_tracker.core.tasks import BaseTask
from distro_tracker.core.tasks.mixins import PackageTagging
from distro_tracker.core.tasks.schedulers import IntervalScheduler
from distro_tracker.core.utils import get_or_none
from distro_tracker.core.utils.http import (
HttpCache,
get_resource_content,
get_resource_text
)
from distro_tracker.core.utils.misc import get_data_checksum
from distro_tracker.core.utils import get_or_none
from distro_tracker.core.utils.packages import (
html_package_list,
package_hashdir,
......
......@@ -11,9 +11,10 @@
This Django app implements a custom User authentication model which lets users
log in using a set of different email addresses.
"""
from django.conf import settings
import importlib
from django.conf import settings
def run_hook(name, *args, **kwargs):
"""
......
......@@ -42,7 +42,7 @@ master_doc = 'index'
# General information about the project.
project = u'Distro Tracker'
copyright = u'2013, The Distro Tracker Developers'
copyright = u'2013-2018, The Distro Tracker Developers'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
......@@ -86,6 +86,9 @@ exclude_patterns = ['_build']
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# Format code blocks as Python code
highlight_language = 'python'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
......
......@@ -181,13 +181,40 @@ Conventions
2. Functions are documented using doctrings with `Sphinx markup
<http://sphinx-doc.org/en/master/>`_.
3. Imports are sorted in 3 groups separated by one empty line: first the
Python standard modules, then the third-party modules and finally
the project modules. Each group is further split in two between
``import foo`` statements and ``from foo import bar`` statements.
Within each group entries are alphabetically sorted. The isort
command used to implement the initial formatting was ``isort -m 3 -l
80 -rc django_email_accounts/ distro_tracker/``.
3. Imports are sorted in multiple groups separated by one empty line:
first a group for ``__future__`` imports, then a single group for all
the Python standard modules, then one group for each third-party
module (and groups are sorted between them as well), followed by
groups for the project modules (one group for ``distro_tracker`` and
one group for ``django_email_accounts``), and last, one group for
relative imports.
Within each group the ``import foo`` statements are grouped and
sorted at the top, while the ``from foo import bar`` statements
are grouped and sorted at the end.
Example:
.. code-block:: python3
from __future__ import print_function
import datetime
import os
from datetime import timedelta
from email.utils import getaddresses, parseaddr
from django.conf import settings
from django.db import connection, models
from django.utils.safestring import mark_safe
import requests
from requests.structures import CaseInsensitiveDict
from distro_tracker.core.models import SourcePackage
from distro_tracker.core.utils import get_or_none
from django_email_accounts.models import User
Git commit notices
~~~~~~~~~~~~~~~~~~
......
......@@ -11,14 +11,14 @@
"""
Functional tests for Distro Tracker.
"""
from unittest import mock
import os
import time