Skip to content

Commit 60be104

Browse files
committed
chore: add ruff and mypy configuration with auto-fixes
1 parent f0259c1 commit 60be104

15 files changed

Lines changed: 466 additions & 261 deletions

File tree

‎backend/app/api.py‎

Lines changed: 215 additions & 63 deletions
Large diffs are not rendered by default.

‎backend/app/core/auth.py‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from datetime import datetime, timedelta
2-
from typing import Optional
3-
from jose import JWTError, jwt
4-
from passlib.context import CryptContext
2+
53
from fastapi import Depends, HTTPException, status
64
from fastapi.security import OAuth2PasswordBearer
5+
from jose import JWTError, jwt
6+
from passlib.context import CryptContext
77
from sqlalchemy.orm import Session
88

99
from .config import settings
@@ -24,42 +24,39 @@ def get_password_hash(password: str) -> str:
2424
return pwd_context.hash(password)
2525

2626

27-
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
27+
def create_access_token(data: dict, expires_delta: timedelta | None = None):
2828
"""Create JWT access token"""
2929
to_encode = data.copy()
30-
30+
3131
if expires_delta:
3232
expire = datetime.utcnow() + expires_delta
3333
else:
3434
expire = datetime.utcnow() + timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
35-
35+
3636
to_encode.update({"exp": expire})
3737
encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM)
38-
38+
3939
return encoded_jwt
4040

4141

42-
def get_current_user(
43-
token: str = Depends(oauth2_scheme),
44-
db: Session = Depends(get_db)
45-
) -> User:
42+
def get_current_user(token: str = Depends(oauth2_scheme), db: Session = Depends(get_db)) -> User:
4643
"""Get current authenticated user from token"""
4744
credentials_exception = HTTPException(
4845
status_code=status.HTTP_401_UNAUTHORIZED,
4946
detail="Could not validate credentials",
5047
headers={"WWW-Authenticate": "Bearer"},
5148
)
52-
49+
5350
try:
5451
payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM])
5552
user_id: str = payload.get("sub")
5653
if user_id is None:
5754
raise credentials_exception
5855
except JWTError:
5956
raise credentials_exception
60-
57+
6158
user = db.query(User).filter(User.id == user_id).first()
6259
if user is None:
6360
raise credentials_exception
64-
61+
6562
return user

‎backend/app/core/config.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
from pydantic_settings import BaseSettings
2-
from typing import Optional
32

43

54
class Settings(BaseSettings):
65
# Database
76
DATABASE_URL: str = "postgresql://postgres:postgres@localhost:5432/macrobuilder"
8-
7+
98
# Redis
109
REDIS_URL: str = "redis://localhost:6379/0"
11-
10+
1211
# Auth
1312
SECRET_KEY: str = "change-this-secret-key-in-production"
1413
ALGORITHM: str = "HS256"
1514
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
16-
15+
1716
# File storage
1817
UPLOAD_DIR: str = "uploads"
1918
MAX_FILE_SIZE: int = 50 * 1024 * 1024 # 50MB
2019
FILE_EXPIRATION_HOURS: int = 24
21-
20+
2221
# CORS
2322
CORS_ORIGINS: list = ["http://localhost:3000", "http://localhost:5173"]
24-
23+
2524
# Celery
2625
CELERY_BROKER_URL: str = "redis://localhost:6379/0"
2726
CELERY_RESULT_BACKEND: str = "redis://localhost:6379/0"
28-
27+
2928
class Config:
3029
env_file = ".env"
3130
case_sensitive = True

‎backend/app/core/database.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from sqlalchemy import create_engine
22
from sqlalchemy.ext.declarative import declarative_base
33
from sqlalchemy.orm import sessionmaker
4+
45
from .config import settings
56

67
engine = create_engine(settings.DATABASE_URL)

‎backend/app/core/models.py‎

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from sqlalchemy import Column, String, Boolean, DateTime, Integer, ForeignKey, Text, JSON
1+
import uuid
2+
from datetime import datetime
3+
4+
from sqlalchemy import JSON, Boolean, Column, DateTime, ForeignKey, Integer, String, Text
25
from sqlalchemy.dialects.postgresql import UUID
36
from sqlalchemy.orm import relationship
4-
from datetime import datetime
5-
import uuid
67

78
from .database import Base
89

@@ -14,7 +15,7 @@ class Company(Base):
1415
name = Column(String(255), nullable=False)
1516
plan = Column(String(50), default="free") # free, pro, enterprise
1617
created_at = Column(DateTime, default=datetime.utcnow)
17-
18+
1819
# Relationships
1920
users = relationship("Membership", back_populates="company")
2021
workflows = relationship("Workflow", back_populates="company")
@@ -28,7 +29,7 @@ class User(Base):
2829
password_hash = Column(Text, nullable=False)
2930
is_active = Column(Boolean, default=True)
3031
created_at = Column(DateTime, default=datetime.utcnow)
31-
32+
3233
# Relationships
3334
memberships = relationship("Membership", back_populates="user")
3435

@@ -38,7 +39,7 @@ class Role(Base):
3839

3940
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
4041
name = Column(String(50), unique=True, nullable=False) # owner, admin, editor, runner, viewer
41-
42+
4243
# Relationships
4344
memberships = relationship("Membership", back_populates="role")
4445

@@ -48,10 +49,12 @@ class Membership(Base):
4849

