20
20
ServingImageBuilderContext ,
21
21
)
22
22
from truss .contexts .local_loader .docker_build_emulator import DockerBuildEmulator
23
- from truss .truss_handle .build import init
23
+ from truss .truss_handle .build import init_directory
24
24
from truss .truss_handle .truss_handle import TrussHandle
25
25
26
26
CUSTOM_MODEL_CODE = """
@@ -435,17 +435,15 @@ def dynamic_config_mount_dir(tmp_path, monkeypatch: pytest.MonkeyPatch):
435
435
@pytest .fixture
436
436
def custom_model_truss_dir_with_pre_and_post_no_example (tmp_path ):
437
437
dir_path = tmp_path / "custom_truss_with_pre_post_no_example"
438
- handle = init (str (dir_path ))
439
- handle .spec .model_class_filepath .write_text (
440
- CUSTOM_MODEL_CODE_WITH_PRE_AND_POST_PROCESS
441
- )
438
+ th = TrussHandle (init_directory (dir_path ))
439
+ th .spec .model_class_filepath .write_text (CUSTOM_MODEL_CODE_WITH_PRE_AND_POST_PROCESS )
442
440
yield dir_path
443
441
444
442
445
443
@pytest .fixture
446
444
def custom_model_truss_dir_with_hidden_files (tmp_path ):
447
445
truss_dir_path : Path = tmp_path / "custom_model_truss_dir_with_hidden_files"
448
- _ = init ( str ( truss_dir_path ) )
446
+ init_directory ( truss_dir_path )
449
447
(truss_dir_path / "__pycache__" ).mkdir (parents = True , exist_ok = True )
450
448
(truss_dir_path / ".git" ).mkdir (parents = True , exist_ok = True )
451
449
(truss_dir_path / "__pycache__" / "test.cpython-311.pyc" ).touch ()
@@ -458,7 +456,7 @@ def custom_model_truss_dir_with_hidden_files(tmp_path):
458
456
@pytest .fixture
459
457
def custom_model_truss_dir_with_truss_ignore (tmp_path ):
460
458
truss_dir_path : Path = tmp_path / "custom_model_truss_dir_with_truss_ignore"
461
- _ = init ( str ( truss_dir_path ) )
459
+ init_directory ( truss_dir_path )
462
460
(truss_dir_path / "random_folder_1" ).mkdir (parents = True , exist_ok = True )
463
461
(truss_dir_path / "random_folder_2" ).mkdir (parents = True , exist_ok = True )
464
462
(truss_dir_path / "random_file_1.txt" ).touch ()
@@ -478,19 +476,17 @@ def custom_model_truss_dir_with_truss_ignore(tmp_path):
478
476
@pytest .fixture
479
477
def custom_model_truss_dir_with_pre_and_post (tmp_path ):
480
478
dir_path = tmp_path / "custom_truss_with_pre_post"
481
- handle = init (str (dir_path ))
482
- handle .spec .model_class_filepath .write_text (
483
- CUSTOM_MODEL_CODE_WITH_PRE_AND_POST_PROCESS
484
- )
485
- handle .update_examples ([Example ("example1" , {"inputs" : [[0 ]]})])
479
+ th = TrussHandle (init_directory (dir_path ))
480
+ th .spec .model_class_filepath .write_text (CUSTOM_MODEL_CODE_WITH_PRE_AND_POST_PROCESS )
481
+ th .update_examples ([Example ("example1" , {"inputs" : [[0 ]]})])
486
482
yield dir_path
487
483
488
484
489
485
@pytest .fixture
490
486
def custom_model_truss_dir_with_bundled_packages (tmp_path ):
491
487
truss_dir_path : Path = tmp_path / "custom_model_truss_dir_with_bundled_packages"
492
- handle = init ( str (truss_dir_path ))
493
- handle .spec .model_class_filepath .write_text (CUSTOM_MODEL_CODE_USING_BUNDLED_PACKAGE )
488
+ th = TrussHandle ( init_directory (truss_dir_path ))
489
+ th .spec .model_class_filepath .write_text (CUSTOM_MODEL_CODE_USING_BUNDLED_PACKAGE )
494
490
packages_path = truss_dir_path / DEFAULT_BUNDLED_PACKAGES_DIR / "test_package"
495
491
packages_path .mkdir (parents = True )
496
492
with (packages_path / "test.py" ).open ("w" ) as file :
@@ -501,11 +497,9 @@ def custom_model_truss_dir_with_bundled_packages(tmp_path):
501
497
@pytest .fixture
502
498
def custom_model_truss_dir_with_pre_and_post_str_example (tmp_path ):
503
499
dir_path = tmp_path / "custom_truss_with_pre_post_str_example"
504
- handle = init (str (dir_path ))
505
- handle .spec .model_class_filepath .write_text (
506
- CUSTOM_MODEL_CODE_WITH_PRE_AND_POST_PROCESS
507
- )
508
- handle .update_examples (
500
+ th = TrussHandle (init_directory (dir_path ))
501
+ th .spec .model_class_filepath .write_text (CUSTOM_MODEL_CODE_WITH_PRE_AND_POST_PROCESS )
502
+ th .update_examples (
509
503
[
510
504
Example (
511
505
"example1" ,
@@ -525,29 +519,27 @@ def custom_model_truss_dir_with_pre_and_post_str_example(tmp_path):
525
519
@pytest .fixture
526
520
def custom_model_truss_dir_with_pre_and_post_description (tmp_path ):
527
521
dir_path = tmp_path / "custom_truss_with_pre_post"
528
- handle = init (str (dir_path ))
529
- handle .spec .model_class_filepath .write_text (
530
- CUSTOM_MODEL_CODE_WITH_PRE_AND_POST_PROCESS
531
- )
532
- handle .update_description ("This model adds 3 to all inputs" )
522
+ th = TrussHandle (init_directory (dir_path ))
523
+ th .spec .model_class_filepath .write_text (CUSTOM_MODEL_CODE_WITH_PRE_AND_POST_PROCESS )
524
+ th .update_description ("This model adds 3 to all inputs" )
533
525
yield dir_path
534
526
535
527
536
528
@pytest .fixture
537
529
def custom_model_truss_dir_for_gpu (tmp_path ):
538
530
dir_path = tmp_path / "custom_truss"
539
- handle = init ( str (dir_path ))
540
- handle .enable_gpu ()
541
- handle .spec .model_class_filepath .write_text (CUSTOM_MODEL_CODE_FOR_GPU_TESTING )
531
+ th = TrussHandle ( init_directory (dir_path ))
532
+ th .enable_gpu ()
533
+ th .spec .model_class_filepath .write_text (CUSTOM_MODEL_CODE_FOR_GPU_TESTING )
542
534
yield dir_path
543
535
544
536
545
537
@pytest .fixture
546
538
def custom_model_truss_dir_for_secrets (tmp_path ):
547
539
dir_path = tmp_path / "custom_truss"
548
- handle = init ( str (dir_path ))
549
- handle .add_secret ("secret_name" , "default_secret_value" )
550
- handle .spec .model_class_filepath .write_text (CUSTOM_MODEL_CODE_FOR_SECRETS_TESTING )
540
+ th = TrussHandle ( init_directory (dir_path ))
541
+ th .add_secret ("secret_name" , "default_secret_value" )
542
+ th .spec .model_class_filepath .write_text (CUSTOM_MODEL_CODE_FOR_SECRETS_TESTING )
551
543
yield dir_path
552
544
553
545
@@ -624,10 +616,10 @@ def _custom_model_from_code(
624
616
where_dir : Path , truss_name : str , model_code : str , handle_ops : callable = None
625
617
) -> Path :
626
618
dir_path = where_dir / truss_name
627
- handle = init ( str (dir_path ))
619
+ th = TrussHandle ( init_directory (dir_path ))
628
620
if handle_ops is not None :
629
- handle_ops (handle )
630
- handle .spec .model_class_filepath .write_text (model_code )
621
+ handle_ops (th )
622
+ th .spec .model_class_filepath .write_text (model_code )
631
623
return dir_path
632
624
633
625
0 commit comments