|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 58, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "import modal" |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": null, |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [], |
| 17 | + "source": [ |
| 18 | + "\n", |
| 19 | + "\n", |
| 20 | + "import os\n", |
| 21 | + "from codegen.configs.models.secrets import SecretsConfig\n", |
| 22 | + "from codegen.sdk.core.codebase import Codebase\n", |
| 23 | + "from codegen.shared.enums.programming_language import ProgrammingLanguage\n", |
| 24 | + "\n", |
| 25 | + "class CodebaseSnapshot(modal.Cls):\n", |
| 26 | + " codebase: Codebase\n", |
| 27 | + " repo_org: str | None = modal.parameter(default=\"codegen-sh\") \n", |
| 28 | + " repo_name: str | None = modal.parameter(default=\"codegen-sdk\")\n", |
| 29 | + " commit: str | None = modal.parameter(default=None)\n", |
| 30 | + " temp_dir: str = \"/root\"\n", |
| 31 | + "\n", |
| 32 | + "\n", |
| 33 | + " def __init__(self, *args, **kwargs):\n", |
| 34 | + " super().__init__(*args, **kwargs)\n", |
| 35 | + " \n", |
| 36 | + " @modal.enter(snap=True)\n", |
| 37 | + " def load(self):\n", |
| 38 | + " config = SecretsConfig()\n", |
| 39 | + " config.github_token = os.environ[\"GITHUB_TOKEN\"]\n", |
| 40 | + " self.codebase = Codebase.from_repo(f\"{self.repo_org}/{self.repo_name}\", commit=self.commit, language=ProgrammingLanguage.PYTHON, tmp_dir=self.temp_dir, secrets=config)\n" |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "code", |
| 45 | + "execution_count": 38, |
| 46 | + "metadata": {}, |
| 47 | + "outputs": [], |
| 48 | + "source": [ |
| 49 | + "\n", |
| 50 | + "image = modal.Image.debian_slim(python_version=\"3.13\").apt_install(\"git\").pip_install(\"fastapi[standard]\", \"codegen==0.30.1\")\n", |
| 51 | + "\n", |
| 52 | + "\n", |
| 53 | + "app = modal.App(\"snapshot-test\", image=image)\n" |
| 54 | + ] |
| 55 | + }, |
| 56 | + { |
| 57 | + "cell_type": "code", |
| 58 | + "execution_count": 25, |
| 59 | + "metadata": {}, |
| 60 | + "outputs": [], |
| 61 | + "source": [ |
| 62 | + "\n", |
| 63 | + "\n", |
| 64 | + "@app.cls(secrets=[modal.Secret.from_dotenv()], enable_memory_snapshot=True)\n", |
| 65 | + "class SubClassTest(CodebaseSnapshot):\n", |
| 66 | + " \n", |
| 67 | + "\n", |
| 68 | + "\n", |
| 69 | + " @modal.method()\n", |
| 70 | + " def files(self):\n", |
| 71 | + " return len(self.codebase.files)\n", |
| 72 | + "\n", |
| 73 | + "\n" |
| 74 | + ] |
| 75 | + }, |
| 76 | + { |
| 77 | + "cell_type": "code", |
| 78 | + "execution_count": 59, |
| 79 | + "metadata": {}, |
| 80 | + "outputs": [], |
| 81 | + "source": [ |
| 82 | + "Klass = modal.Cls.from_name(app_name=\"snapshot-test\", name=\"SubClassTest\")\n", |
| 83 | + "klass = Klass(repo_org=\"codegen-sh\", repo_name=\"codegen-sdk\", commit=\"834b600c6802f9eb33023cb30abeb7a96c80f495\")" |
| 84 | + ] |
| 85 | + }, |
| 86 | + { |
| 87 | + "cell_type": "code", |
| 88 | + "execution_count": 60, |
| 89 | + "metadata": {}, |
| 90 | + "outputs": [ |
| 91 | + { |
| 92 | + "ename": "KeyboardInterrupt", |
| 93 | + "evalue": "", |
| 94 | + "output_type": "error", |
| 95 | + "traceback": [ |
| 96 | + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
| 97 | + "\u001b[0;31mCancelledError\u001b[0m Traceback (most recent call last)", |
| 98 | + "File \u001b[0;32m~/dev/codegen-sdk/.venv/lib/python3.13/site-packages/synchronicity/synchronizer.py:336\u001b[0m, in \u001b[0;36mSynchronizer._run_function_sync\u001b[0;34m(self, coro, original_func)\u001b[0m\n\u001b[1;32m 335\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 336\u001b[0m value \u001b[38;5;241m=\u001b[39m \u001b[43mfut\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mresult\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 337\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m concurrent\u001b[38;5;241m.\u001b[39mfutures\u001b[38;5;241m.\u001b[39mCancelledError \u001b[38;5;28;01mas\u001b[39;00m expected_cancellation:\n\u001b[1;32m 338\u001b[0m \u001b[38;5;66;03m# we *expect* this cancellation, but defer to the passed coro to potentially\u001b[39;00m\n\u001b[1;32m 339\u001b[0m \u001b[38;5;66;03m# intercept and treat the cancellation some other way\u001b[39;00m\n", |
| 99 | + "File \u001b[0;32m~/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13/concurrent/futures/_base.py:454\u001b[0m, in \u001b[0;36mFuture.result\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 453\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_state \u001b[38;5;129;01min\u001b[39;00m [CANCELLED, CANCELLED_AND_NOTIFIED]:\n\u001b[0;32m--> 454\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m CancelledError()\n\u001b[1;32m 455\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_state \u001b[38;5;241m==\u001b[39m FINISHED:\n", |
| 100 | + "\u001b[0;31mCancelledError\u001b[0m: ", |
| 101 | + "\nDuring handling of the above exception, another exception occurred:\n", |
| 102 | + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", |
| 103 | + "Cell \u001b[0;32mIn[60], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mklass\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfiles\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mremote\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", |
| 104 | + "File \u001b[0;32m~/dev/codegen-sdk/.venv/lib/python3.13/site-packages/synchronicity/synchronizer.py:592\u001b[0m, in \u001b[0;36mSynchronizer._wrap_proxy_method.<locals>.proxy_method\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 590\u001b[0m instance \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__dict__\u001b[39m[synchronizer_self\u001b[38;5;241m.\u001b[39m_original_attr]\n\u001b[1;32m 591\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 592\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mwrapped_method\u001b[49m\u001b[43m(\u001b[49m\u001b[43minstance\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 593\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m UserCodeException \u001b[38;5;28;01mas\u001b[39;00m uc_exc:\n\u001b[1;32m 594\u001b[0m uc_exc\u001b[38;5;241m.\u001b[39mexc\u001b[38;5;241m.\u001b[39m__suppress_context__ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n", |
| 105 | + "File \u001b[0;32m~/dev/codegen-sdk/.venv/lib/python3.13/site-packages/synchronicity/combined_types.py:26\u001b[0m, in \u001b[0;36mFunctionWithAio.__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 20\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 21\u001b[0m \u001b[38;5;66;03m# .__call__ is special - it's being looked up on the class instead of the instance when calling something,\u001b[39;00m\n\u001b[1;32m 22\u001b[0m \u001b[38;5;66;03m# so setting the magic method from the constructor is not possible\u001b[39;00m\n\u001b[1;32m 23\u001b[0m \u001b[38;5;66;03m# https://stackoverflow.com/questions/22390532/object-is-not-callable-after-adding-call-method-to-instance\u001b[39;00m\n\u001b[1;32m 24\u001b[0m \u001b[38;5;66;03m# so we need to use an explicit wrapper function here\u001b[39;00m\n\u001b[1;32m 25\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m---> 26\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_func\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 27\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m UserCodeException \u001b[38;5;28;01mas\u001b[39;00m uc_exc:\n\u001b[1;32m 28\u001b[0m uc_exc\u001b[38;5;241m.\u001b[39mexc\u001b[38;5;241m.\u001b[39m__suppress_context__ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n", |
| 106 | + "File \u001b[0;32m~/dev/codegen-sdk/.venv/lib/python3.13/site-packages/synchronicity/synchronizer.py:510\u001b[0m, in \u001b[0;36mSynchronizer._wrap_callable.<locals>.f_wrapped\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 507\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m interface \u001b[38;5;241m==\u001b[39m Interface\u001b[38;5;241m.\u001b[39mBLOCKING:\n\u001b[1;32m 508\u001b[0m \u001b[38;5;66;03m# This is the exit point, so we need to unwrap the exception here\u001b[39;00m\n\u001b[1;32m 509\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 510\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_run_function_sync\u001b[49m\u001b[43m(\u001b[49m\u001b[43mres\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mf\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 511\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mStopAsyncIteration\u001b[39;00m:\n\u001b[1;32m 512\u001b[0m \u001b[38;5;66;03m# this is a special case for handling __next__ wrappers around\u001b[39;00m\n\u001b[1;32m 513\u001b[0m \u001b[38;5;66;03m# __anext__ that raises StopAsyncIteration\u001b[39;00m\n\u001b[1;32m 514\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mStopIteration\u001b[39;00m()\n", |
| 107 | + "File \u001b[0;32m~/dev/codegen-sdk/.venv/lib/python3.13/site-packages/synchronicity/synchronizer.py:341\u001b[0m, in \u001b[0;36mSynchronizer._run_function_sync\u001b[0;34m(self, coro, original_func)\u001b[0m\n\u001b[1;32m 337\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m concurrent\u001b[38;5;241m.\u001b[39mfutures\u001b[38;5;241m.\u001b[39mCancelledError \u001b[38;5;28;01mas\u001b[39;00m expected_cancellation:\n\u001b[1;32m 338\u001b[0m \u001b[38;5;66;03m# we *expect* this cancellation, but defer to the passed coro to potentially\u001b[39;00m\n\u001b[1;32m 339\u001b[0m \u001b[38;5;66;03m# intercept and treat the cancellation some other way\u001b[39;00m\n\u001b[1;32m 340\u001b[0m expected_cancellation\u001b[38;5;241m.\u001b[39m__suppress_context__ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m--> 341\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m exc \u001b[38;5;66;03m# if cancel - re-raise the original KeyboardInterrupt again\u001b[39;00m\n\u001b[1;32m 343\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mgetattr\u001b[39m(original_func, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_output_translation_attr, \u001b[38;5;28;01mTrue\u001b[39;00m):\n\u001b[1;32m 344\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_translate_out(value)\n", |
| 108 | + "File \u001b[0;32m~/dev/codegen-sdk/.venv/lib/python3.13/site-packages/synchronicity/synchronizer.py:325\u001b[0m, in \u001b[0;36mSynchronizer._run_function_sync\u001b[0;34m(self, coro, original_func)\u001b[0m\n\u001b[1;32m 321\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 322\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 323\u001b[0m \u001b[38;5;66;03m# poll every second to give Windows a chance to abort on Ctrl-C\u001b[39;00m\n\u001b[1;32m 324\u001b[0m \u001b[38;5;66;03m#\u001b[39;00m\n\u001b[0;32m--> 325\u001b[0m value \u001b[38;5;241m=\u001b[39m \u001b[43mfut\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mresult\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m0.1\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 326\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[1;32m 327\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m concurrent\u001b[38;5;241m.\u001b[39mfutures\u001b[38;5;241m.\u001b[39mTimeoutError:\n", |
| 109 | + "File \u001b[0;32m~/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13/concurrent/futures/_base.py:451\u001b[0m, in \u001b[0;36mFuture.result\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 448\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_state \u001b[38;5;241m==\u001b[39m FINISHED:\n\u001b[1;32m 449\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m__get_result()\n\u001b[0;32m--> 451\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_condition\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwait\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 453\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_state \u001b[38;5;129;01min\u001b[39;00m [CANCELLED, CANCELLED_AND_NOTIFIED]:\n\u001b[1;32m 454\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m CancelledError()\n", |
| 110 | + "File \u001b[0;32m~/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13/threading.py:363\u001b[0m, in \u001b[0;36mCondition.wait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 361\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 362\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m timeout \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m--> 363\u001b[0m gotit \u001b[38;5;241m=\u001b[39m \u001b[43mwaiter\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43macquire\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 364\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 365\u001b[0m gotit \u001b[38;5;241m=\u001b[39m waiter\u001b[38;5;241m.\u001b[39macquire(\u001b[38;5;28;01mFalse\u001b[39;00m)\n", |
| 111 | + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " |
| 112 | + ] |
| 113 | + } |
| 114 | + ], |
| 115 | + "source": [ |
| 116 | + "klass.files.remote()" |
| 117 | + ] |
| 118 | + }, |
| 119 | + { |
| 120 | + "cell_type": "code", |
| 121 | + "execution_count": 42, |
| 122 | + "metadata": {}, |
| 123 | + "outputs": [], |
| 124 | + "source": [ |
| 125 | + "Klass = modal.Cls.from_name(app_name=\"snapshot-test\", name=\"SubClassTest\")\n", |
| 126 | + "klass = Klass(repo_org=\"codegen-sh\", repo_name=\"codegen-sdk\", commit=\"eb7ca7445c2afd580eaf94a87c4f0dbe281463ee\")\n" |
| 127 | + ] |
| 128 | + }, |
| 129 | + { |
| 130 | + "cell_type": "code", |
| 131 | + "execution_count": null, |
| 132 | + "metadata": {}, |
| 133 | + "outputs": [], |
| 134 | + "source": [ |
| 135 | + "klass.files.remote()" |
| 136 | + ] |
| 137 | + }, |
| 138 | + { |
| 139 | + "cell_type": "code", |
| 140 | + "execution_count": 52, |
| 141 | + "metadata": {}, |
| 142 | + "outputs": [], |
| 143 | + "source": [ |
| 144 | + "c = Codebase.from_repo(commit=\"eb7ca7445c2afd580eaf94a87c4f0dbe281463ee\", repo_full_name=\"codegen-sh/codegen-sdk\")" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "code", |
| 149 | + "execution_count": null, |
| 150 | + "metadata": {}, |
| 151 | + "outputs": [], |
| 152 | + "source": [ |
| 153 | + "len(c.files)" |
| 154 | + ] |
| 155 | + }, |
| 156 | + { |
| 157 | + "cell_type": "code", |
| 158 | + "execution_count": null, |
| 159 | + "metadata": {}, |
| 160 | + "outputs": [], |
| 161 | + "source": [] |
| 162 | + } |
| 163 | + ], |
| 164 | + "metadata": { |
| 165 | + "kernelspec": { |
| 166 | + "display_name": ".venv", |
| 167 | + "language": "python", |
| 168 | + "name": "python3" |
| 169 | + }, |
| 170 | + "language_info": { |
| 171 | + "codemirror_mode": { |
| 172 | + "name": "ipython", |
| 173 | + "version": 3 |
| 174 | + }, |
| 175 | + "file_extension": ".py", |
| 176 | + "mimetype": "text/x-python", |
| 177 | + "name": "python", |
| 178 | + "nbconvert_exporter": "python", |
| 179 | + "pygments_lexer": "ipython3", |
| 180 | + "version": "3.13.0" |
| 181 | + } |
| 182 | + }, |
| 183 | + "nbformat": 4, |
| 184 | + "nbformat_minor": 2 |
| 185 | +} |
0 commit comments