4950
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
5051
user_id = Column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
51-
company_id = Column(UUID(as_uuid=True), ForeignKey("companies.id", ondelete="CASCADE"), nullable=False)
52+
company_id = Column(
53+
UUID(as_uuid=True), ForeignKey("companies.id", ondelete="CASCADE"), nullable=False
54+
)
5255
role_id = Column(UUID(as_uuid=True), ForeignKey("roles.id"), nullable=False)
5356
created_at = Column(DateTime, default=datetime.utcnow)
54-
57+
5558
# Relationships
5659
user = relationship("User", back_populates="memberships")
5760
company = relationship("Company", back_populates="users")
@@ -62,28 +65,40 @@ class Workflow(Base):
6265
__tablename__ = "workflows"
6366

6467
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
65-
company_id = Column(UUID(as_uuid=True), ForeignKey("companies.id", ondelete="CASCADE"), nullable=False, index=True)
68+
company_id = Column(
69+
UUID(as_uuid=True),
70+
ForeignKey("companies.id", ondelete="CASCADE"),
71+
nullable=False,
72+
index=True,
73+
)
6674
name = Column(String(255), nullable=False)
6775
description = Column(Text)
6876
is_active = Column(Boolean, default=True)
6977
created_at = Column(DateTime, default=datetime.utcnow)
7078
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
71-
79+
7280
# Relationships
7381
company = relationship("Company", back_populates="workflows")
74-
versions = relationship("WorkflowVersion", back_populates="workflow", cascade="all, delete-orphan")
82+
versions = relationship(
83+
"WorkflowVersion", back_populates="workflow", cascade="all, delete-orphan"
84+
)
7585

7686

7787
class WorkflowVersion(Base):
7888
__tablename__ = "workflow_versions"
7989

8090
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
81-
workflow_id = Column(UUID(as_uuid=True), ForeignKey("workflows.id", ondelete="CASCADE"), nullable=False, index=True)
91+
workflow_id = Column(
92+
UUID(as_uuid=True),
93+
ForeignKey("workflows.id", ondelete="CASCADE"),
94+
nullable=False,
95+
index=True,
96+
)
8297
version_number = Column(Integer, nullable=False)
8398
rules_json = Column(JSON, nullable=False) # JSONB in PostgreSQL
8499
created_at = Column(DateTime, default=datetime.utcnow)
85100
created_by = Column(UUID(as_uuid=True), ForeignKey("users.id"))
86-
101+
87102
# Relationships
88103
workflow = relationship("Workflow", back_populates="versions")
89104
executions = relationship("Execution", back_populates="workflow_version")
@@ -93,13 +108,20 @@ class Execution(Base):
93108
__tablename__ = "executions"
94109

95110
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
96-
company_id = Column(UUID(as_uuid=True), ForeignKey("companies.id", ondelete="CASCADE"), nullable=False, index=True)
97-
workflow_version_id = Column(UUID(as_uuid=True), ForeignKey("workflow_versions.id"), nullable=False)
111+
company_id = Column(
112+
UUID(as_uuid=True),
113+
ForeignKey("companies.id", ondelete="CASCADE"),
114+
nullable=False,
115+
index=True,
116+
)
117+
workflow_version_id = Column(
118+
UUID(as_uuid=True), ForeignKey("workflow_versions.id"), nullable=False
119+
)
98120
status = Column(String(50), default="pending") # pending, running, success, failed
99121
started_at = Column(DateTime)
100122
finished_at = Column(DateTime)
101123
error_message = Column(Text)
102-
124+
103125
# Relationships
104126
workflow_version = relationship("WorkflowVersion", back_populates="executions")
105127
logs = relationship("ExecutionLog", back_populates="execution", cascade="all, delete-orphan")
@@ -110,13 +132,18 @@ class ExecutionLog(Base):
110132
__tablename__ = "execution_logs"
111133

112134
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
113-
execution_id = Column(UUID(as_uuid=True), ForeignKey("executions.id", ondelete="CASCADE"), nullable=False, index=True)
135+
execution_id = Column(
136+
UUID(as_uuid=True),
137+
ForeignKey("executions.id", ondelete="CASCADE"),
138+
nullable=False,
139+
index=True,
140+
)
114141
step_index = Column(Integer, nullable=False)
115142
step_type = Column(String(50), nullable=False)
116143
message = Column(Text, nullable=False)
117144
affected_rows = Column(Integer, default=0)
118145
created_at = Column(DateTime, default=datetime.utcnow)
119-
146+
120147
# Relationships
121148
execution = relationship("Execution", back_populates="logs")
122149

@@ -125,7 +152,12 @@ class File(Base):
125152
__tablename__ = "files"
126153

127154
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
128-
company_id = Column(UUID(as_uuid=True), ForeignKey("companies.id", ondelete="CASCADE"), nullable=False, index=True)
155+
company_id = Column(
156+
UUID(as_uuid=True),
157+
ForeignKey("companies.id", ondelete="CASCADE"),
158+
nullable=False,
159+
index=True,
160+
)
129161
original_filename = Column(String(255), nullable=False)
130162
storage_path = Column(Text, nullable=False)
131163
file_type = Column(String(50), nullable=False) # input, output
@@ -136,9 +168,13 @@ class File(Base):
136168
class ExecutionFile(Base):
137169
__tablename__ = "execution_files"
138170

139-
execution_id = Column(UUID(as_uuid=True), ForeignKey("executions.id", ondelete="CASCADE"), primary_key=True)
140-
file_id = Column(UUID(as_uuid=True), ForeignKey("files.id", ondelete="CASCADE"), primary_key=True)
171+
execution_id = Column(
172+
UUID(as_uuid=True), ForeignKey("executions.id", ondelete="CASCADE"), primary_key=True
173+
)
174+
file_id = Column(
175+
UUID(as_uuid=True), ForeignKey("files.id", ondelete="CASCADE"), primary_key=True
176+
)
141177
role = Column(String(50), nullable=False) # input, output
142-
178+
143179
# Relationships
144180
execution = relationship("Execution", back_populates="files")

0 commit comments

Comments
 (0)