Skip to content

Commit bb9d0df

Browse files
Initial docstrings and ruff formatting
1 parent a3e9ead commit bb9d0df

18 files changed

Lines changed: 2066 additions & 736 deletions

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ ENV/
106106
# vscode
107107
.vscode
108108

109+
# SonarQube
110+
.scannerwork
111+
109112
# Configurations
110113
config.py
111114

@@ -132,4 +135,4 @@ packet/static/site.webmanifest
132135
faviconData.json
133136

134137
# csvs
135-
*.csv
138+
*.csv

packet/__init__.py

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
The application setup and initialization code lives here
33
"""
44

5-
import json
65
import logging
76
import os
87

9-
import csh_ldap
108
import onesignal
119
from flask import Flask
1210
from flask_gzip import Gzip
@@ -26,76 +24,84 @@
2624

2725
# Load default configuration and any environment variable overrides
2826
_root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
29-
app.config.from_pyfile(os.path.join(_root_dir, 'config.env.py'))
27+
app.config.from_pyfile(os.path.join(_root_dir, "config.env.py"))
3028

3129
# Load file based configuration overrides if present
32-
_pyfile_config = os.path.join(_root_dir, 'config.py')
30+
_pyfile_config = os.path.join(_root_dir, "config.py")
3331
if os.path.exists(_pyfile_config):
3432
app.config.from_pyfile(_pyfile_config)
3533

3634
# Fetch the version number
37-
app.config['VERSION'] = get_version()
35+
app.config["VERSION"] = get_version()
3836

3937
# Logger configuration
40-
logging.getLogger().setLevel(app.config['LOG_LEVEL'])
41-
app.logger.info('Launching packet ' + app.config['VERSION'])
42-
app.logger.info('Using the {} realm'.format(app.config['REALM']))
38+
logging.getLogger().setLevel(app.config["LOG_LEVEL"])
39+
app.logger.info("Launching packet " + app.config["VERSION"])
40+
app.logger.info("Using the {} realm".format(app.config["REALM"]))
4341

4442
# Initialize the extensions
4543
db = SQLAlchemy(app)
4644
migrate = Migrate(app, db)
47-
app.logger.info('SQLAlchemy pointed at ' + repr(db.engine.url))
45+
app.logger.info("SQLAlchemy pointed at " + repr(db.engine.url))
4846

49-
APP_CONFIG = ProviderConfiguration(issuer=app.config['OIDC_ISSUER'],
50-
client_metadata=ClientMetadata(app.config['OIDC_CLIENT_ID'],
51-
app.config['OIDC_CLIENT_SECRET']))
47+
APP_CONFIG = ProviderConfiguration(
48+
issuer=app.config["OIDC_ISSUER"],
49+
client_metadata=ClientMetadata(
50+
app.config["OIDC_CLIENT_ID"], app.config["OIDC_CLIENT_SECRET"]
51+
),
52+
)
5253

5354
# Initialize Onesignal Notification apps
5455
csh_onesignal_client = None
55-
if app.config['ONESIGNAL_USER_AUTH_KEY'] and \
56-
app.config['ONESIGNAL_CSH_APP_AUTH_KEY'] and \
57-
app.config['ONESIGNAL_CSH_APP_ID']:
56+
if (
57+
app.config["ONESIGNAL_USER_AUTH_KEY"]
58+
and app.config["ONESIGNAL_CSH_APP_AUTH_KEY"]
59+
and app.config["ONESIGNAL_CSH_APP_ID"]
60+
):
5861
csh_onesignal_client = onesignal.Client(
59-
user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
60-
app_auth_key=app.config['ONESIGNAL_CSH_APP_AUTH_KEY'],
61-
app_id=app.config['ONESIGNAL_CSH_APP_ID']
62+
user_auth_key=app.config["ONESIGNAL_USER_AUTH_KEY"],
63+
app_auth_key=app.config["ONESIGNAL_CSH_APP_AUTH_KEY"],
64+
app_id=app.config["ONESIGNAL_CSH_APP_ID"],
6265
)
63-
app.logger.info('CSH Onesignal configured and notifications enabled')
66+
app.logger.info("CSH Onesignal configured and notifications enabled")
6467

6568
intro_onesignal_client = None
66-
if app.config['ONESIGNAL_USER_AUTH_KEY'] and \
67-
app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'] and \
68-
app.config['ONESIGNAL_INTRO_APP_ID']:
69+
if (
70+
app.config["ONESIGNAL_USER_AUTH_KEY"]
71+
and app.config["ONESIGNAL_INTRO_APP_AUTH_KEY"]
72+
and app.config["ONESIGNAL_INTRO_APP_ID"]
73+
):
6974
intro_onesignal_client = onesignal.Client(
70-
user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
71-
app_auth_key=app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'],
72-
app_id=app.config['ONESIGNAL_INTRO_APP_ID']
75+
user_auth_key=app.config["ONESIGNAL_USER_AUTH_KEY"],
76+
app_auth_key=app.config["ONESIGNAL_INTRO_APP_AUTH_KEY"],
77+
app_id=app.config["ONESIGNAL_INTRO_APP_ID"],
7378
)
74-
app.logger.info('Intro Onesignal configured and notifications enabled')
79+
app.logger.info("Intro Onesignal configured and notifications enabled")
7580

7681
# OIDC Auth
77-
auth = OIDCAuthentication({'app': APP_CONFIG}, app)
78-
app.logger.info('OIDCAuth configured')
82+
auth = OIDCAuthentication({"app": APP_CONFIG}, app)
83+
app.logger.info("OIDCAuth configured")
7984

8085
# Sentry
8186
# pylint: disable=abstract-class-instantiated
8287
sentry_sdk.init(
83-
dsn=app.config['SENTRY_DSN'],
84-
integrations=[FlaskIntegration(), SqlalchemyIntegration()]
88+
dsn=app.config["SENTRY_DSN"],
89+
integrations=[FlaskIntegration(), SqlalchemyIntegration()],
8590
)
8691

87-
88-
# pylint: disable=wrong-import-position
89-
from .ldap import ldap
90-
from . import models
91-
from . import context_processors
92-
from . import commands
93-
from .routes import api, shared
94-
95-
if app.config['REALM'] == 'csh':
96-
from .routes import upperclassmen
97-
from .routes import admin
92+
__all__: list = [
93+
"ldap",
94+
"models",
95+
"context_processors",
96+
"commands",
97+
"api",
98+
"shared",
99+
]
100+
101+
if app.config["REALM"] == "csh":
102+
from .routes import upperclassmen as upperclassmen
103+
from .routes import admin as admin
98104
else:
99-
from .routes import freshmen
105+
from .routes import freshmen as freshmen
100106

101-
app.logger.info('Routes registered')
107+
app.logger.info("Routes registered")

0 commit comments

Comments
 (0)