Skip to content

Commit 06fe9a9

Browse files
committed
sdk/python: ruff format
1 parent 50d8122 commit 06fe9a9

7 files changed

Lines changed: 92 additions & 61 deletions

File tree

sdk/python/src/dstack_sdk/dstack_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ class BaseClient:
197197

198198

199199
class AsyncDstackClient(BaseClient):
200-
201200
PATH_PREFIX = "/"
202201

203202
def __init__(self, endpoint: str | None = None, use_sync_http: bool = False):
@@ -363,7 +362,6 @@ async def is_reachable(self) -> bool:
363362

364363

365364
class DstackClient(BaseClient):
366-
367365
PATH_PREFIX = "/"
368366

369367
def __init__(self, endpoint: str | None = None):

sdk/python/src/dstack_sdk/ethereum.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Use with ``dstack_sdk.DstackClient`` responses to create ``eth_account``
88
objects for signing and transacting.
99
"""
10+
1011
import hashlib
1112
import warnings
1213

sdk/python/src/dstack_sdk/solana.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Use with ``dstack_sdk.DstackClient`` responses to create ``solders.Keypair``
88
objects for signing transactions on Solana.
99
"""
10+
1011
import hashlib
1112
import warnings
1213

sdk/python/test_outputs.py

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,82 +5,103 @@
55
import asyncio
66
import sys
77

8-
from dstack_sdk import DstackClient, AsyncDstackClient, TappdClient, AsyncTappdClient, get_compose_hash, verify_env_encrypt_public_key
8+
from dstack_sdk import (
9+
DstackClient,
10+
AsyncDstackClient,
11+
TappdClient,
12+
AsyncTappdClient,
13+
get_compose_hash,
14+
verify_env_encrypt_public_key,
15+
)
916

1017

1118
async def main():
1219
print("=== Python SDK Output Test ===")
13-
20+
1421
try:
1522
# Test client get_key
1623
client = DstackClient()
1724
print("\n1. Testing DstackClient.get_key()")
18-
25+
1926
test_paths = [
2027
{"path": "test/wallet", "purpose": "ethereum"},
2128
{"path": "test/signing", "purpose": "solana"},
22-
{"path": "user/alice", "purpose": "mainnet"}
29+
{"path": "user/alice", "purpose": "mainnet"},
2330
]
24-
31+
2532
for test_case in test_paths:
2633
path, purpose = test_case["path"], test_case["purpose"]
2734
key_result = client.get_key(path, purpose)
2835
print(f"get_key('{path}', '{purpose}'):")
2936
print(f" key: {key_result.decode_key().hex()}")
3037
print(f" signature_chain length: {len(key_result.signature_chain)}")
31-
print(f" signature_chain[0]: {key_result.decode_signature_chain()[0].hex()}")
38+
print(
39+
f" signature_chain[0]: {key_result.decode_signature_chain()[0].hex()}"
40+
)
3241

3342
# Test viem integration (if available)
3443
print("\n2. Testing Viem Integration")
3544
eth_key = client.get_key("eth/test", "wallet")
36-
45+
3746
print("\n2.1 to_account (legacy):")
3847
try:
3948
from dstack_sdk.ethereum import to_account
49+
4050
account = to_account(eth_key)
4151
print(f" address: {account.address}")
4252
print(f" type: ethereum account")
4353
except ImportError:
44-
print(" error: Ethereum integration not available (install with pip install 'dstack-sdk[eth]')")
54+
print(
55+
" error: Ethereum integration not available (install with pip install 'dstack-sdk[eth]')"
56+
)
4557
except Exception as error:
4658
print(f" error: {error}")
47-
59+
4860
print("\n2.2 to_account_secure:")
4961
try:
5062
from dstack_sdk.ethereum import to_account_secure
63+
5164
account_secure = to_account_secure(eth_key)
5265
print(f" address: {account_secure.address}")
5366
print(f" type: ethereum account")
5467
except ImportError:
55-
print(" error: Ethereum integration not available (install with pip install 'dstack-sdk[eth]')")
68+
print(
69+
" error: Ethereum integration not available (install with pip install 'dstack-sdk[eth]')"
70+
)
5671
except Exception as error:
5772
print(f" error: {error}")
5873

5974
# Test solana integration (if available)
6075
print("\n3. Testing Solana Integration")
6176
sol_key = client.get_key("sol/test", "wallet")
62-
77+
6378
print("\n3.1 to_keypair (legacy):")
6479
try:
6580
from dstack_sdk.solana import to_keypair
81+
6682
keypair = to_keypair(sol_key)
6783
print(f" publicKey: {keypair.pubkey()}")
6884
print(f" secretKey length: {len(bytes(keypair))}")
6985
print(f" secretKey (first 32 bytes): {bytes(keypair)[:32].hex()}")
7086
except ImportError:
71-
print(" error: Solana integration not available (install with pip install 'dstack-sdk[sol]')")
87+
print(
88+
" error: Solana integration not available (install with pip install 'dstack-sdk[sol]')"
89+
)
7290
except Exception as error:
7391
print(f" error: {error}")
74-
92+
7593
print("\n3.2 to_keypair_secure:")
7694
try:
7795
from dstack_sdk.solana import to_keypair_secure
96+
7897
keypair_secure = to_keypair_secure(sol_key)
7998
print(f" publicKey: {keypair_secure.pubkey()}")
8099
print(f" secretKey length: {len(bytes(keypair_secure))}")
81100
print(f" secretKey (first 32 bytes): {bytes(keypair_secure)[:32].hex()}")
82101
except ImportError:
83-
print(" error: Solana integration not available (install with pip install 'dstack-sdk[sol]')")
102+
print(
103+
" error: Solana integration not available (install with pip install 'dstack-sdk[sol]')"
104+
)
84105
except Exception as error:
85106
print(f" error: {error}")
86107

