Jean-Frédéric has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/378741 )
Change subject: Use isort to sort imports
......................................................................
Use isort to sort imports
isort is a Python utility to sort imports alphabetically,
and automatically separated into sections.
This adds to `setup.cfg` an isort config closely mimicking
our current conventions (cf `multi_line_output`), and
updates the entire codebase.
Change-Id: Id37f2e645db0c93951916410f0fbd34fee0b62be
---
M bin/deploy_message_from_git_log.py
M erfgoedbot/add_coord_to_articles.py
M erfgoedbot/add_object_location_monuments.py
M erfgoedbot/categorize_images.py
M erfgoedbot/converters.py
M erfgoedbot/database_connection.py
M erfgoedbot/fill_table_monuments_all.py
M erfgoedbot/images_of_monuments_without_id.py
M erfgoedbot/missing_commonscat_links.py
M erfgoedbot/monument_tables.py
M erfgoedbot/monuments_config.py
M erfgoedbot/populate_image_table.py
M erfgoedbot/unused_monument_images.py
M erfgoedbot/update_database.py
M erfgoedbot/update_id_dump.py
M setup.cfg
M tests/test_categorization.py
M tests/test_checkers.py
M tests/test_common.py
M tests/test_converters.py
M tests/test_database_connection.py
M tests/test_database_statistics.py
M tests/test_fill_table.py
M tests/test_monument_tables.py
M tests/test_monuments_config.py
M tests/test_populate_image_table.py
M tests/test_update_database.py
27 files changed, 72 insertions(+), 48 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/labs/tools/heritage
refs/changes/41/378741/1
diff --git a/bin/deploy_message_from_git_log.py
b/bin/deploy_message_from_git_log.py
index fa609d4..8e6c8de 100644
--- a/bin/deploy_message_from_git_log.py
+++ b/bin/deploy_message_from_git_log.py
@@ -4,7 +4,6 @@
import re
import subprocess
-
GIT_COMMIT_FIELDS = ['id', 'message']
GIT_LOG_FORMAT_FIELDS = ['%h', '%b']
GIT_LOG_FORMAT = '%x1f'.join(GIT_LOG_FORMAT_FIELDS) + '%x1e'
diff --git a/erfgoedbot/add_coord_to_articles.py
b/erfgoedbot/add_coord_to_articles.py
index 5a9950e..b6356f0 100644
--- a/erfgoedbot/add_coord_to_articles.py
+++ b/erfgoedbot/add_coord_to_articles.py
@@ -19,12 +19,12 @@
import pywikibot
-import monuments_config as mconfig
import common as common
+import monuments_config as mconfig
from database_connection import (
close_database_connection,
- connect_to_monuments_database,
- connect_to_commons_database
+ connect_to_commons_database,
+ connect_to_monuments_database
)
# coordinate templates for different language wikipedias
diff --git a/erfgoedbot/add_object_location_monuments.py
b/erfgoedbot/add_object_location_monuments.py
index 1ffc23f..c8a18d8 100644
--- a/erfgoedbot/add_object_location_monuments.py
+++ b/erfgoedbot/add_object_location_monuments.py
@@ -11,8 +11,8 @@
import monuments_config as mconfig
from database_connection import (
close_database_connection,
- connect_to_monuments_database,
- connect_to_commons_database
+ connect_to_commons_database,
+ connect_to_monuments_database
)
diff --git a/erfgoedbot/categorize_images.py b/erfgoedbot/categorize_images.py
index 1705d56..23c05d7 100644
--- a/erfgoedbot/categorize_images.py
+++ b/erfgoedbot/categorize_images.py
@@ -20,11 +20,10 @@
import os
import pywikibot
-from pywikibot import pagegenerators
-from pywikibot import textlib
+from pywikibot import pagegenerators, textlib
-import monuments_config as mconfig
import common as common
+import monuments_config as mconfig
from database_connection import (
close_database_connection,
connect_to_monuments_database
diff --git a/erfgoedbot/converters.py b/erfgoedbot/converters.py
index 92abc44..6747319 100644
--- a/erfgoedbot/converters.py
+++ b/erfgoedbot/converters.py
@@ -4,6 +4,7 @@
"""Conversion methods"""
import re
+
from checkers import is_int
diff --git a/erfgoedbot/database_connection.py
b/erfgoedbot/database_connection.py
index 741b061..1438e8a 100644
--- a/erfgoedbot/database_connection.py
+++ b/erfgoedbot/database_connection.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import os
+
import MySQLdb
import yaml
diff --git a/erfgoedbot/fill_table_monuments_all.py
b/erfgoedbot/fill_table_monuments_all.py
index 4193478..41d577a 100644
--- a/erfgoedbot/fill_table_monuments_all.py
+++ b/erfgoedbot/fill_table_monuments_all.py
@@ -2,9 +2,11 @@
# -*- coding: utf-8 -*-
"""Create the fill_table_monuments_all SQL."""
from __future__ import unicode_literals
-import os
+
import json
+import os
from collections import OrderedDict
+
import pywikibot
diff --git a/erfgoedbot/images_of_monuments_without_id.py
b/erfgoedbot/images_of_monuments_without_id.py
index 5413ea1..62189bf 100644
--- a/erfgoedbot/images_of_monuments_without_id.py
+++ b/erfgoedbot/images_of_monuments_without_id.py
@@ -18,8 +18,8 @@
import monuments_config as mconfig
from database_connection import (
close_database_connection,
- connect_to_monuments_database,
- connect_to_commons_database
+ connect_to_commons_database,
+ connect_to_monuments_database
)
diff --git a/erfgoedbot/missing_commonscat_links.py
b/erfgoedbot/missing_commonscat_links.py
index fd5898d..cc81a12 100644
--- a/erfgoedbot/missing_commonscat_links.py
+++ b/erfgoedbot/missing_commonscat_links.py
@@ -18,8 +18,8 @@
import monuments_config as mconfig
from database_connection import (
close_database_connection,
- connect_to_monuments_database,
- connect_to_commons_database
+ connect_to_commons_database,
+ connect_to_monuments_database
)
_logger = "missing_commonscat"
diff --git a/erfgoedbot/monument_tables.py b/erfgoedbot/monument_tables.py
index 15bee1e..a6fd148 100755
--- a/erfgoedbot/monument_tables.py
+++ b/erfgoedbot/monument_tables.py
@@ -6,6 +6,7 @@
Author: Platonides
"""
import os
+
import monuments_config as mconfig
diff --git a/erfgoedbot/monuments_config.py b/erfgoedbot/monuments_config.py
index a12c660..788dd5d 100755
--- a/erfgoedbot/monuments_config.py
+++ b/erfgoedbot/monuments_config.py
@@ -4,8 +4,8 @@
Configuration for the monuments bot.
'''
-import os
import json
+import os
def _get_config_dir():
diff --git a/erfgoedbot/populate_image_table.py
b/erfgoedbot/populate_image_table.py
index 5ceac15..952e67c 100644
--- a/erfgoedbot/populate_image_table.py
+++ b/erfgoedbot/populate_image_table.py
@@ -34,8 +34,8 @@
import monuments_config as mconfig
from database_connection import (
close_database_connection,
- connect_to_monuments_database,
- connect_to_commons_database
+ connect_to_commons_database,
+ connect_to_monuments_database
)
diff --git a/erfgoedbot/unused_monument_images.py
b/erfgoedbot/unused_monument_images.py
index 16e6ebe..27d4553 100644
--- a/erfgoedbot/unused_monument_images.py
+++ b/erfgoedbot/unused_monument_images.py
@@ -13,12 +13,12 @@
'''
import pywikibot
-import monuments_config as mconfig
import common as common
+import monuments_config as mconfig
from database_connection import (
close_database_connection,
- connect_to_monuments_database,
- connect_to_commons_database
+ connect_to_commons_database,
+ connect_to_monuments_database
)
_logger = "unused_images"
diff --git a/erfgoedbot/update_database.py b/erfgoedbot/update_database.py
index b124386..1718d11 100755
--- a/erfgoedbot/update_database.py
+++ b/erfgoedbot/update_database.py
@@ -11,11 +11,11 @@
python update_database.py -countrycode:XX -langcode:YY
'''
-import os
-import warnings
import datetime
-import urlparse
+import os
import time
+import urlparse
+import warnings
from requests.exceptions import Timeout
@@ -24,21 +24,21 @@
from pywikibot import pagegenerators
from pywikibot.exceptions import OtherPageSaveError
-import monuments_config as mconfig
import common as common
-from converters import (
- extractWikilink,
- extract_elements_from_template_param,
- remove_commons_category_prefix,
- CH1903Converter,
- int_to_european_digits
-)
+import monuments_config as mconfig
from checkers import (
- checkLat,
- checkLon,
- check_wikidata,
check_integer,
- check_lat_with_lon
+ check_lat_with_lon,
+ check_wikidata,
+ checkLat,
+ checkLon
+)
+from converters import (
+ CH1903Converter,
+ extract_elements_from_template_param,
+ extractWikilink,
+ int_to_european_digits,
+ remove_commons_category_prefix
)
from database_connection import (
close_database_connection,
diff --git a/erfgoedbot/update_id_dump.py b/erfgoedbot/update_id_dump.py
index b4b16b2..0170efa 100755
--- a/erfgoedbot/update_id_dump.py
+++ b/erfgoedbot/update_id_dump.py
@@ -16,9 +16,7 @@
from pywikibot import pagegenerators
import monuments_config as mconfig
-from converters import (
- extract_elements_from_template_param
-)
+from converters import extract_elements_from_template_param
from database_connection import (
close_database_connection,
connect_to_monuments_database
diff --git a/setup.cfg b/setup.cfg
index c66ce3d..e487f8c 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -4,3 +4,10 @@
cover-erase=1
cover-inclusive=1
cover-package=erfgoedbot
+
+[isort]
+known_first_party = erfgoedbot
+known_pywikibot = pywikibot
+multi_line_output = 3
+sections = FUTURE,STDLIB,THIRDPARTY,PYWIKIBOT,FIRSTPARTY,LOCALFOLDER
+skip_glob = .tox/*
diff --git a/tests/test_categorization.py b/tests/test_categorization.py
index 0b3be6f..e572366 100644
--- a/tests/test_categorization.py
+++ b/tests/test_categorization.py
@@ -3,7 +3,9 @@
# from pywikibot.site import APISite
# from pywikibot.exceptions import NoPage
import unittest
+
import mock
+
from erfgoedbot import categorize_images
diff --git a/tests/test_checkers.py b/tests/test_checkers.py
index 5f14221..7f4db94 100644
--- a/tests/test_checkers.py
+++ b/tests/test_checkers.py
@@ -4,9 +4,10 @@
Those that aren't checked through test_update_database
"""
-import mock
import unittest
+import mock
+
from erfgoedbot import checkers
diff --git a/tests/test_common.py b/tests/test_common.py
index 2f016c0..02db3f8 100644
--- a/tests/test_common.py
+++ b/tests/test_common.py
@@ -1,7 +1,9 @@
"""Unit tests for common."""
import unittest
+
import mock
+
from erfgoedbot import common
diff --git a/tests/test_converters.py b/tests/test_converters.py
index 7dee613..600022f 100644
--- a/tests/test_converters.py
+++ b/tests/test_converters.py
@@ -2,14 +2,15 @@
"""Unit tests for converters."""
import unittest
+
from erfgoedbot.converters import (
- ucfirst,
- extractWikilink,
+ CH1903Converter,
extract_elements_from_template_param,
+ extractWikilink,
+ int_to_european_digits,
remove_commons_category_prefix,
sanitize_wikitext_string,
- CH1903Converter,
- int_to_european_digits
+ ucfirst
)
diff --git a/tests/test_database_connection.py
b/tests/test_database_connection.py
index 519d5ba..3e556cf 100644
--- a/tests/test_database_connection.py
+++ b/tests/test_database_connection.py
@@ -2,10 +2,12 @@
import os
import unittest
+
import mock
-from erfgoedbot import database_connection
from MySQLdb.connections import Connection
+from erfgoedbot import database_connection
+
class TestGetDatabaseConfigFile(unittest.TestCase):
diff --git a/tests/test_database_statistics.py
b/tests/test_database_statistics.py
index 95dcad7..72a2472 100644
--- a/tests/test_database_statistics.py
+++ b/tests/test_database_statistics.py
@@ -3,7 +3,9 @@
# from pywikibot.site import APISite
# from pywikibot.exceptions import NoPage
import unittest
+
import mock
+
from erfgoedbot import database_statistics
diff --git a/tests/test_fill_table.py b/tests/test_fill_table.py
index 2cc83cf..bcc8283 100644
--- a/tests/test_fill_table.py
+++ b/tests/test_fill_table.py
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
"""Validation for fill_table_monuments_all.sql with monuments_config.py."""
-import unittest
import re
+import unittest
+
from custom_assertions import CustomAssertions
-from erfgoedbot import monuments_config as config
from erfgoedbot import fill_table_monuments_all as fill_table
+from erfgoedbot import monuments_config as config
def isolate_dataset_entries(text):
diff --git a/tests/test_monument_tables.py b/tests/test_monument_tables.py
index 8a85ade..84ff558 100644
--- a/tests/test_monument_tables.py
+++ b/tests/test_monument_tables.py
@@ -3,6 +3,7 @@
"""Unit tests for update_database."""
import unittest
+
import mock
from erfgoedbot import monument_tables
diff --git a/tests/test_monuments_config.py b/tests/test_monuments_config.py
index fdd5353..5d2d197 100644
--- a/tests/test_monuments_config.py
+++ b/tests/test_monuments_config.py
@@ -2,6 +2,7 @@
"""Validation for monuments_config."""
import unittest
+
from custom_assertions import CustomAssertions
from erfgoedbot import monuments_config as config
diff --git a/tests/test_populate_image_table.py
b/tests/test_populate_image_table.py
index 496811b..0b55974 100644
--- a/tests/test_populate_image_table.py
+++ b/tests/test_populate_image_table.py
@@ -3,9 +3,10 @@
"""Unit tests for populate_image_table."""
-import mock
import unittest
+import mock
+
from erfgoedbot import populate_image_table
diff --git a/tests/test_update_database.py b/tests/test_update_database.py
index 1145984..bb04a0b 100644
--- a/tests/test_update_database.py
+++ b/tests/test_update_database.py
@@ -1,7 +1,9 @@
"""Unit tests for update_database."""
-import mock
import unittest
+
+import mock
+
import pywikibot
from erfgoedbot import update_database
--
To view, visit https://gerrit.wikimedia.org/r/378741
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id37f2e645db0c93951916410f0fbd34fee0b62be
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/heritage
Gerrit-Branch: master
Gerrit-Owner: Jean-Frédéric <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits