Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

fix(cli): use absolute import in generated Python build scripts (#1505)

mattteufel-e2bd071bb78c833
diff --git a/.changeset/migrate-python-build-import.md b/.changeset/migrate-python-build-import.md
new file mode 100644
index 000000000..cddb32973
--- /dev/null
+++ b/.changeset/migrate-python-build-import.md
@@ -0,0 +1,5 @@
+---
+"@e2b/cli": patch
+---
+
+Fix `e2b template migrate` generating Python build scripts that fail to run as instructed. The generated `build_dev.py` / `build_prod.py` used a package-relative import (`from .template import template`) while the command instructs single-file execution (`python build_dev.py`), causing `ImportError: attempted relative import with no known parent package`. The scripts now use a runnable absolute import (`from template import template`).
diff --git a/packages/cli/src/templates/python-build-async.hbs b/packages/cli/src/templates/python-build-async.hbs
index 7dee8d823..95e885d73 100644
--- a/packages/cli/src/templates/python-build-async.hbs
+++ b/packages/cli/src/templates/python-build-async.hbs
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/src/templates/python-build-sync.hbs b/packages/cli/src/templates/python-build-sync.hbs
index 3282d48bc..78f9c32c0 100644
--- a/packages/cli/src/templates/python-build-sync.hbs
+++ b/packages/cli/src/templates/python-build-sync.hbs
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_dev.py
index e9831b18b..25af75629 100644
--- a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_dev.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_prod.py
index 18aa5b660..1c5f3151a 100644
--- a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_prod.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_dev.py
index 8c884a5f6..e0b1466fe 100644
--- a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_dev.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_prod.py
index 082f75c42..b3639034e 100644
--- a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_prod.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_dev.py
index d998b5a94..1ad567da8 100644
--- a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_dev.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_prod.py
index f18d3c9b5..f7047a289 100644
--- a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_prod.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_dev.py
index 570303273..03a5874ed 100644
--- a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_dev.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_prod.py
index c8e6ac40a..b01cadf83 100644
--- a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_prod.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_dev.py
index 33c1e1d6b..c4084caac 100644
--- a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_dev.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_prod.py
index 7f0db5b05..0bcb2980f 100644
--- a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_prod.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_dev.py
index 3ceaf7f5d..680b692a3 100644
--- a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_dev.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_prod.py
index b8131505b..e6c1ca76e 100644
--- a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_prod.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_dev.py
index d63430b19..f9178ee20 100644
--- a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_dev.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_prod.py
index 499c26251..08f0c7485 100644
--- a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_prod.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_dev.py
index 9d7aa78cc..4df82d1f9 100644
--- a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_dev.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_prod.py
index 62ccb29ee..30acefb3f 100644
--- a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_prod.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_dev.py
index 4cf9bfa48..16456db43 100644
--- a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_dev.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_prod.py
index 23d29ef82..3cecb8d71 100644
--- a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_prod.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_dev.py
index ff50bda88..cc7e4e9b5 100644
--- a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_dev.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_prod.py
index 0482afd92..c8aff7ed3 100644
--- a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_prod.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_dev.py
index e412fea8c..03d821c99 100644
--- a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_dev.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_prod.py
index 429b2bef0..00fbf6ae7 100644
--- a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_prod.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_dev.py
index 109806c79..1cac5877c 100644
--- a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_dev.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_prod.py
index c4920362e..e31216e81 100644
--- a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_prod.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_dev.py
index 01db35dbf..4f1bb29fe 100644
--- a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_dev.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_prod.py
index d80427426..6eec99586 100644
--- a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_prod.py
@@ -1,6 +1,6 @@
import asyncio
from e2b import AsyncTemplate, default_build_logger
-from .template import template
+from template import template
async def main():
diff --git a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_dev.py
index bd7bf61ca..f0ae5cdb5 100644
--- a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_dev.py
+++ b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_dev.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_prod.py
index 24a98cce3..c3f33de04 100644
--- a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_prod.py
+++ b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_prod.py
@@ -1,5 +1,5 @@
from e2b import Template, default_build_logger
-from .template import template
+from template import template
if __name__ == "__main__":
diff --git a/packages/cli/tests/commands/template/migrate.test.ts b/packages/cli/tests/commands/template/migrate.test.ts
index 9dd87840e..ee6cbb3e5 100644
--- a/packages/cli/tests/commands/template/migrate.test.ts
+++ b/packages/cli/tests/commands/template/migrate.test.ts
@@ -125,6 +125,15 @@ describe('Template Migration', () => {
'utf-8'
)
expect(buildProdFile.trim()).toEqual(expectedBuildProd.trim())
+ if (
+ language === Language.PythonSync ||
+ language === Language.PythonAsync
+ ) {
+ for (const content of [buildDevFile, buildProdFile]) {
+ expect(content).toContain('from template import template')
+ expect(content).not.toContain('from .template import template')
+ }
+ }
// Check that old files are renamed to .old extensions
const oldDockerfilePath = path.join(testDir, 'e2b.Dockerfile.old')