Skip to content

Commit

Permalink
use isort to sort python imports
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieucan committed May 2, 2021
1 parent 4407efc commit 3763280
Show file tree
Hide file tree
Showing 50 changed files with 195 additions and 220 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Build and test:
services:
- docker:dind
before_script:
- apk add black=20.8_beta1-r0 py3-flake8 docker-compose make
- apk add black=20.8_beta1-r0 py3-flake8 py3-isort docker-compose make
script:
- cd contrib/docker
- make build
Expand Down
23 changes: 10 additions & 13 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,23 @@ All new Debsources code should be [PEP8][1] compliant and pass [pyflakes][2]
validation. Before submitting patches, please make sure that the lines of code
they touch conform to such requirements.

Additionally, `black` [3] is used to format Python source files.
Additionally, `black` [3] and `isort` [4] are used to format Python source
files.

[1]: https://www.python.org/dev/peps/pep-0008/
[2]: https://pypi.python.org/pypi/pyflakes
[3]: https://black.readthedocs.io/en/stable/
[4]: https://pycqa.github.io/isort/

If you develop on Debian(-based distros), a good way to check that this is the
case is:

# apt-get install python-flake8
$ flake8 file1.py file2.py ...

You can check all Debsources Python source files black and flake8 compliance
with:
If you develop on Debian(-based distros), a good way to apply formatting and
check that everything is good is:

# apt-get install flake8 isort
$ python3 -m pip install --user black
$ make format
$ make check

You can add a pre-commit hook to automatically test PEP8 compliance:
You can add a pre-commit hook to automatically test PEP8 compliance (might be
outdated):

$ ln -s ../../contrib/git-pre-commit .git/hooks/pre-commit

If you stumble upon Debsources source files that are not flake8-compliant,
patches that put them back in compliance are more than welcome (hint hint).
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ NOSE = nosetests3
FLAKE = flake8 --max-line-length 88 --ignore=E203,W503
# E203 (whitespace before ':') conflicts with black formatting
# W503 (line break before binary operator), ditto
BLACK = black --check
BLACK = black
ISORT = isort --profile black --dont-follow-links -p debsources

SRCDIR = lib/debsources
BINDIR = bin
Expand Down Expand Up @@ -32,7 +33,13 @@ test-coverage:

check:
$(FLAKE) $(SRCDIR)/ $(shell grep -H 'env python' $(BINDIR)/debsources-* | cut -f 1 -d :)
$(BLACK) --check $(SRCDIR)
# deactivated for now - until isort>=5 is available on Alpine Linux for CICD pipeline
# $(ISORT) --check $(SRCDIR) $(BINDIR)

format:
$(BLACK) $(SRCDIR)
$(ISORT) $(SRCDIR) $(BINDIR)

test-online-app:
contrib/test-online-app
Expand Down
6 changes: 2 additions & 4 deletions bin/debsources-bulk-insert-checksums
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
# see the COPYING file at the top-level directory of this distribution and at
# https://salsa.debian.org/qa/debsources/blob/master/COPYING

from __future__ import absolute_import

import argparse
import logging

from sqlalchemy import create_engine, bindparam, LargeBinary
from sqlalchemy import LargeBinary, bindparam, create_engine
from sqlalchemy.sql import text as sql_query

from debsources import mainlib
from debsources import fs_storage
from debsources import fs_storage, mainlib
from debsources.plugins.hook_checksums import parse_checksums

METADATA_SUFFIX = ".checksums"
Expand Down
8 changes: 2 additions & 6 deletions bin/debsources-bulk-insert-ctags
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@
# see the COPYING file at the top-level directory of this distribution and at
# https://salsa.debian.org/qa/debsources/blob/master/COPYING

from __future__ import absolute_import

import argparse
import logging


from debsources import mainlib

from sqlalchemy import create_engine, bindparam, LargeBinary
from sqlalchemy import LargeBinary, bindparam, create_engine
from sqlalchemy.sql import text as sql_query

from debsources import fs_storage
from debsources import fs_storage, mainlib
from debsources.plugins.hook_ctags import parse_ctags

