Skip to content

Commit

Permalink
Merge pull request #10 from EnhancedJax/dev
Browse files Browse the repository at this point in the history
0.1.11
  • Loading branch information
EnhancedJax authored Nov 22, 2024
2 parents 69dd2d2 + ca95d27 commit 85db001
Show file tree
Hide file tree
Showing 14 changed files with 480 additions and 78 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Publish"

on:
push:
branches:
- main

jobs:
run:
name: "Build and publish release"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: uv.lock

- name: Set up Python
run: uv python install 3.13 # Or whatever version you want to use.

- name: Build
run: uv build

- name: Publish
run: uv publish -t ${{ secrets.PYPI_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ __pycache__/
*.db
dist/
Bagels.egg-info/
instance/
instance/
snapshot_report.html
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.1.11

- Add transfers as templates.
- Fix: Crash when go to date in calendar
- Fix: Not creating and using custom config file

## 0.1.10

- View by accounts is now an app action. Records will be filtered as well in that view.
Expand Down
11 changes: 8 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "Bagels"
version = "0.1.10"
version = "0.1.11"
authors = [
{ name = "Jax", email = "[email protected]" }
]
Expand All @@ -23,7 +23,6 @@ dependencies = [
"frozenlist==1.5.0",
"idna==3.10",
"itsdangerous==2.2.0",
"jinja2==3.1.4",
"linkify-it-py==2.0.3",
"markdown-it-py==3.0.0",
"markupsafe==3.0.2",
Expand All @@ -39,7 +38,7 @@ dependencies = [
"pydantic-settings>=2.6.1",
"pydantic==2.9.2",
"pygments==2.18.0",
"pytest>=8.3.3",
"pytest-textual-snapshot>=1.0.0",
"pyyaml==6.0.2",
"rich==13.9.3",
"sqlalchemy==2.0.36",
Expand Down Expand Up @@ -70,6 +69,12 @@ bagels = "bagels.__main__:cli"
[tool.uv]
dev-dependencies = [
"textual-dev>=1.6.1",
"pytest>=8.3.1",
"jinja2>=3.1.4",
"syrupy>=4.6.1",
"pytest-xdist>=3.6.1",
"pytest-cov>=5.0.0",
"pytest-textual-snapshot>=1.0.0",
]

[tool.hatch.metadata]
Expand Down
21 changes: 6 additions & 15 deletions src/bagels/__main__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
from pathlib import Path

# from venv import create

import click
import yaml

from bagels.config import Config
from bagels.locations import config_file, database_file, set_custom_root


def create_config_file() -> None:
f = config_file()
if f.exists():
return

try:
f.touch()
with open(f, "w") as f:
yaml.dump(Config.get_default().model_dump(), f)
except OSError:
pass


@click.group(invoke_without_command=True)
@click.option(
"--at",
Expand All @@ -33,6 +20,10 @@ def cli(ctx, at: click.Path | None):
set_custom_root(at)
if ctx.invoked_subcommand is None:

from bagels.config import load_config

load_config()

from bagels.models.database.app import init_db

init_db()
Expand Down
8 changes: 7 additions & 1 deletion src/bagels/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ def watch_app_theme(self, theme: str | None) -> None:
self.refresh_css(animate=False)
self.screen._update_styles()
if theme:
theme_object = self.themes[theme]
try:
theme_object = self.themes[theme]
except KeyError:
self.notify(
f"Theme {theme!r} not found.", title="Theme Error", timeout=1
)
return
self.theme_change_signal.publish(theme_object)

@on(CommandPalette.Opened)
Expand Down
19 changes: 11 additions & 8 deletions src/bagels/components/modules/datemode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from textual.widgets import Label, Static

from textual.widgets import Button
from bagels.forms.form import Form, FormField
from bagels.modals.input import InputModal
from bagels.config import CONFIG

Expand All @@ -18,14 +19,16 @@ class DateMode(Static):
Binding(CONFIG.hotkeys.home.datemode.go_to_day, "go_to_day", "Go to Day"),
]

FORM = [
{
"type": "dateAutoDay",
"key": "date",
"title": "Date",
"default_value": datetime.now().strftime("%d"),
}
]
FORM = Form(
fields=[
FormField(
type="dateAutoDay",
key="date",
title="Date",
default_value=datetime.now().strftime("%d"),
)
]
)

def __init__(self, parent: Static, *args, **kwargs) -> None:
super().__init__(
Expand Down
5 changes: 3 additions & 2 deletions src/bagels/components/modules/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ def check_result_person(result) -> None:
return
if record.isTransfer:
self.app.push_screen(
TransferModal(record), callback=check_result_records
TransferModal(title="Edit transfer", record=record),
callback=check_result_records,
)
else:
filled_form, filled_splits = self.record_form.get_filled_form(
Expand Down Expand Up @@ -614,7 +615,7 @@ def check_result(result) -> None:
timeout=3,
)

self.app.push_screen(TransferModal(), callback=check_result)
self.app.push_screen(TransferModal(title="New transfer"), callback=check_result)

# region View
# --------------- View --------------- #
Expand Down
89 changes: 64 additions & 25 deletions src/bagels/components/modules/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
from bagels.modals.confirmation import ConfirmationModal
from bagels.modals.input import InputModal
from bagels.config import CONFIG
from bagels.modals.transfer import TransferModal
from bagels.models.record_template import RecordTemplate
from bagels.managers.record_templates import (
create_template,
delete_template,
get_adjacent_template,
get_all_templates,
get_template_by_id,
swap_template_order,
update_template,
)
Expand All @@ -24,9 +26,12 @@ class Templates(Static):
can_focus = True

BINDINGS = [
Binding(CONFIG.hotkeys.new, "new_template", "New Template"),
Binding(CONFIG.hotkeys.edit, "edit_template", "Edit Template"),
Binding(CONFIG.hotkeys.delete, "delete_template", "Delete Template"),
Binding(CONFIG.hotkeys.new, "new_template", "New"),
Binding(
CONFIG.hotkeys.home.new_transfer, "new_transfer", "New Transfer Template"
),
Binding(CONFIG.hotkeys.edit, "edit_template", "Edit"),
Binding(CONFIG.hotkeys.delete, "delete_template", "Delete"),
Binding("left", "swap_previous", "Swap left"),
Binding("right", "swap_next", "Swap right"),
]
Expand Down Expand Up @@ -56,15 +61,23 @@ def _create_templates_widgets(self, container: Container) -> None:
for index, template in enumerate(self.templates):
if index > 8:
break
color = template.category.color
widget = Container(
Label(
f"[{color}]{CONFIG.symbols.category_color}[/{color}]", classes="dot"
),
Label(f"{template.label}", classes="label"),
id=f"template-{template.id}",
classes="template-item",
)
if template.isTransfer:
widget = Container(
Label(f"{template.label}", classes="label"),
id=f"template-{template.id}",
classes="template-item",
)
else:
color = template.category.color
widget = Container(
Label(
f"[{color}]{CONFIG.symbols.category_color}[/{color}]",
classes="dot",
),
Label(f"{template.label}", classes="label"),
id=f"template-{template.id}",
classes="template-item",
)
widget.border_subtitle = str(index + 1)
widget.can_focus = True
container.compose_add_child(widget)
Expand Down Expand Up @@ -94,6 +107,7 @@ def _notify_no_selected_template(self) -> None:
timeout=3,
)

# region Callback
# ------------- Callback ------------- #

def on_descendant_focus(self, event: events.DescendantFocus):
Expand Down Expand Up @@ -123,16 +137,13 @@ def select_template(self, index: int) -> None:
)
self.page_parent.rebuild()

# region CRUD
# ----------------- - ---------------- #

def action_new_template(self) -> None:
def check_result(result) -> None:
if result:
create_template(result)
# try:
# except Exception as e:
# self.app.notify(
# title="Error", message=f"{e}", severity="error", timeout=10
# )
# else:
self.app.notify(
title="Success",
message=f"Template created",
Expand All @@ -146,6 +157,23 @@ def check_result(result) -> None:
callback=check_result,
)

def action_new_transfer(self) -> None:
def check_result(result) -> None:
if result:
create_template(result)
self.app.notify(
title="Success",
message=f"Template created",
severity="information",
timeout=3,
)
self.rebuild()

self.app.push_screen(
TransferModal(title="New Transfer Template", isTemplate=True),
callback=check_result,
)

def action_edit_template(self) -> None:
if not self.selected_template_id:
self._notify_no_selected_template()
Expand All @@ -170,13 +198,24 @@ def check_result(result) -> None:
self.rebuild()

# ----------------- - ---------------- #
self.app.push_screen(
InputModal(
"Edit Template",
form=self.template_form.get_filled_form(self.selected_template_id),
),
callback=check_result,
)
template = get_template_by_id(self.selected_template_id)
if template.isTransfer:
self.app.push_screen(
TransferModal(
title="Edit Transfer Template",
record=template,
isTemplate=True,
),
callback=check_result,
)
else:
self.app.push_screen(
InputModal(
"Edit Template",
form=self.template_form.get_filled_form(self.selected_template_id),
),
callback=check_result,
)

def action_delete_template(self) -> None:
if not self.selected_template_id:
Expand Down
27 changes: 18 additions & 9 deletions src/bagels/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any, Literal
import yaml
from pydantic import BaseModel, Field
from pydantic_settings import BaseSettings, SettingsConfigDict
from pydantic_settings import SettingsConfigDict
from pydantic_settings_yaml import YamlBaseSettings
from bagels.locations import config_file

Expand Down Expand Up @@ -63,7 +63,7 @@ class Symbols(BaseModel):


class State(BaseModel):
theme: str = "posting"
theme: str = "dark"


class Config(YamlBaseSettings):
Expand Down Expand Up @@ -112,14 +112,23 @@ def get_default(cls):
)


# Only try to load from file if it exists
config_path = config_file()
CONFIG = None

with warnings.catch_warnings():
warnings.simplefilter("ignore")
CONFIG = (
Config.get_default() if not config_path.exists() else Config()
) # ignore warnings about empty env file

def load_config():
f = config_file()
if not f.exists():
try:
f.touch()
with open(f, "w") as f:
yaml.dump(Config.get_default().model_dump(), f)
except OSError:
pass

global CONFIG
with warnings.catch_warnings():
warnings.simplefilter("ignore")
CONFIG = Config() # ignore warnings about empty env file


def write_state(key: str, value: Any) -> None:
Expand Down
Loading

0 comments on commit 85db001

Please sign in to comment.