Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Rename alias exists > name exists (#1100)

Mish Ushakov07ef17f1b031
diff --git a/.changeset/neat-tips-stick.md b/.changeset/neat-tips-stick.md
new file mode 100644
index 000000000..e8367e384
--- /dev/null
+++ b/.changeset/neat-tips-stick.md
@@ -0,0 +1,6 @@
+---
+'@e2b/python-sdk': patch
+'e2b': patch
+---
+
+deprecate aliasexists and add exists
diff --git a/packages/js-sdk/src/template/index.ts b/packages/js-sdk/src/template/index.ts
index 0712b1810..c40184ab3 100644
--- a/packages/js-sdk/src/template/index.ts
+++ b/packages/js-sdk/src/template/index.ts
@@ -20,7 +20,6 @@ import { parseDockerfile } from './dockerfileParser'
import { LogEntry, LogEntryEnd, LogEntryStart } from './logger'
import { ReadyCmd, waitForFile } from './readycmd'
import {
- AliasExistsOptions,
BuildInfo,
BuildOptions,
CopyItem,
@@ -268,6 +267,28 @@ export class TemplateBase
})
}
+ /**
+ * Check if a template with the given name exists.
+ *
+ * @param name Template name to check
+ * @param options Authentication options
+ * @returns True if the name exists, false otherwise
+ *
+ * @example
+ * ```ts
+ * const exists = await Template.exists('my-python-env')
+ * if (exists) {
+ * console.log('Template exists!')
+ * }
+ * ```
+ */
+ static async exists(
+ name: string,
+ options?: ConnectionOpts
+ ): Promise<boolean> {
+ return TemplateBase.aliasExists(name, options)
+ }
+
/**
* Check if a template with the given alias exists.
*
@@ -275,6 +296,7 @@ export class TemplateBase
* @param options Authentication options
* @returns True if the alias exists, false otherwise
*
+ * @deprecated Use `exists` instead.
* @example
* ```ts
* const exists = await Template.aliasExists('my-python-env')
@@ -285,7 +307,7 @@ export class TemplateBase
*/
static async aliasExists(
alias: string,
- options?: AliasExistsOptions
+ options?: ConnectionOpts
): Promise<boolean> {
const config = new ConnectionConfig(options)
const client = new ApiClient(config)
@@ -1223,6 +1245,7 @@ export function Template(options?: TemplateOptions): TemplateFromImage {
Template.build = TemplateBase.build
Template.buildInBackground = TemplateBase.buildInBackground
Template.getBuildStatus = TemplateBase.getBuildStatus
+Template.exists = TemplateBase.exists
Template.aliasExists = TemplateBase.aliasExists
Template.assignTags = TemplateBase.assignTags
Template.removeTags = TemplateBase.removeTags
@@ -1230,7 +1253,6 @@ Template.toJSON = TemplateBase.toJSON
Template.toDockerfile = TemplateBase.toDockerfile
export type {
- AliasExistsOptions,
BuildInfo,
BuildOptions,
BuildStatusReason,
diff --git a/packages/js-sdk/src/template/types.ts b/packages/js-sdk/src/template/types.ts
index 5d0feabdf..23999de7c 100644
--- a/packages/js-sdk/src/template/types.ts
+++ b/packages/js-sdk/src/template/types.ts
@@ -158,11 +158,6 @@ export type TemplateTagInfo = {
tags: string[]
}
-/**
- * Options for checking if a template alias exists.
- */
-export type AliasExistsOptions = ConnectionOpts
-
/**
* Types of instructions that can be used in a template.
*/
diff --git a/packages/js-sdk/tests/template/aliasExists.test.ts b/packages/js-sdk/tests/template/aliasExists.test.ts
deleted file mode 100644
index a91449dfb..000000000
--- a/packages/js-sdk/tests/template/aliasExists.test.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { randomUUID } from 'node:crypto'
-import { expect, test } from 'vitest'
-import { Template } from '../../src'
-
-test('check if base template alias exists', async () => {
- const exists = await Template.aliasExists('base')
- expect(exists).toBe(true)
-})
-
-test('check non existing alias', async () => {
- const nonExistingAlias = `nonexistent-${randomUUID()}`
- const exists = await Template.aliasExists(nonExistingAlias)
- expect(exists).toBe(false)
-})
diff --git a/packages/js-sdk/tests/template/exists.test.ts b/packages/js-sdk/tests/template/exists.test.ts
new file mode 100644
index 000000000..aa62857c7
--- /dev/null
+++ b/packages/js-sdk/tests/template/exists.test.ts
@@ -0,0 +1,14 @@
+import { randomUUID } from 'node:crypto'
+import { expect, test } from 'vitest'
+import { Template } from '../../src'
+
+test('check if base template name exists', async () => {
+ const exists = await Template.exists('base')
+ expect(exists).toBe(true)
+})
+
+test('check non existing name', async () => {
+ const nonExistingName = `nonexistent-${randomUUID()}`
+ const exists = await Template.exists(nonExistingName)
+ expect(exists).toBe(false)
+})
diff --git a/packages/python-sdk/e2b/template_async/main.py b/packages/python-sdk/e2b/template_async/main.py
index 8a1746b4d..a459af2cc 100644
--- a/packages/python-sdk/e2b/template_async/main.py
+++ b/packages/python-sdk/e2b/template_async/main.py
@@ -376,6 +376,29 @@ class AsyncTemplate(TemplateBase):
logs_offset,
)
+ @staticmethod
+ async def exists(
+ name: str,
+ **opts: Unpack[ApiParams],
+ ) -> bool:
+ """
+ Check if a template with the given name exists.
+
+ :param name: Template name to check
+ :return: True if the name exists, False otherwise
+
+ Example
+ ```python
+ from e2b import AsyncTemplate
+
+ exists = await AsyncTemplate.exists('my-python-env')
+ if exists:
+ print('Template exists!')
+ ```
+ """
+
+ return await AsyncTemplate.alias_exists(name, **opts)
+
@staticmethod
async def alias_exists(
alias: str,
@@ -384,6 +407,8 @@ class AsyncTemplate(TemplateBase):
"""
Check if a template with the given alias exists.
+ Deprecated Use `exists` instead.
+
:param alias: Template alias to check
:return: True if the alias exists, False otherwise
@@ -391,7 +416,7 @@ class AsyncTemplate(TemplateBase):
```python
from e2b import AsyncTemplate
- exists = await AsyncTemplate.alias_exists('base')
+ exists = await AsyncTemplate.alias_exists('my-python-env')
if exists:
print('Template exists!')
```
diff --git a/packages/python-sdk/e2b/template_sync/main.py b/packages/python-sdk/e2b/template_sync/main.py
index 10a6012f8..1278e4d0c 100644
--- a/packages/python-sdk/e2b/template_sync/main.py
+++ b/packages/python-sdk/e2b/template_sync/main.py
@@ -377,6 +377,29 @@ class Template(TemplateBase):
logs_offset,
)
+ @staticmethod
+ def exists(
+ name: str,
+ **opts: Unpack[ApiParams],
+ ) -> bool:
+ """
+ Check if a template with the given name exists.
+
+ :param name: Template name to check
+ :return: True if the name exists, False otherwise
+
+ Example
+ ```python
+ from e2b import Template
+
+ exists = Template.exists('my-python-env')
+ if exists:
+ print('Template exists!')
+ ```
+ """
+
+ return Template.alias_exists(name, **opts)
+
@staticmethod
def alias_exists(
alias: str,
@@ -385,6 +408,8 @@ class Template(TemplateBase):
"""
Check if a template with the given alias exists.
+ Deprecated Use `exists` instead.
+
:param alias: Template alias to check
:return: True if the alias exists, False otherwise
@@ -392,7 +417,7 @@ class Template(TemplateBase):
```python
from e2b import Template
- exists = Template.alias_exists('base')
+ exists = Template.alias_exists('my-python-env')
if exists:
print('Template exists!')
```
diff --git a/packages/python-sdk/tests/async/template_async/test_alias_exists.py b/packages/python-sdk/tests/async/template_async/test_alias_exists.py
deleted file mode 100644
index da2b7093d..000000000
--- a/packages/python-sdk/tests/async/template_async/test_alias_exists.py
+++ /dev/null
@@ -1,20 +0,0 @@
-import uuid
-
-import pytest
-
-from e2b import AsyncTemplate
-
-
-async def test_check_base_template_alias_exists():
- """Test that the base template alias exists."""
- exists = await AsyncTemplate.alias_exists("base")
- assert exists is True
-
-
-async def test_check_non_existing_alias():
- """Test that a non-existing alias returns False."""
- non_existing_alias = f"nonexistent-{uuid.uuid4()}"
- exists = await AsyncTemplate.alias_exists(non_existing_alias)
- assert exists is False
diff --git a/packages/python-sdk/tests/async/template_async/test_exists.py b/packages/python-sdk/tests/async/template_async/test_exists.py
new file mode 100644
index 000000000..6da560947
--- /dev/null
+++ b/packages/python-sdk/tests/async/template_async/test_exists.py
@@ -0,0 +1,20 @@
+import uuid
+
+import pytest
+
+from e2b import AsyncTemplate
+
+
+async def test_check_base_template_name_exists():
+ """Test that the base template name exists."""
+ exists = await AsyncTemplate.exists("base")
+ assert exists is True
+
+
+async def test_check_non_existing_name():
+ """Test that a non-existing name returns False."""
+ non_existing_name = f"nonexistent-{uuid.uuid4()}"
+ exists = await AsyncTemplate.exists(non_existing_name)
+ assert exists is False
diff --git a/packages/python-sdk/tests/sync/template_sync/test_alias_exists.py b/packages/python-sdk/tests/sync/template_sync/test_alias_exists.py
deleted file mode 100644
index 43397db90..000000000
--- a/packages/python-sdk/tests/sync/template_sync/test_alias_exists.py
+++ /dev/null
@@ -1,20 +0,0 @@
-import uuid
-
-import pytest
-
-from e2b import Template
-
-
-def test_check_base_template_alias_exists():
- """Test that the base template alias exists."""
- exists = Template.alias_exists("base")
- assert exists is True
-
-
-def test_check_non_existing_alias():
- """Test that a non-existing alias returns False."""
- non_existing_alias = f"nonexistent-{uuid.uuid4()}"
- exists = Template.alias_exists(non_existing_alias)
- assert exists is False
diff --git a/packages/python-sdk/tests/sync/template_sync/test_exists.py b/packages/python-sdk/tests/sync/template_sync/test_exists.py
new file mode 100644
index 000000000..641b58ba0
--- /dev/null
+++ b/packages/python-sdk/tests/sync/template_sync/test_exists.py
@@ -0,0 +1,20 @@
+import uuid
+
+import pytest
+
+from e2b import Template
+
+
+def test_check_base_template_name_exists():
+ """Test that the base template name exists."""
+ exists = Template.exists("base")
+ assert exists is True
+
+
+def test_check_non_existing_name():
+ """Test that a non-existing name returns False."""
+ non_existing_name = f"nonexistent-{uuid.uuid4()}"
+ exists = Template.exists(non_existing_name)
+ assert exists is False