Skip to content

Commit 4a1356b

Browse files
committed
Refactor code for improved readability and consistency in various modules
1 parent bfe4f2b commit 4a1356b

File tree

12 files changed

+206
-203
lines changed

12 files changed

+206
-203
lines changed

context_portal/alembic/env.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
21
from logging.config import fileConfig
32

4-
from sqlalchemy import engine_from_config
5-
from sqlalchemy import pool
3+
from sqlalchemy import engine_from_config, pool
64

75
from alembic import context
86

@@ -65,9 +63,7 @@ def run_migrations_online() -> None:
6563
)
6664

6765
with connectable.connect() as connection:
68-
context.configure(
69-
connection=connection, target_metadata=target_metadata
70-
)
66+
context.configure(connection=connection, target_metadata=target_metadata)
7167

7268
with context.begin_transaction():
7369
context.run_migrations()
Lines changed: 125 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,141 @@
1-
21
"""Initial schema
32
43
Revision ID: 20250617
54
Revises:
65
Create Date: 2025-06-17 15:00:00.000000
76
87
"""
9-
from alembic import op
10-
import sqlalchemy as sa
8+
119
import json
1210

11+
import sqlalchemy as sa
12+
13+
from alembic import op
14+
1315
# revision identifiers, used by Alembic.
14-
revision = '20250617'
16+
revision = "20250617"
1517
down_revision = None
1618
branch_labels = None
1719
depends_on = None
1820

1921

