| 
 | 1 | +from pathlib import Path  | 
 | 2 | + | 
 | 3 | +import click  | 
 | 4 | + | 
 | 5 | +from llama_dev.utils import (  | 
 | 6 | +    BumpType,  | 
 | 7 | +    bump_version,  | 
 | 8 | +    load_pyproject,  | 
 | 9 | +    update_pyproject_version,  | 
 | 10 | +)  | 
 | 11 | + | 
 | 12 | + | 
 | 13 | +def _replace_core_dependency(project_path: Path, old_dep: str, new_dep: str):  | 
 | 14 | +    pyproject_path = project_path / "pyproject.toml"  | 
 | 15 | +    # Read the file content  | 
 | 16 | +    with open(pyproject_path, "r") as f:  | 
 | 17 | +        content = f.read()  | 
 | 18 | + | 
 | 19 | +    # Replace the old dependency string  | 
 | 20 | +    new_content = content.replace(old_dep, new_dep)  | 
 | 21 | + | 
 | 22 | +    # Write the updated content back  | 
 | 23 | +    with open(pyproject_path, "w") as f:  | 
 | 24 | +        f.write(new_content)  | 
 | 25 | + | 
 | 26 | + | 
 | 27 | +@click.command(  | 
 | 28 | +    short_help="Bump the versions to begin a llama_index umbrella package release"  | 
 | 29 | +)  | 
 | 30 | +@click.option(  | 
 | 31 | +    "--version-type",  | 
 | 32 | +    type=click.Choice([t.value for t in BumpType], case_sensitive=False),  | 
 | 33 | +    default=BumpType.PATCH.value,  | 
 | 34 | +    help="Type of version bump to perform (default: patch)",  | 
 | 35 | +)  | 
 | 36 | +@click.option(  | 
 | 37 | +    "--dry-run",  | 
 | 38 | +    is_flag=True,  | 
 | 39 | +    help="Show what would be done without making changes",  | 
 | 40 | +)  | 
 | 41 | +@click.pass_obj  | 
 | 42 | +def prepare(  | 
 | 43 | +    obj: dict,  | 
 | 44 | +    version_type: str,  | 
 | 45 | +    dry_run: bool,  | 
 | 46 | +):  | 
 | 47 | +    """Bump the version numbers to initiate the llama_index umbrella package release."""  | 
 | 48 | +    console = obj["console"]  | 
 | 49 | +    repo_root = obj["repo_root"]  | 
 | 50 | +    bump_enum = BumpType(version_type)  | 
 | 51 | + | 
 | 52 | +    root_package_data = load_pyproject(repo_root)  | 
 | 53 | +    current_version = root_package_data["project"]["version"]  | 
 | 54 | +    new_version = bump_version(current_version, bump_enum)  | 
 | 55 | +    new_dep_string = (  | 
 | 56 | +        f"llama-index-core>={new_version},<{bump_version(new_version, BumpType.MINOR)}"  | 
 | 57 | +    )  | 
 | 58 | + | 
 | 59 | +    if dry_run:  | 
 | 60 | +        console.print(f"Would bump llama_index from {current_version} to {new_version}")  | 
 | 61 | +        console.print(f"llama_index will depend on '{new_dep_string}'")  | 
 | 62 | +    else:  | 
 | 63 | +        # Update llama-index version number  | 
 | 64 | +        update_pyproject_version(repo_root, new_version)  | 
 | 65 | +        # Update llama-index-core version number  | 
 | 66 | +        update_pyproject_version(repo_root / "llama-index-core", new_version)  | 
 | 67 | +        # Update llama-index-core dependency version  | 
 | 68 | +        for dep in root_package_data["project"]["dependencies"]:  | 
 | 69 | +            if dep.startswith("llama-index-core"):  | 
 | 70 | +                _replace_core_dependency(repo_root, dep, new_dep_string)  | 
 | 71 | +                break  | 
0 commit comments