Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add black and isort #1115

Merged
merged 4 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
361ba8821de684b077dcad34bea3d16df246a8c4
23 changes: 22 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
DEFAULT_GOAL: help
SHELL := /bin/bash

.PHONY: venv
venv: ## Provision a Python 3 virtualenv for development.
python3 -m venv .venv
.venv/bin/pip install --require-hashes -r dev-requirements.txt

.PHONY: black
black: ## Format Python source code with black
@black setup.py securedrop_client tests

.PHONY: check-black
check-black: ## Check Python source code formatting with black
@black --check --diff setup.py securedrop_client tests

.PHONY: isort
isort: ## Run isort to organize Python imports
@isort --recursive setup.py securedrop_client tests

.PHONY: check-isort
check-isort: ## Check Python import organization with isort
@isort --check-only --diff --recursive setup.py securedrop_client tests

.PHONY: mypy
mypy: ## Run static type checker
@mypy --ignore-missing-imports securedrop_client
Expand Down Expand Up @@ -80,7 +101,7 @@ bandit: ## Run bandit with medium level excluding test-related folders
bandit -ll --recursive . --exclude ./tests,./.venv

.PHONY: check
check: clean bandit lint mypy test-random test-integration test-functional ## Run the full CI test suite
check: clean check-black check-isort bandit lint mypy test-random test-integration test-functional ## Run the full CI test suite

