Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Commit

Permalink
Add isort configuration file (#1054)
Browse files Browse the repository at this point in the history
* add .isort.cfg

* add comment about known_first_party modules

* Remove redundant config

* Fixup after rebase

---------

Co-authored-by: Madison Swain-Bowden <[email protected]>
  • Loading branch information
raiyaj and AetherUnbound committed Mar 28, 2023
1 parent 5ad9448 commit 75990f3
Show file tree
Hide file tree
Showing 92 changed files with 118 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[settings]
profile=black

sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
# These submodules are all added to the PYTHONPATH by Airflow, so we need to add them individually here.
known_first_party=common,data_refresh,database,maintenance,oauth2,providers,retired
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ deploy:
@just up

# Run pre-commit on all files
lint:
pre-commit run --all-files
lint hook="":
pre-commit run {{ hook }} --all-files

# Load any dependencies necessary for actions on the stack without running the webserver
_deps:
Expand Down
1 change: 1 addition & 0 deletions openverse_catalog/dags/common/loader/loader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from airflow.models.abstractoperator import AbstractOperator

from common.loader import paths, s3, sql
from common.loader.paths import _extract_media_type
from common.loader.reporting import RecordMetrics
Expand Down
1 change: 1 addition & 0 deletions openverse_catalog/dags/common/loader/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from airflow.exceptions import AirflowSkipException
from airflow.providers.amazon.aws.hooks.s3 import S3Hook

from common.loader import paths


Expand Down
3 changes: 2 additions & 1 deletion openverse_catalog/dags/common/loader/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from textwrap import dedent

from airflow.models.abstractoperator import AbstractOperator
from psycopg2.errors import InvalidTextRepresentation

from common.constants import AUDIO, IMAGE, MediaType
from common.loader import provider_details as prov
from common.loader.paths import _extract_media_type
Expand All @@ -15,7 +17,6 @@
CURRENT_IMAGE_TSV_COLUMNS,
required_columns,
)
from psycopg2.errors import InvalidTextRepresentation


logger = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions openverse_catalog/dags/common/popularity/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from textwrap import dedent

from airflow.models.abstractoperator import AbstractOperator

from common.constants import AUDIO, IMAGE
from common.loader.sql import TABLE_NAMES
from common.sql import PostgresHook
Expand Down
3 changes: 2 additions & 1 deletion openverse_catalog/dags/common/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import time
from collections.abc import Callable

import oauth2
import requests
from airflow.exceptions import AirflowException
from requests.exceptions import JSONDecodeError

import oauth2


# pytest_socket will not be available in production, so we must create a shim for
# that specific exception so this code does not error out.
Expand Down
1 change: 1 addition & 0 deletions openverse_catalog/dags/common/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from airflow.providers.postgres.hooks.postgres import (
PostgresHook as UpstreamPostgresHook,
)

from common.constants import DAG_DEFAULT_ARGS, POSTGRES_CONN_ID


Expand Down
1 change: 1 addition & 0 deletions openverse_catalog/dags/data_refresh/dag_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from airflow.settings import SASession
from airflow.utils.session import provide_session
from airflow.utils.state import State

