Skip to content

chore: rename to input_repo / output_repo #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions flask_to_fastapi_migration/input_repo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@
authors = ["Author A", "Author B", "Author C"]
categories = ["Fiction", "Non-Fiction", "Biography"]


# Home Page
@app.route("/")
def home():
return render_template("index.html")


# Books Page
@app.route("/books", methods=["GET"])
def get_books():
return render_template("books.html", books=books)


@app.route("/books", methods=["POST"])
def add_book():
data = request.json
books.append(data)
return jsonify(data), 201


@app.route("/books/<int:book_id>", methods=["PUT"])
def update_book(book_id):
data = request.json
Expand All @@ -36,33 +40,39 @@ def update_book(book_id):
return jsonify(book)
return jsonify({"error": "Book not found"}), 404


@app.route("/books/<int:book_id>", methods=["DELETE"])
def delete_book(book_id):
global books
books = [book for book in books if book["id"] != book_id]
return jsonify({"message": "Book deleted"})


# Authors Page
@app.route("/authors", methods=["GET"])
def get_authors():
return render_template("authors.html", authors=authors)


@app.route("/authors", methods=["POST"])
def add_author():
data = request.json
authors.append(data["name"])
return jsonify({"name": data["name"]}), 201


# Categories Page
@app.route("/categories", methods=["GET"])
def get_categories():
return render_template("categories.html", categories=categories)


@app.route("/categories", methods=["POST"])
def add_category():
data = request.json
categories.append(data["name"])
return jsonify({"name": data["name"]}), 201


if __name__ == "__main__":
app.run(debug=True)
28 changes: 14 additions & 14 deletions freezegun_to_timemachine_migration/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from codegen import Codebase

codebase = Codebase.from_repo("getmoto/moto", commit="786a8ada7ed0c7f9d8b04d49f24596865e4b7901")

print("🚀 Starting FreezeGun to TimeMachine conversion...")
Expand All @@ -9,32 +10,31 @@
print(f"📝 Processing: {file.filepath}")
# Update imports
for imp in file.imports:
if imp.symbol_name and 'freezegun' in imp.source:
if imp.name == 'freeze_time':
if imp.symbol_name and "freezegun" in imp.source:
if imp.name == "freeze_time":
# required due to Codegen limitations
imp.edit('from time_machine import travel')
imp.edit("from time_machine import travel")
else:
imp.set_import_module('time_machine')
imp.set_import_module("time_machine")
# Find all function calls in the file
for fcall in file.function_calls:
# Skip if not a freeze_time call
if 'freeze_time' not in fcall.source:
if "freeze_time" not in fcall.source:
continue
# Get original source and prepare new source
new_source = fcall.source
# Add tick parameter if not present
if not fcall.get_arg_by_parameter_name('tick'):
if new_source.endswith(')'):
if not fcall.get_arg_by_parameter_name("tick"):
if new_source.endswith(")"):
new_source = new_source[:-1]
if not new_source.endswith('('):
new_source += ','
new_source += ' tick=False)'
if not new_source.endswith("("):
new_source += ","
new_source += " tick=False)"
# Replace freeze_time with travel
if '.' in new_source:
new_source = new_source.replace(
'freeze_time', 'travel').replace('freezegun', 'time_machine')
if "." in new_source:
new_source = new_source.replace("freeze_time", "travel").replace("freezegun", "time_machine")
else:
new_source = 'travel' + new_source[len('freeze_time'):]
new_source = "travel" + new_source[len("freeze_time") :]
# Make single edit with complete changes
fcall.edit(new_source)
codebase.commit()
Expand Down
8 changes: 2 additions & 6 deletions generate_training_data/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,8 @@ def run(codebase: Codebase):
# Update metadata
training_data["metadata"]["total_processed"] = len(training_data["functions"])
if training_data["functions"]:
training_data["metadata"]["avg_dependencies"] = sum(
len(f["dependencies"]) for f in training_data["functions"]
) / len(training_data["functions"])
training_data["metadata"]["avg_usages"] = sum(
len(f["usages"]) for f in training_data["functions"]
) / len(training_data["functions"])
training_data["metadata"]["avg_dependencies"] = sum(len(f["dependencies"]) for f in training_data["functions"]) / len(training_data["functions"])
training_data["metadata"]["avg_usages"] = sum(len(f["usages"]) for f in training_data["functions"]) / len(training_data["functions"])

# Print stats
print(f"Processed {training_data['metadata']['total_processed']} functions")
Expand Down
14 changes: 13 additions & 1 deletion sqlalchemy_1.6_to_2.0/input_repo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
app = FastAPI()
models.Base.metadata.create_all(bind=engine)


# Dependency for the database session
def get_db():
db = SessionLocal()
Expand All @@ -18,15 +19,18 @@ def get_db():
finally:
db.close()


# Utility Functions
def get_book_or_404(book_id: int, db: Session):
book = db.query(models.Book).filter(models.Book.id == book_id).first()
if not book:
raise HTTPException(status_code=404, detail="Book not found")
return book


# CRUD Operations


@app.post("/books/", response_model=schemas.Book)
def create_book(book: schemas.BookCreate, db: Session = Depends(get_db)):
db_book = models.Book(**book.dict())
Expand All @@ -35,18 +39,21 @@ def create_book(book: schemas.BookCreate, db: Session = Depends(get_db)):
db.refresh(db_book)
return db_book


@app.get("/books/", response_model=List[schemas.Book])
def read_books(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
books = db.query(models.Book).offset(skip).limit(limit).all()
return books


@app.get("/books/{book_id}", response_model=schemas.Book)
def read_book(book_id: int, db: Session = Depends(get_db)):
book = db.query(models.Book).filter(models.Book.id == book_id).first()
if book is None:
raise HTTPException(status_code=404, detail="Book not found")
return book


@app.put("/books/{book_id}", response_model=schemas.Book)
def update_book(book_id: int, book: schemas.BookCreate, db: Session = Depends(get_db)):
db_book = db.query(models.Book).filter(models.Book.id == book_id).first()
Expand All @@ -58,6 +65,7 @@ def update_book(book_id: int, book: schemas.BookCreate, db: Session = Depends(ge
db.refresh(db_book)
return db_book


@app.delete("/books/{book_id}", response_model=schemas.Book)
def delete_book(book_id: int, db: Session = Depends(get_db)):
db_book = db.query(models.Book).filter(models.Book.id == book_id).first()
Expand All @@ -67,6 +75,7 @@ def delete_book(book_id: int, db: Session = Depends(get_db)):
db.commit()
return db_book


@app.post("/publishers/", response_model=schemas.Publisher)
def create_publisher(publisher: schemas.PublisherCreate, db: Session = Depends(get_db)):
db_publisher = models.Publisher(**publisher.dict())
Expand All @@ -75,18 +84,21 @@ def create_publisher(publisher: schemas.PublisherCreate, db: Session = Depends(g
db.refresh(db_publisher)
return db_publisher


@app.get("/publishers/", response_model=List[schemas.Publisher])
def read_publishers(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
publishers = db.query(models.Publisher).offset(skip).limit(limit).all()
return publishers


@app.get("/publishers/{publisher_id}", response_model=schemas.Publisher)
def read_publisher(publisher_id: int, db: Session = Depends(get_db)):
publisher = db.query(models.Publisher).filter(models.Publisher.id == publisher_id).first()
if not publisher:
raise HTTPException(status_code=404, detail="Publisher not found")
return publisher


@app.put("/publishers/{publisher_id}", response_model=schemas.Publisher)
def update_publisher(publisher_id: int, publisher: schemas.PublisherCreate, db: Session = Depends(get_db)):
db_publisher = db.query(models.Publisher).filter(models.Publisher.id == publisher_id).first()
Expand All @@ -98,6 +110,7 @@ def update_publisher(publisher_id: int, publisher: schemas.PublisherCreate, db:
db.refresh(db_publisher)
return db_publisher


@app.delete("/publishers/{publisher_id}", response_model=schemas.Publisher)
def delete_publisher(publisher_id: int, db: Session = Depends(get_db)):
db_publisher = db.query(models.Publisher).filter(models.Publisher.id == publisher_id).first()
Expand All @@ -106,4 +119,3 @@ def delete_publisher(publisher_id: int, db: Session = Depends(get_db)):
db.delete(db_publisher)
db.commit()
return db_publisher

1 change: 1 addition & 0 deletions sqlalchemy_1.6_to_2.0/input_repo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from sqlalchemy.orm import relationship
from database import Base


class Publisher(Base):
__tablename__ = "publishers"

Expand Down
6 changes: 6 additions & 0 deletions sqlalchemy_1.6_to_2.0/input_repo/schemas.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
from pydantic import BaseModel
from typing import List, Optional


class PublisherBase(BaseModel):
name: str


class PublisherCreate(PublisherBase):
pass


class Publisher(PublisherBase):
id: int
books: List["Book"] = []

class Config:
orm_mode = True


class BookBase(BaseModel):
title: str
author: str
description: str
publisher_id: Optional[int]


class BookCreate(BookBase):
pass


class Book(BookBase):
id: int
publisher: Optional[Publisher]
Expand Down
13 changes: 12 additions & 1 deletion sqlalchemy_1.6_to_2.0/output_repo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
app = FastAPI()
models.Base.metadata.create_all(bind=engine)


# Dependency for the database session
def get_db():
db = SessionLocal()
Expand All @@ -18,8 +19,10 @@ def get_db():
finally:
db.close()


# CRUD Operations


@app.post("/books/", response_model=schemas.Book)
def create_book(book: schemas.BookCreate, db: Session = Depends(get_db)):
db_book = models.Book(**book.dict())
Expand All @@ -28,18 +31,21 @@ def create_book(book: schemas.BookCreate, db: Session = Depends(get_db)):
db.refresh(db_book)
return db_book


@app.get("/books/", response_model=List[schemas.Book])
def read_books(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
books = db.query()(models.Book).offset(skip).limit(limit).scalars().all()
return books


@app.get("/books/{book_id}", response_model=schemas.Book)
def read_book(book_id: int, db: Session = Depends(get_db)):
book = db.query()(models.Book).where(models.Book.id == book_id).first()
if book is None:
raise HTTPException(status_code=404, detail="Book not found")
return book


@app.put("/books/{book_id}", response_model=schemas.Book)
def update_book(book_id: int, book: schemas.BookCreate, db: Session = Depends(get_db)):
db_book = db.query()(models.Book).where(models.Book.id == book_id).first()
Expand All @@ -51,6 +57,7 @@ def update_book(book_id: int, book: schemas.BookCreate, db: Session = Depends(ge
db.refresh(db_book)
return db_book


@app.delete("/books/{book_id}", response_model=schemas.Book)
def delete_book(book_id: int, db: Session = Depends(get_db)):
db_book = db.query()(models.Book).where(models.Book.id == book_id).first()
Expand All @@ -60,6 +67,7 @@ def delete_book(book_id: int, db: Session = Depends(get_db)):
db.commit()
return db_book


@app.post("/publishers/", response_model=schemas.Publisher)
def create_publisher(publisher: schemas.PublisherCreate, db: Session = Depends(get_db)):
db_publisher = models.Publisher(**publisher.dict())
Expand All @@ -68,18 +76,21 @@ def create_publisher(publisher: schemas.PublisherCreate, db: Session = Depends(g
db.refresh(db_publisher)
return db_publisher


@app.get("/publishers/", response_model=List[schemas.Publisher])
def read_publishers(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
publishers = db.query()(models.Publisher).offset(skip).limit(limit).scalars().all()
return publishers


@app.get("/publishers/{publisher_id}", response_model=schemas.Publisher)
def read_publisher(publisher_id: int, db: Session = Depends(get_db)):
publisher = db.query()(models.Publisher).where(models.Publisher.id == publisher_id).first()
if not publisher:
raise HTTPException(status_code=404, detail="Publisher not found")
return publisher


@app.put("/publishers/{publisher_id}", response_model=schemas.Publisher)
def update_publisher(publisher_id: int, publisher: schemas.PublisherCreate, db: Session = Depends(get_db)):
db_publisher = db.query()(models.Publisher).where(models.Publisher.id == publisher_id).first()
Expand All @@ -91,6 +102,7 @@ def update_publisher(publisher_id: int, publisher: schemas.PublisherCreate, db:
db.refresh(db_publisher)
return db_publisher


@app.delete("/publishers/{publisher_id}", response_model=schemas.Publisher)
def delete_publisher(publisher_id: int, db: Session = Depends(get_db)):
db_publisher = db.query()(models.Publisher).where(models.Publisher.id == publisher_id).first()
Expand All @@ -99,4 +111,3 @@ def delete_publisher(publisher_id: int, db: Session = Depends(get_db)):
db.delete(db_publisher)
db.commit()
return db_publisher

Loading
Loading