.PHONY: update-pip-requirements
update-pip-requirements: ## Updates all Python requirements files via pip-compile for Linux.
Expand Down
2 changes: 2 additions & 0 deletions dev-requirements.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
atomicwrites==1.2.1
attrs==18.2.0
black==19.10b0
Click==7.0
coverage==4.5.1
flake8==3.6.0
flaky==3.6.1
isort==4.3.21
MarkupSafe>=1.1
mccabe==0.6.1
more-itertools==4.3.0
Expand Down
69 changes: 56 additions & 13 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ apipkg==1.5 \
--hash=sha256:37228cda29411948b422fae072f57e31d3396d2ee1c9783775980ee9c9990af6 \
--hash=sha256:58587dd4dc3daefad0487f6d9ae32b4542b185e1c36db6993290e7c41ca2b47c \
# via execnet
appdirs==1.4.4 \
--hash=sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41 \
--hash=sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128 \
# via black
arrow==0.12.1 \
--hash=sha256:a558d3b7b6ce7ffc74206a86c147052de23d3d4ef0e17c210dd478c53575c4cd \
# via -r requirements.in
Expand All @@ -21,7 +25,11 @@ atomicwrites==1.2.1 \
attrs==18.2.0 \
--hash=sha256:10cbf6e27dbce8c30807caf056c8eb50917e0eaafe86347671b57254006c3e69 \
--hash=sha256:ca4be454458f9dec299268d472aaa5a11f67a4ff70093396e1ceae9c76cf4bbb \
# via -r dev-requirements.in, pytest
# via -r dev-requirements.in, black, pytest
black==19.10b0 \
--hash=sha256:1b30e59be925fafc1ee4565e5e08abef6b03fe455102883820fe5ee2e4734e0b \
--hash=sha256:c2edb73a08e9e0e6f65a0e6af18b059b8b1cdd5bef997d7a0b181df93dc81539 \
# via -r dev-requirements.in
certifi==2018.10.15 \
--hash=sha256:339dc09518b07e2fa7eda5450740925974815557727d6bd35d319c1524a04a4c \
--hash=sha256:6d58c986d22b038c8c0df30d639f23a3e6d172a05c3583e766f4c0b785c0986a \
Expand All @@ -33,7 +41,7 @@ chardet==3.0.4 \
click==7.0 \
--hash=sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13 \
--hash=sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7 \
# via -r dev-requirements.in, pip-tools
# via -r dev-requirements.in, black, pip-tools
coverage==4.5.1 \
--hash=sha256:03481e81d558d30d230bc12999e3edffe392d244349a90f4ef9b88425fac74ba \
--hash=sha256:0b136648de27201056c1869a6c0d4e23f464750fd9a9ba9750b8336a244429ed \
Expand Down Expand Up @@ -89,6 +97,10 @@ importlib-metadata==1.6.0 \
--hash=sha256:2a688cbaa90e0cc587f1df48bdc97a6eadccdcd9c35fb3f976a09e3b5016d90f \
--hash=sha256:34513a8a0c4962bc66d35b359558fd8a5e10cd472d37aec5f66858addef32c1e \
# via pluggy, pytest
isort==4.3.21 \
--hash=sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1 \
--hash=sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd \
# via -r dev-requirements.in
mako==1.0.7 \
--hash=sha256:4e02fde57bd4abb5ec400181e4c314f56ac3e49ba4fb8b0d50bba18cb27d25ae \
# via -r requirements.in, alembic
Expand Down Expand Up @@ -186,10 +198,10 @@ pathlib2==2.3.2 \
--hash=sha256:8eb170f8d0d61825e09a95b38be068299ddeda82f35e96c3301a8a5e7604cb83 \
--hash=sha256:d1aa2a11ba7b8f7b21ab852b1fb5afb277e1bb99d5dfc663380b5015c0d80c5a \
# via -r requirements.in
pip-tools==4.5.1 \
--hash=sha256:693f30e451875796b1b25203247f0b4cf48a4c4a5ab7341f4f33ffd498cdcc98 \
--hash=sha256:be9c796aa88b2eec5cabf1323ba1cb60a08212b84bfb75b8b4037a8ef8cb8cb6 \
# via -r dev-requirements.in
pathspec==0.8.0 \
--hash=sha256:7d91249d21749788d07a2d0f94147accd8f845507400749ea19c1ec9054a12b0 \
--hash=sha256:da45173eb3a6f2a5a487efba21f050af2b41948be6ab52b6a1e3ff22bb8b7061 \
# via black
pillow==7.0.0 \
--hash=sha256:0a628977ac2e01ca96aaae247ec2bd38e729631ddf2221b4b715446fd45505be \
--hash=sha256:4d9ed9a64095e031435af120d3c910148067087541131e82b3e8db302f4c8946 \
Expand All @@ -214,6 +226,10 @@ pillow==7.0.0 \
--hash=sha256:dc058b7833184970d1248135b8b0ab702e6daa833be14035179f2acb78ff5636 \
--hash=sha256:ff3797f2f16bf9d17d53257612da84dd0758db33935777149b3334c01ff68865 \
# via mouseinfo, pyscreeze
pip-tools==4.5.1 \
--hash=sha256:693f30e451875796b1b25203247f0b4cf48a4c4a5ab7341f4f33ffd498cdcc98 \
--hash=sha256:be9c796aa88b2eec5cabf1323ba1cb60a08212b84bfb75b8b4037a8ef8cb8cb6 \
# via -r dev-requirements.in
pluggy==0.13.0 \
--hash=sha256:0db4b7601aae1d35b4a033282da476845aa19185c1e6964b25cf324b5e4ec3e6 \
--hash=sha256:fa5fa1622fa6dd5c030e9cad086fa19ef6a0cf6d7a2d12318e10cb49d6d68f34 \
Expand Down Expand Up @@ -315,6 +331,12 @@ python-dateutil==2.7.5 \
python-editor==1.0.3 \
--hash=sha256:a3c066acee22a1c94f63938341d4fb374e3fdd69366ed6603d7b24bed1efc565 \
# via -r requirements.in, alembic
python3-xlib==0.15 \
--hash=sha256:dc4245f3ae4aa5949c1d112ee4723901ade37a96721ba9645f2bfa56e5b383f8 \
# via mouseinfo, pyautogui
pytweening==1.0.3 \
--hash=sha256:4b608a570f4dccf2201e898f643c2a12372eb1d71a3dbc7e778771b603ca248b \
# via pyautogui
pyyaml==5.3.1 \
--hash=sha256:06a0d7ba600ce0b2d2fe2e78453a470b5a6e000a985dd4a4e54e436cc36b0e97 \
--hash=sha256:240097ff019d7c70a4922b6869d8a86407758333f02203e0fc6ff79c5dcede76 \
Expand All @@ -328,12 +350,29 @@ pyyaml==5.3.1 \
--hash=sha256:cc8955cfbfc7a115fa81d85284ee61147059a753344bc51098f3ccd69b0d7e0c \
--hash=sha256:d13155f591e6fcc1ec3b30685d50bf0711574e2c0dfffd7644babf8b5102ca1a \
# via -r dev-requirements.in, vcrpy
python3-xlib==0.15 \
--hash=sha256:dc4245f3ae4aa5949c1d112ee4723901ade37a96721ba9645f2bfa56e5b383f8 \
# via mouseinfo, pyautogui
pytweening==1.0.3 \
--hash=sha256:4b608a570f4dccf2201e898f643c2a12372eb1d71a3dbc7e778771b603ca248b \
# via pyautogui
regex==2020.6.8 \
--hash=sha256:08997a37b221a3e27d68ffb601e45abfb0093d39ee770e4257bd2f5115e8cb0a \
--hash=sha256:112e34adf95e45158c597feea65d06a8124898bdeac975c9087fe71b572bd938 \
--hash=sha256:1700419d8a18c26ff396b3b06ace315b5f2a6e780dad387e4c48717a12a22c29 \
--hash=sha256:2f6f211633ee8d3f7706953e9d3edc7ce63a1d6aad0be5dcee1ece127eea13ae \
--hash=sha256:52e1b4bef02f4040b2fd547357a170fc1146e60ab310cdbdd098db86e929b387 \
--hash=sha256:55b4c25cbb3b29f8d5e63aeed27b49fa0f8476b0d4e1b3171d85db891938cc3a \
--hash=sha256:5aaa5928b039ae440d775acea11d01e42ff26e1561c0ffcd3d805750973c6baf \
--hash=sha256:654cb773b2792e50151f0e22be0f2b6e1c3a04c5328ff1d9d59c0398d37ef610 \
--hash=sha256:690f858d9a94d903cf5cada62ce069b5d93b313d7d05456dbcd99420856562d9 \
--hash=sha256:6ad8663c17db4c5ef438141f99e291c4d4edfeaacc0ce28b5bba2b0bf273d9b5 \
--hash=sha256:89cda1a5d3e33ec9e231ece7307afc101b5217523d55ef4dc7fb2abd6de71ba3 \
--hash=sha256:92d8a043a4241a710c1cf7593f5577fbb832cf6c3a00ff3fc1ff2052aff5dd89 \
--hash=sha256:95fa7726d073c87141f7bbfb04c284901f8328e2d430eeb71b8ffdd5742a5ded \
--hash=sha256:97712e0d0af05febd8ab63d2ef0ab2d0cd9deddf4476f7aa153f76feef4b2754 \
--hash=sha256:b2ba0f78b3ef375114856cbdaa30559914d081c416b431f2437f83ce4f8b7f2f \
--hash=sha256:bae83f2a56ab30d5353b47f9b2a33e4aac4de9401fb582b55c42b132a8ac3868 \
--hash=sha256:c78e66a922de1c95a208e4ec02e2e5cf0bb83a36ceececc10a72841e53fbf2bd \
--hash=sha256:cf59bbf282b627130f5ba68b7fa3abdb96372b24b66bdf72a4920e8153fc7910 \
--hash=sha256:e3cdc9423808f7e1bb9c2e0bdb1c9dc37b0607b30d646ff6faf0d4e41ee8fee3 \
--hash=sha256:e9b64e609d37438f7d6e68c2546d2cb8062f3adb27e6336bc129b51be20773ac \
--hash=sha256:fbff901c54c22425a5b809b914a3bfaf4b9570eee0e5ce8186ac71eb2025191c \
# via black
requests==2.20.0 \
--hash=sha256:99dcfdaaeb17caf6e526f32b6a7b780461512ab3f1d992187801694cba42770c \
--hash=sha256:a84b8c9ab6239b578f22d1c21d51b696dcfe004032bb80ea832398d6909d7279 \
Expand Down Expand Up @@ -362,6 +401,10 @@ six==1.11.0 \
sqlalchemy==1.3.3 \
--hash=sha256:91c54ca8345008fceaec987e10924bf07dcab36c442925357e5a467b36a38319 \
# via -r requirements.in, alembic
toml==0.10.1 \
--hash=sha256:926b612be1e5ce0634a2ca03470f95169cf16f939018233a670519cb4ac58b0f \
--hash=sha256:bda89d5935c2eac546d648028b9901107a595863cb36bae0c73ac804a9b4ce88 \
# via black
typed-ast==1.4.1 \
--hash=sha256:0666aa36131496aed8f7be0410ff974562ab7eeac11ef351def9ea6fa28f6355 \
--hash=sha256:0c2c07682d61a629b68433afb159376e24e5b2fd4641d35424e462169c0a7919 \
Expand All @@ -384,7 +427,7 @@ typed-ast==1.4.1 \
--hash=sha256:d5d33e9e7af3b34a40dc05f498939f0ebf187f07c385fd58d591c533ad8562fe \
--hash=sha256:fc0fea399acb12edbf8a628ba8d2312f583bdbdb3335635db062fa98cf71fca4 \
--hash=sha256:fe460b922ec15dd205595c9b5b99e2f056fd98ae8f9f56b888e7a17dc2b757e7 \
# via -r dev-requirements.in, mypy
# via -r dev-requirements.in, black, mypy
typing-extensions==3.7.4.2 \
--hash=sha256:6e95524d8a547a91e08f404ae485bbb71962de46967e1b71a0cb89af24e761c5 \
--hash=sha256:79ee589a3caca649a9bfd2a8de4709837400dfa00b6cc81962a1e6a1815969ae \
Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tool.black]
line-length = 100