from common.constants import (
DAG_DEFAULT_ARGS,
OPENLEDGER_API_CONN_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@
from airflow.providers.http.operators.http import SimpleHttpOperator
from airflow.providers.http.sensors.http import HttpSensor
from airflow.utils.task_group import TaskGroup
from requests import Response

from common.constants import XCOM_PULL_TEMPLATE
from common.sensors.single_run_external_dags_sensor import SingleRunExternalDAGsSensor
from data_refresh.data_refresh_types import DataRefresh
from requests import Response


logger = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""
from airflow.operators.python import PythonOperator
from airflow.utils.task_group import TaskGroup

from common.constants import POSTGRES_CONN_ID
from common.popularity import sql
from data_refresh import reporting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""
from airflow.operators.python import PythonOperator
from airflow.utils.trigger_rule import TriggerRule

from common.constants import POSTGRES_CONN_ID
from common.popularity import sql
from data_refresh import reporting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from airflow import DAG
from airflow.operators.python import PythonOperator

from common.constants import DAG_DEFAULT_ARGS, POSTGRES_CONN_ID
from common.loader import sql

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""
from airflow import DAG
from airflow.operators.python import PythonOperator

from common.constants import DAG_DEFAULT_ARGS, POSTGRES_CONN_ID
from common.popularity import sql
from data_refresh.data_refresh_types import DATA_REFRESH_CONFIGS, DataRefresh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from airflow.exceptions import AirflowException
from airflow.models import BaseOperator, TaskInstance
from airflow.operators.python import PythonOperator

from common import slack
from common.constants import (
DAG_DEFAULT_ARGS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from airflow import DAG
from airflow.exceptions import AirflowSkipException
from airflow.operators.python import PythonOperator

from common.constants import (
DAG_DEFAULT_ARGS,
OPENLEDGER_API_CONN_ID,
Expand Down
3 changes: 2 additions & 1 deletion openverse_catalog/dags/maintenance/add_license_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
from airflow.operators.python import PythonOperator
from airflow.providers.amazon.aws.hooks.s3 import S3Hook
from airflow.utils.trigger_rule import TriggerRule
from psycopg2._json import Json

from common.constants import DAG_DEFAULT_ARGS, POSTGRES_CONN_ID, XCOM_PULL_TEMPLATE
from common.licenses import get_license_info_from_license_pair
from common.loader.sql import RETURN_ROW_COUNT
from common.slack import send_message
from common.sql import PostgresHook
from providers.provider_dag_factory import AWS_CONN_ID, OPENVERSE_BUCKET
from psycopg2._json import Json


DAG_ID = "add_license_url"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from airflow.configuration import conf
from airflow.models import DAG
from airflow.operators.python import PythonOperator

from common import log_cleanup
from common.constants import DAG_DEFAULT_ARGS

Expand Down
1 change: 1 addition & 0 deletions openverse_catalog/dags/maintenance/check_silenced_dags.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from airflow.exceptions import AirflowException, AirflowSkipException
from airflow.models import DAG, Variable
from airflow.operators.python import PythonOperator

from common.constants import DAG_DEFAULT_ARGS
from common.github import GitHubAPI
from common.slack import SilencedSlackNotification, send_alert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from airflow.exceptions import AirflowSkipException
from airflow.models import Variable
from airflow.operators.python import PythonOperator

from common.constants import DAG_DEFAULT_ARGS
from common.loader import provider_details as prov
from common.requester import DelayedRequester
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from airflow.models import DAG
from airflow.operators.python import PythonOperator

from common.constants import DAG_DEFAULT_ARGS
from maintenance.pr_review_reminders import pr_review_reminders

Expand Down
3 changes: 2 additions & 1 deletion openverse_catalog/dags/oauth2/authorize_dag.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""# OAuth Provider Authorization"""
from datetime import datetime

import oauth2
from airflow.models import DAG
from airflow.operators.python import PythonOperator

import oauth2
from common.constants import DAG_DEFAULT_ARGS


Expand Down
3 changes: 2 additions & 1 deletion openverse_catalog/dags/oauth2/token_refresh_dag.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""# OAuth Provider Token Refresh"""
from datetime import datetime

import oauth2
from airflow.models import DAG
from airflow.operators.python import PythonOperator

import oauth2
from common.constants import DAG_DEFAULT_ARGS


Expand Down
1 change: 1 addition & 0 deletions openverse_catalog/dags/providers/factory_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from airflow.models import DagRun, TaskInstance
from airflow.utils.dates import cron_presets

from common.constants import MediaType
from common.storage.media import MediaStore
from providers.provider_api_scripts.provider_data_ingester import ProviderDataIngester
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lxml.html as html
from airflow.models import Variable

from common import constants
from common.licenses import get_license_info
from common.loader import provider_details as prov
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import logging
from datetime import datetime, timedelta, timezone

import common
from airflow.models import Variable

import common
from common.licenses import get_license_info
from common.loader import provider_details as prov
from providers.provider_api_scripts.provider_data_ingester import ProviderDataIngester
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import lxml.html as html
from airflow.models import Variable

from common import constants
from common.licenses import get_license_info
from common.loader import provider_details as prov
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
from datetime import datetime

from airflow.models import Variable
from requests.exceptions import ConnectionError, SSLError
from retry import retry

from common import constants
from common.licenses.licenses import get_license_info
from common.loader import provider_details as prov
from common.requester import RetriesExceeded
from providers.provider_api_scripts.provider_data_ingester import ProviderDataIngester
from requests.exceptions import ConnectionError, SSLError
from retry import retry


logger = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from airflow.providers.amazon.aws.hooks.s3 import S3Hook
from airflow.utils.task_group import TaskGroup
from airflow.utils.trigger_rule import TriggerRule

from common.constants import IMAGE, POSTGRES_CONN_ID, XCOM_PULL_TEMPLATE
from common.loader import provider_details, reporting, sql
from common.sql import PGExecuteQueryOperator, PostgresHook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import logging
from urllib.parse import parse_qs, urlencode, urlsplit

import common
from airflow.models import Variable

import common
from common import constants
from common.licenses import get_license_info
from common.loader import provider_details as prov
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
import argparse
import logging

from provider_data_ingester import ProviderDataIngester

from common.licenses import get_license_info
from common.loader import provider_details as prov
from provider_data_ingester import ProviderDataIngester


logging.basicConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from urllib.parse import parse_qs, urlparse

from airflow.models import Variable

from common import constants
from common.licenses import get_license_info
from common.loader import provider_details as prov
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from airflow.exceptions import AirflowException
from airflow.models import Variable

from common.requester import DelayedRequester
from common.storage.media import MediaStore
from common.storage.util import get_media_store_class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from urllib.parse import urlencode

from airflow.models import Variable

from common import constants
from common.licenses import NO_LICENSE_FOUND, get_license_info
from common.loader import provider_details as prov
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

from airflow.exceptions import AirflowException
from airflow.models import Variable
from retry import retry

from common import constants
from common.licenses import get_license_info
from common.loader import provider_details as prov
from providers.provider_api_scripts.provider_data_ingester import ProviderDataIngester
from retry import retry


logger = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
from types import MappingProxyType

import lxml.html as html

from common.constants import AUDIO, IMAGE
from common.licenses import get_license_info
from common.loader import provider_details as prov
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import logging

import lxml.html as html

from common import constants
from common.licenses import get_license_info
from common.loader import provider_details as prov
Expand Down
1 change: 1 addition & 0 deletions openverse_catalog/dags/providers/provider_dag_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from airflow.operators.python import PythonOperator
from airflow.utils.task_group import TaskGroup
from airflow.utils.trigger_rule import TriggerRule

from common.constants import DAG_DEFAULT_ARGS, XCOM_PULL_TEMPLATE
from common.loader import loader, reporting, s3, sql
from providers.factory_utils import date_partition_for_prefix, pull_media_wrapper
Expand Down
3 changes: 2 additions & 1 deletion openverse_catalog/dags/providers/provider_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from datetime import datetime, timedelta

from airflow.models import Variable
from typing_extensions import NotRequired, TypedDict

from providers.provider_api_scripts.brooklyn_museum import BrooklynMuseumDataIngester
from providers.provider_api_scripts.cleveland_museum import ClevelandDataIngester
from providers.provider_api_scripts.europeana import EuropeanaDataIngester
Expand All @@ -29,7 +31,6 @@
WikimediaCommonsDataIngester,
)
from providers.provider_api_scripts.wordpress import WordPressDataIngester
from typing_extensions import NotRequired, TypedDict


logger = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import NamedTuple

from airflow.models import DAG, DagBag

from providers.provider_workflows import PROVIDER_WORKFLOWS, ProviderWorkflow


Expand Down
Loading

0 comments on commit 75990f3

Please sign in to comment.