Skip to content

Commit

Permalink
DEV-2301 externalize enums so that they can be accessed by other modu…
Browse files Browse the repository at this point in the history
…les (#69)

DEV-2301 externalize enums so that they can be accessed by other modules
* introduce pre-commit isort
* reformat all with isort
  • Loading branch information
stilesj-uchicago authored Dec 1, 2023
1 parent ce58001 commit f96ea94
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 90 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ repos:
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.11.5
hooks:
- id: isort
args: [--profile, black]
- repo: git@github.com:Yelp/detect-secrets
rev: v1.4.0
hooks:
Expand Down
17 changes: 4 additions & 13 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@
{
"name": "CloudantDetector"
},
{
"name": "DiscordBotTokenDetector"
},
{
"name": "GitHubTokenDetector"
},
{
"name": "HexHighEntropyString",
"limit": 3
"limit": 3.0
},
{
"name": "IbmCloudIamDetector"
Expand Down Expand Up @@ -109,12 +106,6 @@
},
{
"path": "detect_secrets.filters.heuristic.is_templated_secret"
},
{
"path": "detect_secrets.filters.regex.should_exclude_file",
"pattern": [
"^.secrets.baseline$"
]
}
],
"results": {
Expand Down Expand Up @@ -144,7 +135,7 @@
"filename": "gdc_ng_models/alembic/versions/12dbbcac7a1d_change_columns_to_biginteger.py",
"hashed_secret": "e9a4b5d5cbc26e98f00981d15146f2a23871666b",
"is_verified": false,
"line_number": 14,
"line_number": 13,
"is_secret": false
}
],
Expand All @@ -154,10 +145,10 @@
"filename": "gdc_ng_models/alembic/versions/e9d53a640d5d_add_start_end_datetimes_notifications.py",
"hashed_secret": "e9a4b5d5cbc26e98f00981d15146f2a23871666b",
"is_verified": false,
"line_number": 13,
"line_number": 12,
"is_secret": false
}
]
},
"generated_at": "2023-08-25T14:30:18Z"
"generated_at": "2023-12-01T15:34:13Z"
}
4 changes: 1 addition & 3 deletions gdc_ng_models/alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from logging.config import fileConfig

from alembic import context
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from sqlalchemy import engine_from_config, pool

import gdc_ng_models.models.batch as batch_models
import gdc_ng_models.models.download_reports as download_reports_models
Expand All @@ -15,7 +14,6 @@
import gdc_ng_models.models.studyrule as studyrule_models
import gdc_ng_models.models.submission as submission_models


# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
Create Date: 2021-03-30 13:16:01.055456
"""
from alembic import op
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "12dbbcac7a1d"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
Create Date: 2020-12-11 16:06:21.960486
"""
from alembic import op
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "e9d53a640d5d"
Expand Down
2 changes: 1 addition & 1 deletion gdc_ng_models/models/audit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Common audit metadata for our data models."""
import datetime

from sqlalchemy import schema, sql, func
from sqlalchemy import func, schema, sql
from sqlalchemy.sql import sqltypes


Expand Down
2 changes: 2 additions & 0 deletions gdc_ng_models/models/cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
"""

import uuid

import sqlalchemy
from sqlalchemy.dialects import postgresql
from sqlalchemy.ext import declarative

from gdc_ng_models.models import accessed, audit

Base = declarative.declarative_base()
Expand Down
4 changes: 2 additions & 2 deletions gdc_ng_models/models/download_reports.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json

import sqlalchemy as db
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.dialects.postgresql import JSONB

from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