[tool.isort]
line_length = 100
indent = ' '
multi_line_output = 3
ensure_newline_before_comments = true
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
2 changes: 1 addition & 1 deletion securedrop_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.0'
__version__ = "0.2.0"
38 changes: 20 additions & 18 deletions securedrop_client/api_jobs/base.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import logging
from typing import Any, Optional, TypeVar

from PyQt5.QtCore import QObject, pyqtSignal
from sdclientapi import API, AuthError, RequestTimeoutError, ServerConnectionError
from sqlalchemy.orm.session import Session
from typing import Any, Optional, TypeVar

logger = logging.getLogger(__name__)

DEFAULT_NUM_ATTEMPTS = 5

QueueJobType = TypeVar('QueueJobType', bound='QueueJob')
QueueJobType = TypeVar("QueueJobType", bound="QueueJob")


class ApiInaccessibleError(Exception):

def __init__(self, message: Optional[str] = None) -> None:
if not message:
message = ('API is inaccessible either because there is no client or because the '
'client is not properly authenticated.')
message = (
"API is inaccessible either because there is no client or because the "
"client is not properly authenticated."
)
super().__init__(message)


Expand All @@ -27,15 +28,15 @@ def __init__(self) -> None:
self.order_number = None # type: Optional[int]

def __lt__(self, other: QueueJobType) -> bool:
'''
"""
Python's PriorityQueue requires that QueueJobs are sortable as it
retrieves the next job using sorted(list(entries))[0].

For QueueJobs that have equal priority, we need to use the order_number key
to break ties to ensure that objects are retrieved in FIFO order.
'''
"""
if self.order_number is None or other.order_number is None:
raise ValueError('cannot compare jobs without order_number!')
raise ValueError("cannot compare jobs without order_number!")

return self.order_number < other.order_number

Expand All @@ -47,14 +48,15 @@ def __init__(self) -> None:

class ApiJob(QueueJob):

'''
"""
Signal that is emitted after an job finishes successfully.
'''
success_signal = pyqtSignal('PyQt_PyObject')
"""

success_signal = pyqtSignal("PyQt_PyObject")

'''
"""
Signal that is emitted if there is a failure during the job.
'''
"""
failure_signal = pyqtSignal(Exception)

