Skip to content

Commit

Permalink
refactor: add internal use indicator to _clean_up_table, _do_connect …
Browse files Browse the repository at this point in the history
…and _do_begin functions

improve docstrings
  • Loading branch information
Michele-Alberti committed Nov 19, 2024
1 parent a20e209 commit f94438f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
16 changes: 13 additions & 3 deletions dlunch/core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""Module that defines main functions used to manage Data-Lunch operations.
!!! Note
Could be improved with classes.
"""

import cryptography.fernet
import panel as pn
import pandas as pd
Expand Down Expand Up @@ -1102,7 +1110,7 @@ def df_list_by_lunch_time(

# The following function prepare the dataframe before saving it into
# the dictionary that will be returned
def clean_up_table(
def _clean_up_table(
config: DictConfig, df_in: pd.DataFrame, df_complete: pd.DataFrame
):
df = df_in.copy()
Expand Down Expand Up @@ -1147,13 +1155,15 @@ def clean_up_table(
# Clean and add resulting dataframes to dict
# RESTAURANT LUNCH
if not df_users_restaurant.empty:
df_users_restaurant = clean_up_table(
df_users_restaurant = _clean_up_table(
config, df_users_restaurant, df
)
df_dict[time] = df_users_restaurant
# TAKEAWAY
if not df_users_takeaways.empty:
df_users_takeaways = clean_up_table(config, df_users_takeaways, df)
df_users_takeaways = _clean_up_table(
config, df_users_takeaways, df
)
df_dict[f"{time} {config.panel.gui.takeaway_id}"] = (
df_users_takeaways
)
Expand Down
10 changes: 5 additions & 5 deletions dlunch/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,13 +964,13 @@ def create_exclusive_session(config: DictConfig) -> Session:

# Alter begin statement
@event.listens_for(engine, "connect")
def do_connect(dbapi_connection, connection_record):
def _do_connect(dbapi_connection, connection_record):
# disable pysqlite's emitting of the BEGIN statement entirely.
# also stops it from emitting COMMIT before any DDL.
dbapi_connection.isolation_level = None

@event.listens_for(engine, "begin")
def do_begin(conn):
def _do_begin(conn):
# Emit exclusive BEGIN
conn.exec_driver_sql("BEGIN EXCLUSIVE")

Expand Down Expand Up @@ -1003,18 +1003,18 @@ def create_database(config: DictConfig, add_basic_auth_users=False) -> None:
)
),
)
def create_database_with_retries(config: DictConfig) -> None:
def _create_database_with_retries(config: DictConfig) -> None:
engine = create_engine(config)
Data.metadata.create_all(engine)

# Create tables
log.debug(f"attempt database creation: {config.db.attempt_creation}")
if config.db.attempt_creation:
create_database_with_retries(config)
_create_database_with_retries(config)

# Retries stats
log.debug(
f"create database attempts: {create_database_with_retries.retry.statistics}"
f"create database attempts: {_create_database_with_retries.retry.statistics}"
)

# If requested add users for basic auth (admin and guest)
Expand Down
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ for a group of people (wether they are friends or teammates).

It started as a small personal project and it quickly became an unrepleaceable companion for me and my colleagues.

[Getting Started :material-fuel:](getting_started.md){ .md-button .md-button--primary }

## More info

!!! warning "Work in Progress"
Expand Down
17 changes: 15 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@ theme:
logo: assets/logo-dark.png
favicon: assets/favicon.ico
palette:
scheme: dlunch
# Light mode
- scheme: dlunch
toggle:
icon: material/lightbulb-outline
name: Switch to dark mode
# Dark mode
- scheme: slate
toggle:
icon: material/lightbulb
name: Switch to light mode
features:
- navigation.tabs
- navigation.tabs.sticky
- navigation.sections
- navigation.top
- toc.follow

# Custom colors
extra_css:
Expand All @@ -42,9 +53,9 @@ extra:

# Plugins
plugins:
- gh-admonitions
- search
- autorefs
- gh-admonitions
- gen-files:
scripts:
- scripts/docs/generate_reference_pages.py
Expand Down Expand Up @@ -76,6 +87,8 @@ plugins:

# Extensions
markdown_extensions:
- toc:
permalink: true
- admonition
- pymdownx.details
- pymdownx.superfences
Expand Down

0 comments on commit f94438f

Please sign in to comment.