From 98c0a4fc3d228ca0aa011801234830c6e4a3a375 Mon Sep 17 00:00:00 2001 From: Jon Banafato Date: Sat, 9 Nov 2019 10:45:01 -0500 Subject: [PATCH] Use isort [isort](https://isort.readthedocs.io/en/latest/) sorts your Python imports so you don't have to. This makes sure that imports are always where they should be and prevents issues like duplicated imports and merge conflicts. Using pre-commit, this can be done automatically without any manual steps. Depends on #9. --- .pre-commit-config.yaml | 12 ++++++++++++ __init__.py | 5 +++-- lib/api_hooks.py | 2 ++ lib/display.py | 3 ++- lib/storage.py | 4 +++- main.py | 7 +++---- pyproject.toml | 10 ++++++++++ tests/__init__.py | 1 + tests/test_bookserver.py | 3 ++- tests/test_storage.py | 3 ++- 10 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 pyproject.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fefb2fa..47976ea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,3 +10,15 @@ repos: rev: v1.3.0 hooks: - id: trailing-whitespace + + # Python import formatting + - repo: https://github.com/asottile/seed-isort-config + rev: v1.9.3 + hooks: + - id: seed-isort-config + + - repo: https://github.com/timothycrosley/isort + rev: 4.3.21-2 + hooks: + - id: isort + additional_dependencies: ["toml"] diff --git a/__init__.py b/__init__.py index d68f921..9a3cbc8 100755 --- a/__init__.py +++ b/__init__.py @@ -1,3 +1,4 @@ -import sys import os -sys.path.insert(0, os.path.abspath('.')) \ No newline at end of file +import sys + +sys.path.insert(0, os.path.abspath('.')) diff --git a/lib/api_hooks.py b/lib/api_hooks.py index 6d18080..239f88a 100644 --- a/lib/api_hooks.py +++ b/lib/api_hooks.py @@ -1,6 +1,8 @@ #!/usr/bin/python import sys + import requests + # sys.path.insert(1, 'lib/') diff --git a/lib/display.py b/lib/display.py index 5c37a4a..9e89641 100644 --- a/lib/display.py +++ b/lib/display.py @@ -2,9 +2,10 @@ import cgi import sys -sys.path.insert(0, '../') from config import Config +sys.path.insert(0, '../') + class Frontend(): """Dynamic frontend display functions""" diff --git a/lib/storage.py b/lib/storage.py index a5ee801..196cc95 100644 --- a/lib/storage.py +++ b/lib/storage.py @@ -1,8 +1,10 @@ #!/usr/bin/python -import sys import sqlite3 +import sys + # sys.path.insert(1, '../') from config import Config + db_pointer = Config().catalogue_db diff --git a/main.py b/main.py index c8f3f6f..7ee3fd1 100755 --- a/main.py +++ b/main.py @@ -2,11 +2,10 @@ import sys from config import Config -from lib.library import Catalogue -from lib.pyShelf import InitFiles -from lib.pyShelf import BookServer -from lib.pyShelf import BookDisplay from lib.display import Frontend +from lib.library import Catalogue +from lib.pyShelf import BookDisplay, BookServer, InitFiles + # sys.path.insert(1, 'lib/') config = Config() # Get configuration settings diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..31ec3a3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[tool.isort] +force_grid_wrap = 0 +include_trailing_comma = true +line_length = 88 +multi_line_output = 3 +use_parentheses = true +# NOTE: the known_third_party setting is managed by +# seed-isort-config and should not be modified directly. +# Any changes made to this setting will be overwritten. +known_third_party = ["PIL", "bs4", "requests"] diff --git a/tests/__init__.py b/tests/__init__.py index b8bb7c9..19a5a0d 100755 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,2 +1,3 @@ import sys + sys.path.insert(1, '../lib/') diff --git a/tests/test_bookserver.py b/tests/test_bookserver.py index 72400fc..ebaead2 100644 --- a/tests/test_bookserver.py +++ b/tests/test_bookserver.py @@ -1,8 +1,9 @@ import sys import unittest -from lib.pyShelf import BookDisplay, BookServer from lib.display import Frontend +from lib.pyShelf import BookDisplay, BookServer + sys.path.insert(0, '../lib') sys.path.insert(1, '../') diff --git a/tests/test_storage.py b/tests/test_storage.py index f3dabf5..ba099d3 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -1,5 +1,6 @@ -import unittest import sys +import unittest + # sys.path.insert(1, '../') from lib.storage import Storage