@@ -106,7 +127,9 @@ async def main():
106127
try:
107128
async_tappd_client = AsyncTappdClient()
108129
print("\n4.3.1 AsyncTappdClient.get_key():")
109-
async_tappd_key = await async_tappd_client.get_key("test/wallet", "ethereum")
130+
async_tappd_key = await async_tappd_client.get_key(
131+
"test/wallet", "ethereum"
132+
)
110133
print(f" key: {async_tappd_key.decode_key().hex()}")
111134
print(f" signature_chain length: {len(async_tappd_key.signature_chain)}")
112135

@@ -140,16 +163,16 @@ async def main():
140163
"manifest_version": 1,
141164
"name": "test-app",
142165
"runner": "docker-compose",
143-
"docker_compose_file": "services:\\n app:\\n image: test\\n ports:\\n - 8080:8080"
166+
"docker_compose_file": "services:\\n app:\\n image: test\\n ports:\\n - 8080:8080",
144167
},
145168
{
146169
"manifest_version": 1,
147-
"name": "another-app",
170+
"name": "another-app",
148171
"runner": "docker-compose",
149-
"docker_compose_file": "services:\\n web:\\n build: .\\n environment:\\n - NODE_ENV=production"
150-
}
172+
"docker_compose_file": "services:\\n web:\\n build: .\\n environment:\\n - NODE_ENV=production",
173+
},
151174
]
152-
175+
153176
for index, compose in enumerate(test_composes):
154177
hash_value = get_compose_hash(compose)
155178
print(f"compose {index + 1}: {hash_value}")
@@ -160,23 +183,29 @@ async def main():
160183
print("\n7. Testing verify_env_encrypt_public_key")
161184
test_cases = [
162185
{
163-
"public_key": bytes.fromhex('e33a1832c6562067ff8f844a61e51ad051f1180b66ec2551fb0251735f3ee90a'),
164-
"signature": bytes.fromhex('8542c49081fbf4e03f62034f13fbf70630bdf256a53032e38465a27c36fd6bed7a5e7111652004aef37f7fd92fbfc1285212c4ae6a6154203a48f5e16cad2cef00'),
165-
"app_id": '0000000000000000000000000000000000000000'
186+
"public_key": bytes.fromhex(
187+
"e33a1832c6562067ff8f844a61e51ad051f1180b66ec2551fb0251735f3ee90a"
188+
),
189+
"signature": bytes.fromhex(
190+
"8542c49081fbf4e03f62034f13fbf70630bdf256a53032e38465a27c36fd6bed7a5e7111652004aef37f7fd92fbfc1285212c4ae6a6154203a48f5e16cad2cef00"
191+
),
192+
"app_id": "0000000000000000000000000000000000000000",
166193
},
167194
{
168-
"public_key": bytes.fromhex('deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'),
169-
"signature": bytes.fromhex('0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'),
170-
"app_id": 'invalid-app-id'
171-
}
195+
"public_key": bytes.fromhex(
196+
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
197+
),
198+
"signature": bytes.fromhex(
199+
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
200+
),
201+
"app_id": "invalid-app-id",
202+
},
172203
]
173204

174205
for index, test_case in enumerate(test_cases):
175206
try:
176207
result = verify_env_encrypt_public_key(
177-
test_case["public_key"],
178-
test_case["signature"],
179-
test_case["app_id"]
208+
test_case["public_key"], test_case["signature"], test_case["app_id"]
180209
)
181210
print(f"test case {index + 1}: {result.hex() if result else 'null'}")
182211
except Exception as error:
@@ -186,5 +215,6 @@ async def main():
186215
print(f"Error: {error}")
187216
sys.exit(1)
188217

218+
189219
if __name__ == "__main__":
190-
asyncio.run(main())
220+
asyncio.run(main())

sdk/python/tests/test_client.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,15 @@ def test_tappd_client_deprecated():
263263
with warnings.catch_warnings(record=True) as w:
264264
warnings.simplefilter("always")
265265
TappdClient()
266-
266+
267267
# Filter for TappdClient deprecation warnings specifically
268268
tappd_warnings = [
269-
warning for warning in w
270-
if issubclass(warning.category, DeprecationWarning)
269+
warning
270+
for warning in w
271+
if issubclass(warning.category, DeprecationWarning)
271272
and "TappdClient is deprecated" in str(warning.message)
272273
]
273-
274+
274275
assert len(tappd_warnings) == 1
275276
assert "TappdClient is deprecated" in str(tappd_warnings[0].message)
276277