def __init__(self, remaining_attempts: int = DEFAULT_NUM_ATTEMPTS) -> None:
Expand Down Expand Up @@ -83,31 +85,31 @@ def _do_call_api(self, api_client: API, session: Session) -> None:
break

def call_api(self, api_client: API, session: Session) -> Any:
'''
"""
Method for making the actual API call and handling the result.

This MUST resturn a value if the API call and other tasks were successful and MUST raise
an exception if and only if the tasks failed. Presence of a raise exception indicates a
failure.
'''
"""
raise NotImplementedError


class SingleObjectApiJob(ApiJob):
def __init__(self, uuid: str, remaining_attempts: int = DEFAULT_NUM_ATTEMPTS) -> None:
super().__init__(remaining_attempts)
'''
"""
UUID of the item (source, reply, submission, etc.) that this item
corresponds to. We track this to prevent the addition of duplicate jobs.
'''
"""
self.uuid = uuid

def __repr__(self) -> str:
return "{}('{}', {})".format(self.__class__.__name__, self.uuid, self.remaining_attempts)

def __eq__(self, other: Any) -> bool: # type: ignore[override]
# https://github.com/python/mypy/issues/2783
if self.uuid == getattr(other, 'uuid', None) and type(self) == type(other):
if self.uuid == getattr(other, "uuid", None) and type(self) == type(other):
return True
else:
return False
Loading