Skip to content

Commit

Permalink
Merge pull request #20 from UW-Macrostrat/import-sorting
Browse files Browse the repository at this point in the history
Add import sorting with isort
  • Loading branch information
davenquinn authored Jan 13, 2024
2 parents f3f528e + 33ded43 commit 286f687
Show file tree
Hide file tree
Showing 31 changed files with 155 additions and 114 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ install:
publish:
poetry run mono publish

format:
poetry run isort .
poetry run black .

test:
poetry run pytest -s -x --failed-first
4 changes: 2 additions & 2 deletions app-frame/macrostrat/app_frame/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .core import Application
from .compose import compose
from .subsystems import SubsystemManager, Subsystem, SubsystemError
from .core import Application
from .exc import ApplicationError
from .subsystems import Subsystem, SubsystemError, SubsystemManager
3 changes: 2 additions & 1 deletion app-frame/macrostrat/app_frame/compose.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from macrostrat.utils import cmd, get_logger
from rich.console import Console

from macrostrat.utils import cmd, get_logger

console = Console()

log = get_logger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion app-frame/macrostrat/app_frame/control_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import click
import typer
from click import Group
from macrostrat.utils import get_logger
from typer import Context, Typer
from typer.core import TyperGroup
from typer.models import TyperInfo

from macrostrat.utils import get_logger

from .compose import check_status, compose
from .core import Application
from .follow_logs import Result, command_stream, follow_logs
Expand Down
7 changes: 4 additions & 3 deletions app-frame/macrostrat/app_frame/core.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from rich.console import Console
from typing import Optional, Callable
from macrostrat.utils import setup_stderr_logs, get_logger
import logging
from os import environ
from pathlib import Path
from typing import Callable, Optional

from dotenv import load_dotenv
from rich.console import Console

from macrostrat.utils import get_logger, setup_stderr_logs

log = get_logger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion app-frame/macrostrat/app_frame/follow_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import sys
import termios
from contextlib import contextmanager
from datetime import datetime
from enum import Enum
from subprocess import Popen
from time import sleep
from typing import Generator
from datetime import datetime

from macrostrat.utils import get_logger

Expand Down
8 changes: 4 additions & 4 deletions app-frame/macrostrat/app_frame/subsystems/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from toposort import toposort_flatten
from ..core import ApplicationBase
from typing import Optional

from packaging.specifiers import InvalidSpecifier, SpecifierSet
from packaging.version import Version
from typing import Optional
from toposort import toposort_flatten

from macrostrat.utils.logs import get_logger

from ..core import ApplicationBase
from .defs import Subsystem, SubsystemError


log = get_logger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion app-frame/test_app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path
from macrostrat.app_frame import Application

from macrostrat.app_frame import Application

APP_ROOT = Path(__file__).parent

Expand Down
8 changes: 5 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from pytest import fixture
from os import environ
from macrostrat.dinosaur.upgrade_cluster.utils import database_cluster, get_unused_port
from dotenv import load_dotenv

from docker.client import DockerClient
from dotenv import load_dotenv
from pytest import fixture
from sqlalchemy import create_engine
from sqlalchemy.exc import OperationalError

from macrostrat.dinosaur.upgrade_cluster.utils import database_cluster, get_unused_port

load_dotenv()


Expand Down
16 changes: 5 additions & 11 deletions database/macrostrat/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@
from contextlib import contextmanager
from typing import Optional

from sqlalchemy import create_engine, inspect, MetaData, text
from sqlalchemy.orm import sessionmaker, scoped_session, Session
from sqlalchemy import MetaData, create_engine, inspect, text
from sqlalchemy.exc import IntegrityError
from macrostrat.utils import get_logger
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.orm import Session, scoped_session, sessionmaker
from sqlalchemy.sql.expression import Insert

from macrostrat.utils import get_logger

from .utils import (
run_sql,
get_or_create,
reflect_table,
get_dataframe,
)
from .mapper import DatabaseMapper
from .postgresql import prefix_inserts, on_conflict # noqa

from .postgresql import on_conflict, prefix_inserts # noqa
from .utils import get_dataframe, get_or_create, reflect_table, run_sql

metadata = MetaData()

Expand Down
13 changes: 7 additions & 6 deletions database/macrostrat/database/mapper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from distutils.log import warn
from macrostrat.database.utils import reflect_table
from sqlalchemy.ext.automap import generate_relationship
from macrostrat.utils.logs import get_logger
from warnings import warn

# Drag in geographic types for database reflection
from geoalchemy2 import Geometry, Geography
from geoalchemy2 import Geography, Geometry
from sqlalchemy.ext.automap import generate_relationship

from macrostrat.database.utils import reflect_table
from macrostrat.utils.logs import get_logger

from .cache import DatabaseModelCache
from .utils import (
ModelCollection,
TableCollection,
classname_for_table,
_classname_for_table,
name_for_scalar_relationship,
classname_for_table,
name_for_collection_relationship,
name_for_scalar_relationship,
)

log = get_logger(__name__)
Expand Down
8 changes: 5 additions & 3 deletions database/macrostrat/database/mapper/cache.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from os import makedirs, path
from pickle import dump, load

from sqlalchemy.ext.automap import automap_base
from os import path, makedirs

from macrostrat.utils.logs import get_logger
from sqlalchemy.ext.automap import automap_base
from pickle import load, dump

from .base import ModelHelperMixins

log = get_logger(__name__)
Expand Down
8 changes: 3 additions & 5 deletions database/macrostrat/database/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

from contextlib import contextmanager
from contextvars import ContextVar
from typing import TYPE_CHECKING