2022
def upgrade() -> None:
2123
# ### commands auto-generated by Alembic - please adjust! ###
22-
op.create_table('active_context',
23-
sa.Column('id', sa.Integer(), nullable=False),
24-
sa.Column('content', sa.Text(), nullable=False),
25-
sa.PrimaryKeyConstraint('id')
24+
op.create_table(
25+
"active_context",
26+
sa.Column("id", sa.Integer(), nullable=False),
27+
sa.Column("content", sa.Text(), nullable=False),
28+
sa.PrimaryKeyConstraint("id"),
29+
)
30+
op.create_table(
31+
"active_context_history",
32+
sa.Column("id", sa.Integer(), nullable=False),
33+
sa.Column("timestamp", sa.DateTime(), nullable=False),
34+
sa.Column("version", sa.Integer(), nullable=False),
35+
sa.Column("content", sa.Text(), nullable=False),
36+
sa.Column("change_source", sa.String(length=255), nullable=True),
37+
sa.PrimaryKeyConstraint("id"),
38+
)
39+
op.create_table(
40+
"context_links",
41+
sa.Column("id", sa.Integer(), nullable=False),
42+
sa.Column("workspace_id", sa.String(length=1024), nullable=False),
43+
sa.Column("source_item_type", sa.String(length=255), nullable=False),
44+
sa.Column("source_item_id", sa.String(length=255), nullable=False),
45+
sa.Column("target_item_type", sa.String(length=255), nullable=False),
46+
sa.Column("target_item_id", sa.String(length=255), nullable=False),
47+
sa.Column("relationship_type", sa.String(length=255), nullable=False),
48+
sa.Column("description", sa.Text(), nullable=True),
49+
sa.Column(
50+
"timestamp",
51+
sa.DateTime(),
52+
server_default=sa.text("(CURRENT_TIMESTAMP)"),
53+
nullable=False,
54+
),
55+
sa.PrimaryKeyConstraint("id"),
2656
)
27-
op.create_table('active_context_history',
28-
sa.Column('id', sa.Integer(), nullable=False),
29-
sa.Column('timestamp', sa.DateTime(), nullable=False),
30-
sa.Column('version', sa.Integer(), nullable=False),
31-
sa.Column('content', sa.Text(), nullable=False),
32-
sa.Column('change_source', sa.String(length=255), nullable=True),
33-
sa.PrimaryKeyConstraint('id')
57+
op.create_index(
58+
op.f("ix_context_links_source_item_id"),
59+
"context_links",
60+
["source_item_id"],
61+
unique=False,
3462
)
35-
op.create_table('context_links',
36-
sa.Column('id', sa.Integer(), nullable=False),
37-
sa.Column('workspace_id', sa.String(length=1024), nullable=False),
38-
sa.Column('source_item_type', sa.String(length=255), nullable=False),
39-
sa.Column('source_item_id', sa.String(length=255), nullable=False),
40-
sa.Column('target_item_type', sa.String(length=255), nullable=False),
41-
sa.Column('target_item_id', sa.String(length=255), nullable=False),
42-
sa.Column('relationship_type', sa.String(length=255), nullable=False),
43-
sa.Column('description', sa.Text(), nullable=True),
44-
sa.Column('timestamp', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
45-
sa.PrimaryKeyConstraint('id')
63+
op.create_index(
64+
op.f("ix_context_links_source_item_type"),
65+
"context_links",
66+
["source_item_type"],
67+
unique=False,
4668
)
47-
op.create_index(op.f('ix_context_links_source_item_id'), 'context_links', ['source_item_id'], unique=False)
48-
op.create_index(op.f('ix_context_links_source_item_type'), 'context_links', ['source_item_type'], unique=False)
49-
op.create_index(op.f('ix_context_links_target_item_id'), 'context_links', ['target_item_id'], unique=False)
50-
op.create_index(op.f('ix_context_links_target_item_type'), 'context_links', ['target_item_type'], unique=False)
51-
op.create_table('custom_data',
52-
sa.Column('id', sa.Integer(), nullable=False),
53-
sa.Column('timestamp', sa.DateTime(), nullable=False),
54-
sa.Column('category', sa.String(length=255), nullable=False),
55-
sa.Column('key', sa.String(length=255), nullable=False),
56-
sa.Column('value', sa.Text(), nullable=False),
57-
sa.PrimaryKeyConstraint('id'),
58-
sa.UniqueConstraint('category', 'key')
69+
op.create_index(
70+
op.f("ix_context_links_target_item_id"),
71+
"context_links",
72+
["target_item_id"],
73+
unique=False,
5974
)
60-
op.create_table('decisions',
61-
sa.Column('id', sa.Integer(), nullable=False),
62-
sa.Column('timestamp', sa.DateTime(), nullable=False),
63-
sa.Column('summary', sa.Text(), nullable=False),
64-
sa.Column('rationale', sa.Text(), nullable=True),
65-
sa.Column('implementation_details', sa.Text(), nullable=True),
66-
sa.Column('tags', sa.Text(), nullable=True),
67-
sa.PrimaryKeyConstraint('id')
75+
op.create_index(
76+
op.f("ix_context_links_target_item_type"),
77+
"context_links",
78+
["target_item_type"],
79+
unique=False,
6880
)
69-
op.create_table('product_context',
70-
sa.Column('id', sa.Integer(), nullable=False),
71-
sa.Column('content', sa.Text(), nullable=False),
72-
sa.PrimaryKeyConstraint('id')
81+
op.create_table(
82+
"custom_data",
83+
sa.Column("id", sa.Integer(), nullable=False),
84+
sa.Column("timestamp", sa.DateTime(), nullable=False),
85+
sa.Column("category", sa.String(length=255), nullable=False),
86+
sa.Column("key", sa.String(length=255), nullable=False),
87+
sa.Column("value", sa.Text(), nullable=False),
88+
sa.PrimaryKeyConstraint("id"),
89+
sa.UniqueConstraint("category", "key"),
7390
)
74-
op.create_table('product_context_history',
75-
sa.Column('id', sa.Integer(), nullable=False),
76-
sa.Column('timestamp', sa.DateTime(), nullable=False),
77-
sa.Column('version', sa.Integer(), nullable=False),
78-
sa.Column('content', sa.Text(), nullable=False),
79-
sa.Column('change_source', sa.String(length=255), nullable=True),
80-
sa.PrimaryKeyConstraint('id')
91+
op.create_table(
92+
"decisions",
93+
sa.Column("id", sa.Integer(), nullable=False),
94+
sa.Column("timestamp", sa.DateTime(), nullable=False),
95+
sa.Column("summary", sa.Text(), nullable=False),
96+
sa.Column("rationale", sa.Text(), nullable=True),
97+
sa.Column("implementation_details", sa.Text(), nullable=True),
98+
sa.Column("tags", sa.Text(), nullable=True),
99+
sa.PrimaryKeyConstraint("id"),
81100
)
82-
op.create_table('progress_entries',
83-
sa.Column('id', sa.Integer(), nullable=False),
84-
sa.Column('timestamp', sa.DateTime(), nullable=False),
85-
sa.Column('status', sa.String(length=50), nullable=False),
86-
sa.Column('description', sa.Text(), nullable=False),
87-
sa.Column('parent_id', sa.Integer(), nullable=True),
88-
sa.ForeignKeyConstraint(['parent_id'], ['progress_entries.id'], ondelete='SET NULL'),
89-
sa.PrimaryKeyConstraint('id')
101+
op.create_table(
102+
"product_context",
103+
sa.Column("id", sa.Integer(), nullable=False),
104+
sa.Column("content", sa.Text(), nullable=False),
105+
sa.PrimaryKeyConstraint("id"),
90106
)
91-
op.create_table('system_patterns',
92-
sa.Column('id', sa.Integer(), nullable=False),
93-
sa.Column('timestamp', sa.DateTime(), nullable=False),
94-
sa.Column('name', sa.String(length=255), nullable=False),
95-
sa.Column('description', sa.Text(), nullable=True),
96-
sa.Column('tags', sa.Text(), nullable=True),
97-
sa.PrimaryKeyConstraint('id'),
98-
sa.UniqueConstraint('name')
107+
op.create_table(
108+
"product_context_history",
109+
sa.Column("id", sa.Integer(), nullable=False),
110+
sa.Column("timestamp", sa.DateTime(), nullable=False),
111+
sa.Column("version", sa.Integer(), nullable=False),
112+
sa.Column("content", sa.Text(), nullable=False),
113+
sa.Column("change_source", sa.String(length=255), nullable=True),
114+
sa.PrimaryKeyConstraint("id"),
99115
)
100-
116+
op.create_table(
117+
"progress_entries",
118+
sa.Column("id", sa.Integer(), nullable=False),
119+
sa.Column("timestamp", sa.DateTime(), nullable=False),
120+
sa.Column("status", sa.String(length=50), nullable=False),
121+
sa.Column("description", sa.Text(), nullable=False),
122+
sa.Column("parent_id", sa.Integer(), nullable=True),
123+
sa.ForeignKeyConstraint(
124+
["parent_id"], ["progress_entries.id"], ondelete="SET NULL"
125+
),
126+
sa.PrimaryKeyConstraint("id"),
127+
)
128+
op.create_table(
129+
"system_patterns",
130+
sa.Column("id", sa.Integer(), nullable=False),
131+
sa.Column("timestamp", sa.DateTime(), nullable=False),
132+
sa.Column("name", sa.String(length=255), nullable=False),
133+
sa.Column("description", sa.Text(), nullable=True),
134+
sa.Column("tags", sa.Text(), nullable=True),
135+
sa.PrimaryKeyConstraint("id"),
136+
sa.UniqueConstraint("name"),
137+
)
138+
101139
# Seed initial data
102140
op.execute("INSERT INTO product_context (id, content) VALUES (1, '{}')")
103141
op.execute("INSERT INTO active_context (id, content) VALUES (1, '{}')")
@@ -106,17 +144,17 @@ def upgrade() -> None:
106144

107145
def downgrade() -> None:
108146
# ### commands auto-generated by Alembic - please adjust! ###
109-
op.drop_table('system_patterns')
110-
op.drop_table('progress_entries')
111-
op.drop_table('product_context_history')
112-
op.drop_table('product_context')
113-
op.drop_table('decisions')
114-
op.drop_table('custom_data')
115-
op.drop_index(op.f('ix_context_links_target_item_type'), table_name='context_links')
116-
op.drop_index(op.f('ix_context_links_target_item_id'), table_name='context_links')
117-
op.drop_index(op.f('ix_context_links_source_item_type'), table_name='context_links')
118-
op.drop_index(op.f('ix_context_links_source_item_id'), table_name='context_links')
119-
op.drop_table('context_links')
120-
op.drop_table('active_context_history')
121-
op.drop_table('active_context')
147+
op.drop_table("system_patterns")
148+
op.drop_table("progress_entries")
149+
op.drop_table("product_context_history")
150+
op.drop_table("product_context")
151+
op.drop_table("decisions")
152+
op.drop_table("custom_data")
153+
op.drop_index(op.f("ix_context_links_target_item_type"), table_name="context_links")
154+
op.drop_index(op.f("ix_context_links_target_item_id"), table_name="context_links")
155+
op.drop_index(op.f("ix_context_links_source_item_type"), table_name="context_links")
156+
op.drop_index(op.f("ix_context_links_source_item_id"), table_name="context_links")
157+
op.drop_table("context_links")
158+
op.drop_table("active_context_history")
159+
op.drop_table("active_context")
122160
# ### end Alembic commands ###

src/flowerpower/cfg/adapter.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,14 @@ def from_adapters(
7676
opentelemetry_cfg: OpenTelemetryConfig,
7777
) -> "AdapterConfig":
7878
return cls(
79-
hamilton_tracker=HamiltonTrackerConfig.from_dict(
80-
{
81-
**project_hamilton_tracker_cfg.to_dict(),
82-
**pipeline_hamilton_tracker_cfg.to_dict(),
83-
}
84-
),
85-
mlflow=MLFlowConfig.from_dict(
86-
{
87-
**project_mlflow_cfg.to_dict(),
88-
**pipeline_mlflow_cfg.to_dict(),
89-
}
90-
),
79+
hamilton_tracker=HamiltonTrackerConfig.from_dict({
80+
**project_hamilton_tracker_cfg.to_dict(),
81+
**pipeline_hamilton_tracker_cfg.to_dict(),
82+
}),
83+
mlflow=MLFlowConfig.from_dict({
84+
**project_mlflow_cfg.to_dict(),
85+
**pipeline_mlflow_cfg.to_dict(),
86+
}),
9187
ray=ray_cfg
9288
if isinstance(ray_cfg, RayConfig)
9389
else RayConfig.from_dict(ray_cfg.to_dict()),

src/flowerpower/fs/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
from .base import DirFileSystem, get_filesystem # noqa: E402
1515
from .storage_options import AwsStorageOptions # noqa: E402
1616
from .storage_options import AzureStorageOptions # noqa: E402
17+
from .storage_options import BaseStorageOptions # noqa: E402
1718
from .storage_options import GcsStorageOptions # noqa: E402
1819
from .storage_options import GitHubStorageOptions # noqa: E402
19-
from .storage_options import (BaseStorageOptions, # noqa: E402
20-
GitLabStorageOptions, StorageOptions)
20+
from .storage_options import GitLabStorageOptions, StorageOptions
2121

2222

2323
def get_storage_options_and_fs(

src/flowerpower/job_queue/rq/manager.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import uuid
1313
from typing import Any, Callable
1414

15-
1615
import duration_parser
1716
from cron_descriptor import get_description
1817
from humanize import precisedelta
@@ -24,12 +23,12 @@
2423
from rq.worker_pool import WorkerPool
2524
from rq_scheduler import Scheduler
2625

26+
from ...cfg.pipeline.run import RetryConfig
2727
from ...fs import AbstractFileSystem
28+
from ...pipeline.manager import PipelineManager
2829
from ...utils.logging import setup_logging
2930
from ..base import BaseJobQueueManager
3031
from .setup import RQBackend
31-
from ...cfg.pipeline.run import RetryConfig
32-
from ...pipeline.manager import PipelineManager
3332

3433
setup_logging()
3534

@@ -77,9 +76,7 @@ def __init__(
7776
fs: AbstractFileSystem | None = None,
7877
pipelines_dir: str | None = None,
7978
log_level: str | None = None,
80-
8179
):
82-
8380
"""Initialize the RQ scheduler backend.
8481
8582
Args:
@@ -187,7 +184,9 @@ def run_pipeline_sync(
187184
"log_level": log_level,
188185
"retry": retry,
189186
}
190-
pipeline_run_args = {k: v for k, v in pipeline_run_args.items() if v is not None}
187+
pipeline_run_args = {
188+
k: v for k, v in pipeline_run_args.items() if v is not None
189+
}
191190

192191
return self._run_rq_job_sync(
193192
func=run_func,
@@ -236,7 +235,9 @@ def enqueue_pipeline(
236235
"log_level": log_level,
237236
"retry": retry,
238237
}
239-
pipeline_run_args = {k: v for k, v in pipeline_run_args.items() if v is not None}
238+
pipeline_run_args = {
239+
k: v for k, v in pipeline_run_args.items() if v is not None
240+
}
240241

241242
return self._enqueue_rq_job(
242243
func=run_func,
@@ -290,7 +291,9 @@ def schedule_pipeline(
290291
"log_level": log_level,
291292
"retry": retry,
292293
}
293-
pipeline_run_args = {k: v for k, v in pipeline_run_args.items() if v is not None}
294+
pipeline_run_args = {
295+
k: v for k, v in pipeline_run_args.items() if v is not None
296+
}
294297

295298
return self._schedule_rq_job(
296299
func=run_func,
@@ -304,7 +307,6 @@ def schedule_pipeline(
304307
**kwargs,
305308
)
306309

307-
308310
def _setup_backend(self) -> None:
309311
"""Set up the Redis backend for the scheduler.
310312

0 commit comments

Comments
 (0)