Skip to content

Commit

Permalink
chore(Worker): Add isort formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Oct 15, 2020
1 parent f33253c commit 6e13678
Show file tree
Hide file tree
Showing 33 changed files with 55 additions and 57 deletions.
2 changes: 2 additions & 0 deletions worker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ venv: requirements.txt requirements-dev.txt package.json
# Format code
format: venv
$(VE)/black .
$(VE)/isort .

# Lint code
lint: venv
$(VE)/black --check .
$(VE)/isort --check .
$(VE)/flake8
$(VE)/mypy --config-file pyproject.toml .
$(VE)/pydocstyle --match-dir='^(?!venv)'
Expand Down
2 changes: 1 addition & 1 deletion worker/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Configuration for pytest."""

from testfixtures import TempDirectory
import pytest
from testfixtures import TempDirectory


@pytest.fixture()
Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/archive.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional, List, Union, Dict
import os
import shutil
from typing import Dict, List, Optional, Union

from config import get_snapshot_dir
from jobs.base.job import Job
Expand Down
6 changes: 3 additions & 3 deletions worker/jobs/base/job.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from datetime import datetime
from typing import Any, Optional
import os
import traceback
from datetime import datetime
from pathlib import Path
from typing import Any, Optional

import celery
import sentry_sdk
from celery import states
from celery.exceptions import Ignore, SoftTimeLimitExceeded
from celery.utils.log import get_task_logger
import sentry_sdk
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.redis import RedisIntegration

Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/base/job_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from celery.exceptions import Ignore

from .job import Job, DEBUG, INFO, WARN, ERROR
from .job import DEBUG, ERROR, INFO, WARN, Job


def test_logging():
Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/base/subprocess_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import threading
from typing import List, Optional, Union

from .job import Job, DEBUG, INFO, WARN, ERROR
from .job import DEBUG, ERROR, INFO, WARN, Job


class SubprocessJob(Job):
Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/base/subprocess_job_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import pytest
from celery.exceptions import Ignore

from .job import DEBUG, ERROR, INFO, WARN, Job
from .subprocess_job import SubprocessJob
from .job import Job, DEBUG, INFO, WARN, ERROR


def test_success():
Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/convert.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import cast, List, Union, Dict
import os
from typing import Dict, List, Union, cast

from config import get_node_modules_bin
from jobs.base.subprocess_job import SubprocessJob
Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/decode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import cast, List, Union, Dict
from typing import Dict, List, Union, cast

from .convert import Convert

Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/encode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Any, Union, Dict
from typing import Any, Dict, Union

from .convert import Convert

Expand Down
3 changes: 1 addition & 2 deletions worker/jobs/pin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import os
import re
from typing import cast, Dict, List, Optional, Tuple
from typing import Dict, List, Optional, Tuple, cast

from dxf import DXF

from jobs.base.job import Job


# Regex for parsing a container image identifier
# Based on answers at https://stackoverflow.com/questions/39671641/regex-to-parse-docker-tag
# Playground at https://regex101.com/r/hP8bK1/42
Expand Down
4 changes: 2 additions & 2 deletions worker/jobs/pull/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Callable, Dict, List
import os
from typing import Callable, Dict, List

import config
from jobs.base.job import Job
Expand All @@ -8,10 +8,10 @@
from .gdoc import pull_gdoc
from .gdrive import pull_gdrive
from .github import pull_github
from .helpers import Files
from .http import pull_http
from .plos import pull_plos
from .upload import pull_upload
from .helpers import Files

# Functions for pulling individual source types
PULL_FUNCS: Dict[str, Callable[..., Files]] = {
Expand Down
4 changes: 2 additions & 2 deletions worker/jobs/pull/elife.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import io
import os
import re
import requests
from typing import List

import requests
from lxml import etree

from .helpers import HttpSession, Files, begin_pull, end_pull
from .helpers import Files, HttpSession, begin_pull, end_pull


def pull_elife(source: dict, working_dir: str, path: str, **kwargs) -> Files:
Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/pull/gdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials

from util.files import file_info, Files
from util.files import Files, file_info


def pull_gdoc(source: dict, path: str, secrets: Dict = {}, **kwargs) -> Files:
Expand Down
2 changes: 2 additions & 0 deletions worker/jobs/pull/gdoc_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os

import pytest

from util.working_directory import working_directory

from .gdoc import pull_gdoc

# The following access token is expired, but was valid when this test
Expand Down
15 changes: 5 additions & 10 deletions worker/jobs/pull/gdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@
import os
import shutil
import typing
from typing import List

from googleapiclient.discovery import build
from googleapiclient.http import MediaIoBaseDownload
from oauth2client.client import GoogleCredentials
from typing import List

from .helpers import begin_pull, end_pull, Files
from util.path_operations import (utf8_isdir, utf8_makedirs, utf8_normpath,
utf8_path_exists, utf8_path_join,
utf8_unlink)

from util.path_operations import (
utf8_path_join,
utf8_normpath,
utf8_makedirs,
utf8_path_exists,
utf8_isdir,
utf8_unlink,
)
from .helpers import Files, begin_pull, end_pull


def pull_gdrive(source: dict, working_dir: str, path: str, **kwargs) -> Files:
Expand Down
2 changes: 2 additions & 0 deletions worker/jobs/pull/gdrive_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os

import pytest

from util.path_operations import utf8_path_exists, utf8_path_join

from .gdrive import pull_gdrive

# The following access token is expired, but was valid when this test
Expand Down
17 changes: 6 additions & 11 deletions worker/jobs/pull/github.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import json
import os
import shutil
from io import BytesIO
from typing import List

from github import Github
from github.ContentFile import ContentFile
from io import BytesIO
from typing import List

from util.path_operations import (
utf8_path_join,
utf8_normpath,
utf8_makedirs,
utf8_path_exists,
utf8_isdir,
utf8_unlink,
)
from util.path_operations import (utf8_isdir, utf8_makedirs, utf8_normpath,
utf8_path_exists, utf8_path_join,
utf8_unlink)

from .helpers import begin_pull, end_pull, Files
from .helpers import Files, begin_pull, end_pull


def pull_github(source: dict, working_dir: str, path: str, **kwargs) -> Files:
Expand Down
1 change: 1 addition & 0 deletions worker/jobs/pull/github_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import pytest

from .github import pull_github
Expand Down
9 changes: 5 additions & 4 deletions worker/jobs/pull/helpers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from typing import Dict, Any
from pathlib import Path
import tempfile
import ipaddress
import mimetypes
import os
import re
import requests
import shutil
import tempfile
from pathlib import Path
from socket import gethostbyname
from typing import Any, Dict
from urllib.parse import urlparse

import requests

from util.files import Files, list_files


Expand Down
1 change: 1 addition & 0 deletions worker/jobs/pull/helpers_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from pathlib import Path

import pytest

from .helpers import begin_pull, end_pull
Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/pull/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from typing import List

from .helpers import HttpSession, begin_pull, end_pull, Files
from .helpers import Files, HttpSession, begin_pull, end_pull


def pull_http(source: dict, working_dir: str, path: str, **kwargs) -> Files:
Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/pull/plos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from lxml import etree

from .helpers import HttpSession, begin_pull, end_pull, Files
from .helpers import Files, HttpSession, begin_pull, end_pull


def pull_plos(source: dict, working_dir: str, path: str, **kwargs) -> Files:
Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/push/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Callable, Dict, List
import os
from typing import Callable, Dict, List

import config
from jobs.base.job import Job
Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/push/gdoc.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
import os
import tempfile
from typing import List

from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
from oauth2client.client import GoogleCredentials
from typing import List

from jobs.convert import Convert

Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/push/gdoc_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
import pytest

import pytest
from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials

Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/session/kubernetes_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import sys
import time

from celery.exceptions import Ignore, SoftTimeLimitExceeded
import kubernetes
from celery.exceptions import Ignore, SoftTimeLimitExceeded

from config import get_snapshot_dir, get_working_dir
from jobs.base.job import Job
Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/session/kubernetes_session_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from celery.exceptions import SoftTimeLimitExceeded

from .kubernetes_session import api_instance, KubernetesSession
from .kubernetes_session import KubernetesSession, api_instance


@pytest.mark.skipif(api_instance is None, reason="can only run if K8s is available")
Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/session/session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Type, Union

from .kubernetes_session import api_instance, KubernetesSession
from .kubernetes_session import KubernetesSession, api_instance
from .subprocess_session import SubprocessSession

# If on a K8s is available then use that
Expand Down
2 changes: 1 addition & 1 deletion worker/jobs/sleep.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
import time
from datetime import datetime

from jobs.base.job import Job

Expand Down
1 change: 1 addition & 0 deletions worker/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
black==19.10b0
flake8==3.8.4
isort==5.6.1
mypy==0.790
pydocstyle==5.1.1
pytest==6.1.1
Expand Down
6 changes: 3 additions & 3 deletions worker/util/files.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pathlib import Path
from typing import Dict, Any, Optional
import hashlib
import os
import mimetypes
import os
import shutil
import tempfile
from pathlib import Path
from typing import Any, Dict, Optional

FileInfo = Dict[str, Any]
Files = Dict[str, FileInfo]
Expand Down
3 changes: 1 addition & 2 deletions worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
from celery import Celery
from kombu import Queue

from jobs.base.job import Job

from jobs.archive import Archive
from jobs.base.job import Job
from jobs.clean import Clean
from jobs.convert import Convert
from jobs.decode import Decode
Expand Down

0 comments on commit 6e13678

Please sign in to comment.