Skip to content

Commit

Permalink
Requirements upgrades and config refactor continues
Browse files Browse the repository at this point in the history
  • Loading branch information
questionlp committed Dec 18, 2022
1 parent 08ef2b5 commit 3ef8019
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 50 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changes

## 5.1.5

### Application Changes

- Continue refactoring how application and database connection settings are loaded and setting default values

### Component Changes

- Upgrade wwdtm from 2.0.7 to 2.0.8, which also includes the following changes:
- Upgrade MySQL Connector/Python from 8.0.30 to 8.0.31
- Upgrade NumPy from 1.23.2 to 1.23.4
- Upgrade python-slugify from 5.0.2 to 6.1.2
- Upgrade pytz from 2022.2.1 to 2022.6
- Upgrade Flask from 2.2.0 to 2.2.2
- Upgrade Werkzeug from 2.2.1 to 2.2.2

### Development Changes

- Upgrade flake8 from 4.0.1 to 5.0.4
- Upgrade pycodestyle from 2.8.0 to 2.9.1
- Upgrade pytest from 7.1.2 to 7.2.0
- Upgrade black from 22.6.0 to 22.10.0

## 5.1.4

### Application Changes
Expand Down
22 changes: 13 additions & 9 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,19 @@ def create_app():
app.jinja_env.globals["rank_map"] = dicts.PANELIST_RANKS
app.jinja_env.globals["rendered_at"] = utility.generate_date_time_stamp

app.jinja_env.globals["time_zone"] = app.config["app_settings"].get("app_time_zone", "UTC")
app.jinja_env.globals["ga_property_code"] = app.config["app_settings"].get("ga_property_code", "")
app.jinja_env.globals["api_url"] = app.config["app_settings"].get("api_url", "")
app.jinja_env.globals["blog_url"] = app.config["app_settings"].get("blog_url", "")
app.jinja_env.globals["graphs_url"] = app.config["app_settings"].get("graphs_url", "")
app.jinja_env.globals["reports_url"] = app.config["app_settings"].get("reports_url", "")
app.jinja_env.globals["site_url"] = app.config["app_settings"].get("site_url", "")
app.jinja_env.globals["mastodon_url"] = app.config["app_settings"].get("mastodon_url", "")
app.jinja_env.globals["mastodon_user"] = app.config["app_settings"].get("mastodon_user", "")
app.jinja_env.globals["time_zone"] = _config["settings"]["app_time_zone"]
app.jinja_env.globals["ga_property_code"] = _config["settings"].get(
"ga_property_code", ""
)
app.jinja_env.globals["api_url"] = _config["settings"].get("api_url", "")
app.jinja_env.globals["blog_url"] = _config["settings"].get("blog_url", "")
app.jinja_env.globals["graphs_url"] = _config["settings"].get("graphs_url", "")
app.jinja_env.globals["reports_url"] = _config["settings"].get("reports_url", "")
app.jinja_env.globals["site_url"] = _config["settings"].get("site_url", "")
app.jinja_env.globals["mastodon_url"] = _config["settings"].get("mastodon_url", "")
app.jinja_env.globals["mastodon_user"] = _config["settings"].get(
"mastodon_user", ""
)

# Register Jinja template filters
app.jinja_env.filters["pretty_jsonify"] = utility.pretty_jsonify
Expand Down
49 changes: 23 additions & 26 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# stats.wwdt.me is released under the terms of the Apache License 2.0
"""Configuration Loading and Parsing for Wait Wait Stats Page"""
import json
from multiprocessing import pool
from typing import Any, Dict
import pytz

from app import utility

Expand All @@ -15,31 +15,33 @@


def load_config(
config_file_path: str = "config.json", connection_pool_size: int = 12
config_file_path: str = "config.json",
connection_pool_size: int = 12,
connection_pool_name: str = "wwdtm_stats",
app_time_zone: str = "UTC"
) -> Dict[str, Dict[str, Any]]:
with open(config_file_path, "r") as config_file:
app_config = json.load(config_file)

database_config = app_config["database"]
settings_config = app_config["settings"]

if "database" in app_config:
database_config = app_config["database"]
database_config = app_config.get("database", None)
settings_config = app_config.get("settings", None)

# Process database configuration settings
if database_config:
# Set database connection pooling settings if and only if there
# is a ``use_pool`` key and it is set to True. Remove the key
# after parsing through the configuration to prevent issues
# with mysql.connector.connect()
if "use_pool" in database_config and database_config["use_pool"]:
if "pool_name" not in database_config or not database_config["pool_name"]:
database_config["pool_name"] = "wwdtm_stats"

if "pool_size" not in database_config or not database_config["pool_size"]:
database_config["pool_size"] = connection_pool_size
use_pool = database_config.get("use_pool", False)

if "pool_size" in database_config and database_config["pool_size"] < 8:
database_config["pool_size"] = 8
if use_pool:
pool_name = database_config.get("pool_name", connection_pool_name)
pool_size = database_config.get("pool_size", connection_pool_size)
if pool_size < connection_pool_size:
pool_size = connection_pool_size

database_config["pool_name"] = pool_name
database_config["pool_size"] = pool_size
del database_config["use_pool"]
else:
if "pool_name" in database_config:
Expand All @@ -51,17 +53,12 @@ def load_config(
if "use_pool" in database_config:
del database_config["use_pool"]

if "time_zone" in settings_config and settings_config["time_zone"]:
time_zone = settings_config["time_zone"]
time_zone_object, time_zone_string = utility.time_zone_parser(time_zone)

settings_config["app_time_zone"] = time_zone_object
settings_config["time_zone"] = time_zone_string
database_config["time_zone"] = time_zone_string
else:
settings_config["app_time_zone"] = pytz.timezone("UTC")
settings_config["time_zone"] = "UTC"
database_config["time_zone"] = "UTC"
# Process time zone configuration settings
time_zone = settings_config.get("time_zone", app_time_zone)
time_zone_object, time_zone_string = utility.time_zone_parser(time_zone)
settings_config["app_time_zone"] = time_zone_object
settings_config["time_zone"] = time_zone_string
database_config["time_zone"] = time_zone_string

return {
"database": database_config,
Expand Down
2 changes: 1 addition & 1 deletion app/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# Copyright (c) 2018-2022 Linh Pham
# stats.wwdt.me is released under the terms of the Apache License 2.0
"""Application Version for Wait Wait Stats Page"""
APP_VERSION = "5.1.4"
APP_VERSION = "5.1.5"
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[tool.black]
required-version = "22.6.0"
target-version = ["py38", "py39", "py310"]
required-version = "22.10.0"
target-version = ["py38", "py39", "py310", "py311"]
15 changes: 7 additions & 8 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
flake8==4.0.1
pycodestyle==2.8.0
pytest==7.1.2
black==22.6.0
flake8==5.0.4
pycodestyle==2.9.1
pytest==7.2.0
black==22.10.0

python-dateutil==2.8.2
Flask==2.2.0
Werkzeug==2.2.1
pytz==2022.2.1
Flask==2.2.2
Werkzeug==2.2.2
gunicorn==20.1.0
Markdown==3.4.1

wwdtm==2.0.7
wwdtm==2.0.8
7 changes: 3 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
python-dateutil==2.8.2
Flask==2.2.0
Werkzeug==2.2.1
pytz==2022.2.1
Flask==2.2.2
Werkzeug==2.2.2
gunicorn==20.1.0
Markdown==3.4.1

wwdtm==2.0.7
wwdtm==2.0.8

0 comments on commit 3ef8019

Please sign in to comment.