import psycopg2
from sqlalchemy.dialects import postgresql
from sqlalchemy.exc import CompileError
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.expression import Insert, text
from sqlalchemy.dialects import postgresql
import psycopg2


from typing import TYPE_CHECKING

if TYPE_CHECKING:
from ..database import Database
Expand Down
34 changes: 20 additions & 14 deletions database/macrostrat/database/utils.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
from contextlib import contextmanager
from pathlib import Path
from re import search
from time import sleep
from typing import IO, Union
from warnings import warn

from click import echo, secho
from sqlalchemy.exc import ProgrammingError, IntegrityError, InternalError
from sqlparse import split, format
from sqlalchemy.sql.elements import TextClause, ClauseElement
from psycopg2.sql import SQL, Composable, Composed
from sqlalchemy import MetaData, create_engine, text
from sqlalchemy.engine import Connection, Engine
from sqlalchemy.exc import (
IntegrityError,
InternalError,
InvalidRequestError,
ProgrammingError,
)
from sqlalchemy.orm import sessionmaker
from sqlalchemy.engine import Engine, Connection
from sqlalchemy.schema import Table
from sqlalchemy import MetaData, create_engine, text
from contextlib import contextmanager
from sqlalchemy.sql.elements import ClauseElement, TextClause
from sqlalchemy_utils import create_database, database_exists, drop_database
from sqlalchemy.exc import InvalidRequestError
from sqlparse import format, split

from macrostrat.utils import cmd, get_logger
from time import sleep
from typing import Union, IO
from pathlib import Path
from warnings import warn
from psycopg2.sql import SQL, Composable, Composed
from re import search
from macrostrat.utils import get_logger

from .postgresql import _setup_psycopg2_wait_callback

log = get_logger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion database/test-scripts/test-long-running-query
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
Run a long-running query to test if we can interrupt it.
"""

from macrostrat.database import Database
from sys import argv, exit

from sqlalchemy.exc import OperationalError

from macrostrat.database import Database

db_conn = argv[1]
print(f"Connecting to {db_conn}")
Expand Down
13 changes: 7 additions & 6 deletions database/test_database.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Skeletal testing file
from os import environ
from pathlib import Path
from pytest import fixture

from dotenv import load_dotenv
from psycopg2.sql import SQL, Identifier, Literal, Placeholder
from pytest import fixture, mark, raises, warns
from sqlalchemy.exc import ProgrammingError
from sqlalchemy.sql import text

from macrostrat.utils import relative_path, get_logger
from macrostrat.database import Database, run_sql
from macrostrat.database.utils import temp_database, infer_is_sql_text
from macrostrat.database.postgresql import table_exists
from pytest import warns, raises, mark
from os import environ
from macrostrat.database.utils import infer_is_sql_text, temp_database
from macrostrat.utils import get_logger, relative_path

load_dotenv()

Expand Down Expand Up @@ -215,6 +215,7 @@ def test_close_connection(conn):
"""

import threading

from psycopg2.extensions import QueryCanceledError
from sqlalchemy.exc import DBAPIError

Expand All @@ -240,8 +241,8 @@ def test_sigint_cancel(db):
by sending a SIGINT.
"""

import subprocess
import signal
import subprocess
import time

db_url = str(db.engine.url)
Expand Down
20 changes: 8 additions & 12 deletions dinosaur/macrostrat/dinosaur/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import os
import sys
from contextlib import contextmanager, redirect_stdout
from typing import Callable

from sqlalchemy.exc import ProgrammingError, IntegrityError, DataError
from schemainspect import get_inspector
import docker
from migra import Migration
from migra.statements import check_for_drop
from sqlalchemy import text
from rich import print
from typing import Callable
import docker
from schemainspect import get_inspector
from sqlalchemy import text
from sqlalchemy.exc import DataError, IntegrityError, ProgrammingError

from macrostrat.utils import get_logger, cmd
from macrostrat.database import Database
from macrostrat.database.utils import (
run_sql,
temp_database,
connection_args,
)
from .upgrade_cluster.utils import wait_for_cluster, wait_for_ready
from macrostrat.database.utils import connection_args, run_sql, temp_database
from macrostrat.utils import cmd, get_logger

from .upgrade_cluster.utils import wait_for_cluster, wait_for_ready

log = get_logger(__name__)

Expand Down
20 changes: 11 additions & 9 deletions dinosaur/macrostrat/dinosaur/upgrade_cluster/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
from typing import List

from docker.client import DockerClient
from macrostrat.utils import get_logger
from rich.console import Console
from typing import List

from macrostrat.utils import get_logger

from .describe import (
check_database_cluster_version,
check_database_exists,
count_database_tables,
)
from .restore import pg_restore
from .utils import (
database_cluster,
ensure_empty_docker_volume,
replace_docker_volume,
get_unused_port,
)
from .restore import pg_restore
from .describe import (
check_database_exists,
count_database_tables,
check_database_cluster_version,
replace_docker_volume,
)

log = get_logger(__name__)
Expand Down
7 changes: 4 additions & 3 deletions dinosaur/macrostrat/dinosaur/upgrade_cluster/describe.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from docker.models.containers import Container
from pathlib import Path
from subprocess import CalledProcessError
from docker.errors import ContainerError

from docker.client import DockerClient
from pathlib import Path
from docker.errors import ContainerError
from docker.models.containers import Container

from macrostrat.utils import get_logger

Expand Down
2 changes: 1 addition & 1 deletion dinosaur/macrostrat/dinosaur/upgrade_cluster/restore.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio

from docker.models.containers import Container
from rich.console import Console


console = Console()


Expand Down
Loading

0 comments on commit 286f687

Please sign in to comment.