Skip to content

Commit

Permalink
run ./lint.sh and resolve errors
Browse files Browse the repository at this point in the history
* I liberally used `# noqa` in sqlalchemy_demo.py beacuse that is not production code... just temporary for reference

* I made sure to comment every other use of `# noqa`

======================

(venv) ➜  api git:(mf-flask-api) ✗ ./lint.sh
0
(venv) ➜  api git:(mf-flask-api) ✗ ./format.sh
Reformatting create_all_tables.py
Reformatting database_wrapper.py
Reformatting db_config.py
Reformatting db_wrapper.py
Reformatting demo.py
Reformatting flask_api.py
Reformatting gunicorn_config.py
Reformatting sqlalchemy_demo.py
Reformatting Entity/AudioSampleMetaData.py
Reformatting Entity/Clubs.py
Reformatting Entity/Corequisites.py
Reformatting Entity/Corrections.py
Reformatting Entity/Courses.py
Reformatting Entity/OfficeHours.py
Reformatting Entity/PolyRatings.py
Reformatting Entity/Prerequisites.py
Reformatting Entity/Professors.py
Reformatting Entity/__init__.py
Reformatting modules/formatters.py
Reformatting modules/validators.py
(venv) ➜  api git:(mf-flask-api) ✗ ./lint.sh
0
(venv) ➜  api git:(mf-flask-api) ✗
  • Loading branch information
mfekadu committed Feb 3, 2020
1 parent bb4461f commit 805e520
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 31 deletions.
13 changes: 7 additions & 6 deletions Entity/AudioSampleMetaData.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from sqlalchemy import Column, Integer, String, Text, Enum, Boolean
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.dialects.mysql import SET
import enum

# This is the way SQLAlchemy initializes their special classes
Expand Down Expand Up @@ -31,8 +30,10 @@ class AudioSampleMetaData(Base):
filename = Column(Text)

def __repr__(self):
return (
"<AudioSampleMetaData ( id={}, is_wake_word={}, first_name={}, last_name={}, gender={}, noise_level={}, location={}, tone={}, timestamp={}, username={} )>"
.format(self.id, self.is_wake_word, self.first_name, self.last_name,
self.gender, self.noise_level, self.location, self.tone,
self.timestamp, self.username))
string = "<AudioSampleMetaData ( id={}, is_wake_word={}, "
string += "first_name={}, last_name={}, gender={}, noise_level={}, "
string += "location={}, tone={}, timestamp={}, username={} )>"
return (string.format(self.id, self.is_wake_word, self.first_name,
self.last_name, self.gender, self.noise_level,
self.location, self.tone, self.timestamp,
self.username))
3 changes: 0 additions & 3 deletions Entity/OfficeHours.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#OfficeHours


class OfficeHours:

def __init__(self, Professors_id, ohroom, ohday, ohtime):
Expand Down
3 changes: 0 additions & 3 deletions Entity/Prerequisites.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#Prerequisites


class Prerequisites:

def __init__(self, courseId, prereqCourse):
Expand Down
3 changes: 0 additions & 3 deletions Entity/Professors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#Professors


class Professors:

def __init__(self, id, firstName, lastName, phoneNumber, researchInterests,
Expand Down
16 changes: 5 additions & 11 deletions database_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,15 @@
"""
import json
from abc import ABC, abstractmethod
from datetime import datetime, timedelta
from pprint import pprint as pp
from typing import List, Optional, Union

import mysql.connector
import sqlalchemy
from sqlalchemy import (Column, DateTime, ForeignKey, Integer, String, Table,
create_engine)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import backref, relationship, sessionmaker
from sqlalchemy import create_engine, inspect
from sqlalchemy.orm import sessionmaker

import Entity
from Entity.Courses import Courses
from Entity.AudioSampleMetaData import AudioSampleMetaData, NoiseLevel
from sqlalchemy import inspect
from Entity.Courses import Courses


class BadDictionaryKeyError(Exception):
Expand Down Expand Up @@ -328,7 +322,7 @@ def create_AudioSampleMetaData_table(self) -> None:

self.AudioSampleMetaData.__table__.create(bind=self.engine)

@raises_database_error
@raises_database_error # noqa - C901 "too complex" - agreed TODO: reduce complexity
def save_audio_sample_meta_data(self, formatted_data: dict) -> bool:
"""
Save the metadata into the NimbusDatabase.
Expand All @@ -344,7 +338,7 @@ def save_audio_sample_meta_data(self, formatted_data: dict) -> bool:
"tone": "serious-but-not-really",
"timestamp": 1577077883,
"username": "guest",
"filename": "ww_q_serious-but-not-really_here_m_doe_jj_1577077883_guest.wav"
"filename": "ww_q_serious-but-not-really_here_m_doe_jj_1577077883_guest.wav" # noqa because too hard.
}
Raises:
Expand Down
10 changes: 5 additions & 5 deletions sqlalchemy_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
from datetime import datetime, timedelta
from sqlalchemy import Table, Column, Integer, String, DateTime, ForeignKey
from sqlalchemy.orm import relationship, backref
from datetime import datetime, timedelta # noqa
from sqlalchemy import Table, Column, Integer, String, DateTime, ForeignKey # noqa
from sqlalchemy.orm import relationship, backref # noqa
from sqlalchemy.orm import sessionmaker
from pprint import pprint as pp
from sqlalchemy import inspect
Expand All @@ -27,7 +27,7 @@ def __repr__(self):

# connection
# https://docs.sqlalchemy.org/en/13/dialects/mysql.html#module-sqlalchemy.dialects.mysql.mysqlconnector
# engine = create_engine('mysql+mysqlconnector://USERNAME:PASSWORD@HOST_NAME:3306/DATABASE_NAME')
# engine = create_engine('mysql+mysqlconnector://USERNAME:PASSWORD@HOST_NAME:3306/DATABASE_NAME') # noqa
config_file = 'config.json'
with open(config_file) as json_data_file:
config = json.load(json_data_file)
Expand Down Expand Up @@ -101,7 +101,7 @@ def __repr__(self):

print("dropping table Tag")
# https://www.pythonsheets.com/notes/python-sqlalchemy.html#drop-a-table
# https://stackoverflow.com/questions/35918605/how-to-delete-a-table-in-sqlalchemy
# https://stackoverflow.com/questions/35918605/how-to-delete-a-table-in-sqlalchemy # noqa
print(Tag.__table__.drop(engine))
print("dropped??")

Expand Down

0 comments on commit 805e520

Please sign in to comment.