METADATA_SUFFIX = ".ctags"
Expand Down
3 changes: 0 additions & 3 deletions bin/debsources-dbadmin
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# see the COPYING file at the top-level directory of this distribution and at
# https://salsa.debian.org/qa/debsources/blob/master/COPYING

from __future__ import absolute_import
from __future__ import print_function

import argparse
import time
Expand All @@ -22,7 +20,6 @@ from sqlalchemy import create_engine

from debsources.models import Base


if __name__ == "__main__":
start_time = time.time()

Expand Down
6 changes: 1 addition & 5 deletions bin/debsources-fsck
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

# Check for DB/FS inconsistencies

from __future__ import absolute_import

import argparse
import logging
Expand All @@ -24,10 +23,7 @@ from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from debsources import mainlib
from debsources import db_storage
from debsources import fs_storage

from debsources import db_storage, fs_storage, mainlib
from debsources.debmirror import SourcePackage
from debsources.models import Package

Expand Down
2 changes: 0 additions & 2 deletions bin/debsources-run-app
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# see the COPYING file at the top-level directory of this distribution and at
# https://salsa.debian.org/qa/debsources/blob/master/COPYING

from __future__ import absolute_import
from __future__ import print_function

import argparse

Expand Down
6 changes: 2 additions & 4 deletions bin/debsources-shell
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
# see the COPYING file at the top-level directory of this distribution and at
# https://salsa.debian.org/qa/debsources/blob/master/COPYING

from __future__ import absolute_import

import argparse
import code
import os
import readline
import rlcompleter # NOQA
import argparse

from debsources import mainlib
from debsources import sqla_session
from debsources import mainlib, sqla_session
from debsources.models import * # NOQA


Expand Down
8 changes: 2 additions & 6 deletions bin/debsources-suite-archive
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@
# see the COPYING file at the top-level directory of this distribution and at
# https://salsa.debian.org/qa/debsources/blob/master/COPYING

from __future__ import absolute_import
from __future__ import print_function

import argparse
import logging
import sqlalchemy
import sys

import sqlalchemy

from debsources import archiver
from debsources import debmirror
from debsources import mainlib
from debsources import archiver, debmirror, mainlib


def main():
Expand Down
7 changes: 3 additions & 4 deletions bin/debsources-update
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
# see the COPYING file at the top-level directory of this distribution and at
# https://salsa.debian.org/qa/debsources/blob/master/COPYING

from __future__ import absolute_import

import argparse
import logging
import sqlalchemy
import sys

from debsources import mainlib
from debsources import updater
import sqlalchemy

from debsources import mainlib, updater


def main():
Expand Down
2 changes: 1 addition & 1 deletion lib/debsources/app/app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


import logging
from logging import Formatter, FileHandler, StreamHandler
from logging import FileHandler, Formatter, StreamHandler

from flask import Flask

Expand Down
17 changes: 9 additions & 8 deletions lib/debsources/app/copyright/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@
# https://salsa.debian.org/qa/debsources/blob/master/COPYING


from flask import jsonify, request, render_template
from flask import jsonify, render_template, request

from debsources.excepts import Http404Error

from ..helper import bind_render, generic_before_request
from . import bp_copyright
from ..views import (
ErrorHandler,
IndexView,
PrefixView,
ListPackagesView,
ErrorHandler,
Ping,
NewsArchiveView,
PackageVersionsView,
Ping,
PrefixView,
SearchView,
NewsArchiveView,
)
from .views import LicenseView, ChecksumLicenseView, SearchFileView, StatsView
from debsources.excepts import Http404Error
from . import bp_copyright
from .views import ChecksumLicenseView, LicenseView, SearchFileView, StatsView


# context vars
Expand Down
19 changes: 10 additions & 9 deletions lib/debsources/app/copyright/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,29 @@
# https://salsa.debian.org/qa/debsources/blob/master/COPYING


from collections import defaultdict, Counter
from collections import Counter, defaultdict
from functools import cmp_to_key
from pathlib import Path

