Skip to content
Merged
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
17 changes: 15 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
default_language_version:
python: python3.12
fail_fast: true

ci:
# Define the common exclude pattern as an anchor
exclude_patterns: &exclude_patterns |
(?x)(
.*/input_repo/.*|
.*/output_repo/.*|
.*/repositories/.*
)

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3
Expand All @@ -9,10 +19,12 @@ repos:
- id: ruff
types_or: [python, jupyter, pyi]
args: [--fix]
exclude: *exclude_patterns

# Run the formatter.
- id: ruff-format
types_or: [python, jupyter, pyi]
exclude: *exclude_patterns

- repo: https://github.com/kynan/nbstripout
rev: 0.8.1
Expand All @@ -23,11 +35,12 @@ repos:
rev: v5.0.0
hooks:
- id: trailing-whitespace
exclude: tests/
exclude: *exclude_patterns
exclude_types: [mdx, pyi]
- id: check-yaml
exclude: *exclude_patterns
- id: end-of-file-fixer
files: .*/expected_diff.patch
exclude: *exclude_patterns
- id: check-merge-conflict

- repo: https://github.com/python-jsonschema/check-jsonschema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The migration script handles four key transformations:
# From:
from flask import Flask
app = Flask(__name__)

# To:
from fastapi import FastAPI
app = FastAPI()
Expand All @@ -23,7 +23,7 @@ The migration script handles four key transformations:
```python
# From:
@app.route("/users", methods=["POST"])

# To:
@app.post("/users")
```
Expand All @@ -39,7 +39,7 @@ The migration script handles four key transformations:
```python
# From:
return render_template("users.html", users=users)

# To:
return Jinja2Templates(directory="templates").TemplateResponse(
"users.html",
Expand Down Expand Up @@ -71,4 +71,4 @@ The script will process all Python files in the `repo-before` directory and appl
- [Full Tutorial](https://docs.codegen.com/tutorials/flask-to-fastapi)
- [Flask Documentation](https://flask.palletsprojects.com/)
- [FastAPI Documentation](https://fastapi.tiangolo.com/)
- [Codegen Documentation](https://docs.codegen.com)
- [Codegen Documentation](https://docs.codegen.com)
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ python run.py

## Contributing

Feel free to submit issues and enhancement requests!
Feel free to submit issues and enhancement requests!
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ The generated `training_data.json` follows this structure:

- [Full Tutorial](https://docs.codegen.com/tutorials/generate-training-data)
- [Code Model Pre-training](https://docs.codegen.com/concepts/code-model-training)
- [Codegen Documentation](https://docs.codegen.com)
- [Codegen Documentation](https://docs.codegen.com)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_function_context(function) -> dict:

# Add dependencies
for dep in function.dependencies:
# Hop through imports to find the root symbols ource
# Hop through imports to find the root symbols source
if isinstance(dep, Import):
dep = hop_through_imports(dep)

Expand Down 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The migration script handles five key transformations:
# From:
print "Hello, world!"
print x, y, z

# To:
print("Hello, world!")
print(x, y, z)
Expand All @@ -25,7 +25,7 @@ The migration script handles five key transformations:
from __future__ import unicode_literals
text = unicode("Hello")
prefix = u"prefix"

# To:
text = str("Hello")
prefix = "prefix"
Expand All @@ -35,7 +35,7 @@ The migration script handles five key transformations:
```python
# From:
name = raw_input("Enter your name: ")

# To:
name = input("Enter your name: ")
```
Expand All @@ -47,7 +47,7 @@ The migration script handles five key transformations:
process_data()
except ValueError, e:
print(e)

# To:
try:
process_data()
Expand All @@ -61,7 +61,7 @@ The migration script handles five key transformations:
class MyIterator:
def next(self):
return self.value

# To:
class MyIterator:
def __next__(self):
Expand Down Expand Up @@ -91,4 +91,4 @@ The script will process all Python files in the `repo-before` directory and appl
- [Full Tutorial](https://docs.codegen.com/tutorials/python2-to-python3)
- [Python 3 Documentation](https://docs.python.org/3/)
- [What's New in Python 3](https://docs.python.org/3/whatsnew/3.0.html)
- [Codegen Documentation](https://docs.codegen.com)
- [Codegen Documentation](https://docs.codegen.com)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ python run.py

## Contributing

Feel free to submit issues and enhancement requests!
Feel free to submit issues and enhancement requests!
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The migration script handles four key transformations:
```python
# From:
session.query(User).filter_by(name='john').all()

