Skip to content

Commit

Permalink
fix: format, minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfromyeg committed Aug 12, 2024
1 parent 03be9bc commit bc87cca
Show file tree
Hide file tree
Showing 18 changed files with 31 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"first-line-h1": false,
"line-length": false
"first-line-h1": false,
"line-length": false
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ typecheck:

format:
@echo "Formatting the code..."
@ruff bereal
@ruff check bereal && ruff format bereal
1 change: 1 addition & 0 deletions bereal/bereal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Methods to interface with the unofficial BeReal API.
"""

import os
from datetime import datetime
from typing import Any
Expand Down
1 change: 1 addition & 0 deletions bereal/celery.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Celery stuff.
"""

import gc
from celery import Celery

Expand Down
1 change: 1 addition & 0 deletions bereal/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
A command-line interface for the BeReal generator.
"""

import argparse
import os
import shutil
Expand Down
1 change: 1 addition & 0 deletions bereal/images.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Combine two images together, with the secondary image in the top-left corner of the primary image.
"""

import os
import shutil

Expand Down
1 change: 1 addition & 0 deletions bereal/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
A custom logger.
"""

import logging
import logging.config

Expand Down
1 change: 1 addition & 0 deletions bereal/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
For now, only phone. Eventually, consider e-mail.
"""

from .utils import FLASK_ENV, TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_PHONE_NUMBER
from .logger import logger

Expand Down
1 change: 1 addition & 0 deletions bereal/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
It contains the Flask app routing and the functions to interact with the BeReal API.
"""

from gevent import monkey

monkey.patch_all()
Expand Down
1 change: 1 addition & 0 deletions bereal/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Utility functions and constants.
"""

import configparser
import os
import subprocess
Expand Down
1 change: 1 addition & 0 deletions bereal/videos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This script generates a slideshow from a folder of images and a music file.
"""

import os

import librosa
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.8"

services:
web:
build:
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.8"

services:
web:
build:
Expand Down
2 changes: 2 additions & 0 deletions migrations/README → migrations/MIGRATIONS.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Migrations

Single-database configuration for Flask.
33 changes: 13 additions & 20 deletions migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,31 @@
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')
logger = logging.getLogger("alembic.env")


def get_engine():
try:
# this works with Flask-SQLAlchemy<3 and Alchemical
return current_app.extensions['migrate'].db.get_engine()
return current_app.extensions["migrate"].db.get_engine()
except (TypeError, AttributeError):
# this works with Flask-SQLAlchemy>=3
return current_app.extensions['migrate'].db.engine
return current_app.extensions["migrate"].db.engine


def get_engine_url():
try:
return get_engine().url.render_as_string(hide_password=False).replace(
'%', '%%')
return get_engine().url.render_as_string(hide_password=False).replace("%", "%%")
except AttributeError:
return str(get_engine().url).replace('%', '%%')
return str(get_engine().url).replace("%", "%%")


# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
config.set_main_option('sqlalchemy.url', get_engine_url())
target_db = current_app.extensions['migrate'].db
config.set_main_option("sqlalchemy.url", get_engine_url())
target_db = current_app.extensions["migrate"].db

# other values from the config, defined by the needs of env.py,
# can be acquired:
Expand All @@ -46,7 +45,7 @@ def get_engine_url():


def get_metadata():
if hasattr(target_db, 'metadatas'):
if hasattr(target_db, "metadatas"):
return target_db.metadatas[None]
return target_db.metadata

Expand All @@ -64,9 +63,7 @@ def run_migrations_offline():
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=get_metadata(), literal_binds=True
)
context.configure(url=url, target_metadata=get_metadata(), literal_binds=True)

with context.begin_transaction():
context.run_migrations()
Expand All @@ -84,24 +81,20 @@ def run_migrations_online():
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
if getattr(config.cmd_opts, "autogenerate", False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')
logger.info("No changes in schema detected.")

conf_args = current_app.extensions['migrate'].configure_args
conf_args = current_app.extensions["migrate"].configure_args
if conf_args.get("process_revision_directives") is None:
conf_args["process_revision_directives"] = process_revision_directives

connectable = get_engine()

with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=get_metadata(),
**conf_args
)
context.configure(connection=connection, target_metadata=get_metadata(), **conf_args)

with context.begin_transaction():
context.run_migrations()
Expand Down
2 changes: 1 addition & 1 deletion scripts/server-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

# Apply database migrations
echo "Running database migrations"
Expand Down
2 changes: 2 additions & 0 deletions scripts/test-cors.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

curl -H "Origin: https://bereal.michaeldemar.co" \
-H "Access-Control-Request-Method: GET" \
-H "Access-Control-Request-Headers: X-Requested-With" \
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-nginx.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
#!/bin/bash

docker run --rm -v ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro nginx nginx -t

0 comments on commit bc87cca

Please sign in to comment.