@@ -307,14 +308,15 @@ def test_async_tappd_client_deprecated():
307308
with warnings.catch_warnings(record=True) as w:
308309
warnings.simplefilter("always")
309310
AsyncTappdClient()
310-
311+
311312
# Filter for AsyncTappdClient deprecation warnings specifically
312313
tappd_warnings = [
313-
warning for warning in w
314-
if issubclass(warning.category, DeprecationWarning)
314+
warning
315+
for warning in w
316+
if issubclass(warning.category, DeprecationWarning)
315317
and "AsyncTappdClient is deprecated" in str(warning.message)
316318
]
317-
319+
318320
assert len(tappd_warnings) == 1
319321
assert "AsyncTappdClient is deprecated" in str(tappd_warnings[0].message)
320322

@@ -329,9 +331,7 @@ async def test_async_tappd_client_derive_key_deprecated():
329331
await client.derive_key("/", "test")
330332
# Should have warnings for both constructor and derive_key
331333
warning_messages = [str(warning.message) for warning in w]
332-
assert any(
333-
"AsyncTappdClient is deprecated" in msg for msg in warning_messages
334-
)
334+
assert any("AsyncTappdClient is deprecated" in msg for msg in warning_messages)
335335
assert any("derive_key is deprecated" in msg for msg in warning_messages)
336336

337337

@@ -345,9 +345,7 @@ async def test_async_tappd_client_tdx_quote_deprecated():
345345
await client.tdx_quote("test data", "raw")
346346
# Should have warnings for both constructor and tdx_quote
347347
warning_messages = [str(warning.message) for warning in w]
348-
assert any(
349-
"AsyncTappdClient is deprecated" in msg for msg in warning_messages
350-
)
348+
assert any("AsyncTappdClient is deprecated" in msg for msg in warning_messages)
351349
assert any("tdx_quote is deprecated" in msg for msg in warning_messages)
352350

353351

sdk/python/tests/test_typing.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def test_sync_method_type_annotations():
4141
except Exception as e:
4242
print(f"Error getting type hints for get_tls_key: {e}")
4343
# If we can't get type hints, at least check it's not a coroutine function
44-
assert not inspect.iscoroutinefunction(
45-
get_tls_key_method
46-
), "Sync method should not be a coroutine function"
44+
assert not inspect.iscoroutinefunction(get_tls_key_method), (
45+
"Sync method should not be a coroutine function"
46+
)
4747

4848

4949
def test_all_sync_method_types():
@@ -64,9 +64,9 @@ def test_all_sync_method_types():
6464
assert callable(method), f"{method_name} should be callable"
6565

6666
# Should not be coroutine function for sync client
67-
assert not inspect.iscoroutinefunction(
68-
method
69-
), f"Sync {method_name} should not be coroutine function"
67+
assert not inspect.iscoroutinefunction(method), (
68+
f"Sync {method_name} should not be coroutine function"
69+
)
7070

7171
try:
7272
type_hints = get_type_hints(method)
@@ -80,7 +80,9 @@ def test_all_sync_method_types():
8080
assert (
8181
return_type == expected_return_type
8282
or return_type is expected_return_type
83-
), f"{method_name} should return {expected_return_type}, got {return_type}"
83+
), (
84+
f"{method_name} should return {expected_return_type}, got {return_type}"
85+
)
8486

8587
except Exception as e:
8688
print(f"Warning: Could not get type hints for {method_name}: {e}")
@@ -104,9 +106,9 @@ def test_async_method_types():
104106
assert callable(method), f"{method_name} should be callable"
105107

106108
# Should be coroutine function for async client
107-
assert inspect.iscoroutinefunction(
108-
method
109-
), f"Async {method_name} should be coroutine function"
109+
assert inspect.iscoroutinefunction(method), (
110+
f"Async {method_name} should be coroutine function"
111+
)
110112

111113
try:
112114
type_hints = get_type_hints(method)
@@ -153,9 +155,9 @@ def test_method_signature_comparison():
153155
if "self" in async_params:
154156
async_params.remove("self")
155157

156-
assert (
157-
sync_params == async_params
158-
), f"Parameter mismatch for {method_name}: sync={sync_params}, async={async_params}"
158+
assert sync_params == async_params, (
159+
f"Parameter mismatch for {method_name}: sync={sync_params}, async={async_params}"
160+
)
159161

160162

161163
if __name__ == "__main__":

sdk/run-tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ if [ ! -d .venv ]; then
3535
fi
3636
source .venv/bin/activate
3737
pip install -e .
38-
pip install pytest pytest-asyncio evidence-api web3 solders
38+
pip install pytest pytest-asyncio evidence-api web3 solders ruff
3939
pytest
40+
ruff format --check --diff .
4041
popd
4142

4243
pushd js/

0 commit comments

Comments
 (0)