Expand Down
37 changes: 27 additions & 10 deletions gdc_ng_models/models/entity_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,30 @@
by the cohort service in the backend system.
"""

import enum

import sqlalchemy
from sqlalchemy.dialects import postgresql
from sqlalchemy.ext import declarative

from gdc_ng_models.models import accessed, audit


@enum.unique
class SetType(enum.Enum):
ephemeral = 1
frozen = 2
mutable = 3


@enum.unique
class EntityType(enum.Enum):
case = 1
file = 2
gene = 3
ssm = 4


Base = declarative.declarative_base()


Expand Down Expand Up @@ -51,19 +70,17 @@ class EntitySet(Base, audit.AuditColumnsMixin, accessed.AccessedColumnMixin):
primary_key=True,
)
type = sqlalchemy.Column(
postgresql.ENUM("ephmeral", "frozen", "mutable", name="entity_set_type"),
postgresql.ENUM(SetType, name="entity_set_type"),
nullable=False,
)
entity_type = sqlalchemy.Column(
postgresql.ENUM("case", "file", "gene", "ssm", name="entity_type"),
postgresql.ENUM(EntityType, name="entity_type"),
nullable=False,
)

# entity_ids are UUIDs that are 36 characters long.
# Postgres is more performant when the data sizes are not dynamic
entity_ids = sqlalchemy.Column(
postgresql.ARRAY(sqlalchemy.String(36)), nullable=False
)
# However, postgres does not use lengths in its arrays
entity_ids = sqlalchemy.Column(postgresql.ARRAY(sqlalchemy.String), nullable=False)

def __repr__(self):
return (
Expand All @@ -76,8 +93,8 @@ def __repr__(self):
"updated_datetime={updated_datetime}), "
"accessed_datetime={accessed_datetime})>".format(
id=self.id,
type=self.type,
entity_type=self.entity_type,
type=self.type.name,
entity_type=self.entity_type.name,
entity_ids=self.entity_ids,
created_datetime=self.created_datetime.isoformat()
if self.created_datetime
Expand All @@ -94,8 +111,8 @@ def __repr__(self):
def to_json(self):
return {
"id": str(self.id),
"type": str(self.type),
"entity_type": str(self.entity_type),
"type": self.type.name,
"entity_type": self.entity_type.name,
"entity_ids": [str(entity_id) for entity_id in self.entity_ids],
"created_datetime": self.created_datetime.isoformat()
if self.created_datetime
Expand Down
5 changes: 2 additions & 3 deletions gdc_ng_models/models/misc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import BigInteger, Column, DateTime, Index, String, Text, Sequence
from sqlalchemy import BigInteger, Column, DateTime, Index, Sequence, String, Text
from sqlalchemy.dialects.postgresql import JSONB

from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

Expand Down
9 changes: 4 additions & 5 deletions gdc_ng_models/models/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

from sqlalchemy import (
BigInteger,
Boolean,
Column,
DateTime,
Sequence,
String,
Text,
DateTime,
text,
Boolean,
Sequence,
)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.dialects.postgresql import ARRAY

from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

Expand Down
5 changes: 2 additions & 3 deletions gdc_ng_models/models/qcreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
DateTime,
Enum,
ForeignKey,
Sequence,
String,
Text,
text,
Sequence,
)
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, validates
from sqlalchemy.dialects.postgresql import JSONB


Base = declarative_base()
SEVERITY = Enum("CRITICAL", "WARNING", "PASSED", name="error_severity")
Expand Down
6 changes: 3 additions & 3 deletions gdc_ng_models/models/redaction.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from datetime import datetime

from sqlalchemy import (
Boolean,
BigInteger,
Boolean,
Column,
DateTime,
Enum,
ForeignKey,
Sequence,
String,
Text,
text,
Sequence,
)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import relationship


Base = declarative_base()


Expand Down
5 changes: 2 additions & 3 deletions gdc_ng_models/models/reports.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from sqlalchemy import BigInteger, Column, Text, DateTime, text, Index, func, Sequence
from sqlalchemy import BigInteger, Column, DateTime, Index, Sequence, Text, func, text
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.dialects.postgresql import JSONB


Base = declarative_base()

Expand Down
16 changes: 9 additions & 7 deletions gdc_ng_models/models/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@
Models for submission TransactionLogs
"""

from distutils.version import StrictVersion
from datetime import datetime
from json import loads, dumps
from distutils.version import StrictVersion
from json import dumps, loads

import pytz
import sqlalchemy as db
from sqlalchemy import func, Sequence
from sqlalchemy.ext.declarative import declarative_base, declared_attr
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import relationship, deferred
from sqlalchemy import (
BigInteger,
Boolean,
Column,
DateTime,
ForeignKey,
Integer,
Index,
Integer,
Sequence,
Text,
func,
text,
)
from sqlalchemy.ext.declarative import declarative_base, declared_attr
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import deferred, relationship

if StrictVersion(db.__version__) >= StrictVersion("1.3.4"):
from sqlalchemy.dialects.postgresql.json import JSONB
Expand Down
1 change: 0 additions & 1 deletion gdc_ng_models/snacks/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from gdc_ng_models.utils.decorators import try_or_log_error


logger = getLogger(__name__)

PERMISSIONS = dict(READ="SELECT", WRITE="SELECT, INSERT, UPDATE, DELETE")
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/models/test_cohort.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import enum
import json
import uuid

import pytest
from gdc_ng_models.models import cohort
from sqlalchemy import exc

from gdc_ng_models.models import cohort


class CohortType(enum.Enum):
static = 1
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/models/test_download_reports_models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from datetime import date

from cdisutils.dictionary import sort_dict
from gdc_ng_models.models.download_reports import (
DataDownloadReport,
DataUsageReport,
)

from gdc_ng_models.models.download_reports import DataDownloadReport, DataUsageReport


def test_create_usage_reports(create_reports_db, db_session):
Expand Down
Loading

0 comments on commit f96ea94

Please sign in to comment.