from flask import current_app, request
from debian.debian_support import version_compare
from debian import copyright
from debian.debian_support import version_compare
from flask import current_app, request

import debsources.license_helper as helper
import debsources.query as qry
import debsources.statistics as statistics
from debsources.excepts import (
Http404ErrorSuggestions,
FileOrFolderNotFound,
InvalidPackageOrVersionError,
Http404MissingCopyright,
Http404Error,
Http404ErrorSuggestions,
Http404MissingCopyright,
InvalidPackageOrVersionError,
)
from ..views import GeneralView, ChecksumView, session, app
from ..sourcecode import SourceCodeIterator
from ..pagination import Pagination

from ..extract_stats import extract_stats
from ..pagination import Pagination
from ..sourcecode import SourceCodeIterator
from ..views import ChecksumView, GeneralView, app, session


class LicenseView(GeneralView):
Expand Down
5 changes: 2 additions & 3 deletions lib/debsources/app/doc/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
# https://salsa.debian.org/qa/debsources/blob/master/COPYING


from . import bp_doc

from ..helper import bind_render
from ..views import DocView, AboutView, ErrorHandler
from ..views import AboutView, DocView, ErrorHandler
from . import bp_doc

# site errors
# XXX 500 handler cannot be registered on a blueprint
Expand Down
2 changes: 1 addition & 1 deletion lib/debsources/app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# https://salsa.debian.org/qa/debsources/blob/master/COPYING


from flask_wtf import FlaskForm
from wtforms import TextField
from wtforms.validators import Required
from flask_wtf import FlaskForm


class SearchForm(FlaskForm):
Expand Down
7 changes: 4 additions & 3 deletions lib/debsources/app/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@


from functools import cmp_to_key, partial
from debian.debian_support import version_compare

from flask import request, url_for, render_template, redirect
from debian.debian_support import version_compare
from flask import redirect, render_template, request, url_for

import debsources.query as qry
from debsources.excepts import Http404Error, InvalidPackageOrVersionError
from debsources.models import SuiteAlias
from debsources.excepts import InvalidPackageOrVersionError, Http404Error

from . import app_wrapper

session = app_wrapper.session
Expand Down
6 changes: 3 additions & 3 deletions lib/debsources/app/infobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
# https://salsa.debian.org/qa/debsources/blob/master/COPYING


from flask import url_for, current_app
from flask import current_app, url_for

from debsources.models import PackageName, Package, Suite, SlocCount, Metric, Ctag
from debsources.excepts import Http500Error, Http404Error
from debsources.excepts import Http404Error, Http500Error
from debsources.models import Ctag, Metric, Package, PackageName, SlocCount, Suite

PTS_PREFIX = "https://tracker.debian.org/pkg/"
# XXX move this to configuration file?
Expand Down
3 changes: 1 addition & 2 deletions lib/debsources/app/patches/patches_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
# of the License, or (at your option) any later version. For more information
# see the COPYING file at the top-level directory of this distribution and at
# https://salsa.debian.org/qa/debsources/blob/master/COPYING
import re
import io
import logging
import re
import subprocess

from debsources.navigation import Location, SourceFile


ACCEPTED_FORMATS = ["3.0 (quilt)", "3.0 (native)"]


Expand Down
14 changes: 7 additions & 7 deletions lib/debsources/app/patches/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
# https://salsa.debian.org/qa/debsources/blob/master/COPYING


from flask import jsonify, request, render_template
from flask import jsonify, render_template, request

from . import bp_patches
from debsources.excepts import Http404Error

from ..helper import bind_render, generic_before_request
from ..views import (
ErrorHandler,
IndexView,
ListPackagesView,
NewsArchiveView,
Ping,
PrefixView,
ErrorHandler,
ListPackagesView,
SearchView,
NewsArchiveView,
)
from .views import SummaryView, PatchView, VersionsView
from debsources.excepts import Http404Error
from . import bp_patches
from .views import PatchView, SummaryView, VersionsView


# context vars
Expand Down
Loading

0 comments on commit 3763280

Please sign in to comment.