# To:
session.execute(
select(User).where(User.name == 'john')
Expand All @@ -24,7 +24,7 @@ The migration script handles four key transformations:
# From:
users = session.query(User).all()
first_user = session.query(User).first()

# To:
users = session.execute(select(User)).scalars().all()
first_user = session.execute(select(User)).scalars().first()
Expand All @@ -35,7 +35,7 @@ The migration script handles four key transformations:
# From:
class User(Base):
addresses = relationship("Address", backref="user")

# To:
class User(Base):
addresses = relationship("Address", back_populates="user", use_list=True)
Expand All @@ -51,7 +51,7 @@ The migration script handles four key transformations:
id = Column(Integer, primary_key=True)
name = Column(String)
addresses = relationship("Address")

# To:
class User(Base):
__tablename__ = "users"
Expand Down Expand Up @@ -83,4 +83,4 @@ The script will process all Python files in the `repo-before` directory and appl
- [Full Tutorial](https://docs.codegen.com/tutorials/sqlalchemy-1.6-to-2.0)
- [SQLAlchemy Documentation](https://docs.sqlalchemy.org/en/20/)
- [What's New in SQLAlchemy 2.0](https://docs.sqlalchemy.org/en/20/changelog/migration_20.html)
- [Codegen Documentation](https://docs.codegen.com)
- [Codegen Documentation](https://docs.codegen.com)
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ This guide walks you through the steps to migrate your codebase from SQLAlchemy

The migration focuses on these key updates:

1. **Import Adjustments**
Aligns your code with the updated SQLAlchemy 2.0 module structure.
1. **Import Adjustments**
Aligns your code with the updated SQLAlchemy 2.0 module structure.
[Run the Import Codemod](https://www.codegen.sh/search/6506?skillType=codemod)

2. **Relationship Updates**
Refines relationship definitions by replacing `backref` with `back_populates` for explicitness and better readability.
2. **Relationship Updates**
Refines relationship definitions by replacing `backref` with `back_populates` for explicitness and better readability.
[Run the Relationship Codemod](https://www.codegen.sh/search/6510?skillType=codemod)

3. **Query Syntax Modernization**
Updates queries to leverage the latest syntax like `select()` and `where()`, removing deprecated methods.
3. **Query Syntax Modernization**
Updates queries to leverage the latest syntax like `select()` and `where()`, removing deprecated methods.
[Run the Query Syntax Codemod](https://www.codegen.sh/search/6508?skillType=codemod)

4. **Relationship Lazy Loading**
SQLAlchemy 2.0 introduces a new `lazy` parameter for relationship definitions. Update your relationships to use the new `lazy` parameter for improved performance.
SQLAlchemy 2.0 introduces a new `lazy` parameter for relationship definitions. Update your relationships to use the new `lazy` parameter for improved performance.
[Run the Relationship Lazy Loading Codemod](https://www.codegen.sh/search/6512?skillType=codemod)

5. **Type Annotations**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The script automates the entire migration process in a few key steps:
# Before
id = Column(Integer, primary_key=True)
name = Column(String)

# After
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column()
Expand All @@ -54,7 +54,7 @@ name: Mapped[str] = mapped_column()
```python
# Before
description = Column(String, nullable=True)

# After
description: Mapped[Optional[str]] = mapped_column(nullable=True)
```
Expand All @@ -63,7 +63,7 @@ description: Mapped[Optional[str]] = mapped_column(nullable=True)
```python
# Before
addresses = relationship("Address", backref="user")

# After
addresses: Mapped[List["Address"]] = relationship(back_populates="user")
```
Expand Down Expand Up @@ -106,7 +106,7 @@ class Publisher(Base):
id: Mapped[int] = mapped_column(primary_key=True, index=True)
name: Mapped[str] = mapped_column(unique=True, index=True)
books: Mapped[List["Book"]] = relationship(
"Book",
"Book",
back_populates="publisher"
)

Expand All @@ -122,7 +122,7 @@ class Book(Base):
nullable=True
)
publisher: Mapped[Optional["Publisher"]] = relationship(
"Publisher",
"Publisher",
back_populates="books"
)
```
Expand All @@ -144,4 +144,4 @@ python run.py

## Contributing

Feel free to submit issues and enhancement requests!
Feel free to submit issues and enhancement requests!
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ The script automates the entire migration process in a few key steps:
class TestUsers(unittest.TestCase):
def setUp(self):
self.db = setup_test_db()

def test_create_user(self):
user = self.db.create_user("test")
self.assertEqual(user.name, "test")

# To:
@pytest.fixture
def db():
db = setup_test_db()
yield db

def test_create_user(db):
user = db.create_user("test")
assert user.name == "test"
Expand All @@ -37,7 +37,7 @@ The script automates the entire migration process in a few key steps:
self.assertTrue(is_valid("test"))
self.assertEqual(count_items(), 0)
self.assertRaises(ValueError, parse_id, "invalid")

# To:
def test_validation():
assert is_valid("test")
Expand All @@ -53,7 +53,7 @@ The script automates the entire migration process in a few key steps:
# From:
if __name__ == '__main__':
unittest.main()

# To:
# Remove unittest.main() and rename files to test_*.py
```
Expand All @@ -66,7 +66,7 @@ The script automates the entire migration process in a few key steps:
@classmethod
def setUpClass(cls):
cls.conn = create_db()

# To:
@pytest.fixture(scope="session")
def conn():
Expand Down Expand Up @@ -101,4 +101,4 @@ The script will process all Python test files in the `repo-before` directory and

## Contributing

Feel free to submit issues and enhancement requests!
Feel free to submit issues and enhancement requests!
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def run(codebase: Codebase):
# Convert to useSuspenseQueries if needed
if old_statements:
new_query = f"const [{', '.join(results)}] = useSuspenseQueries({{queries: [{', '.join(queries)}]}})"
print(
f"Converting useSuspenseQuery to useSuspenseQueries in {function.name}"
)
print(f"Converting useSuspenseQuery to useSuspenseQueries in {function.name}")

# Print the diff
print("\nOriginal code:")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ classifiers = [

[tool.ruff]
line-length = 200
lint.exclude = [
exclude = [
"**/input_repo/**",
"**/output_repo/**",
"**/repositories/**",
Expand Down
Loading
Loading