9
9
from typing import Dict , List , Optional , Sequence , Type , Union
10
10
11
11
import executorch .devtools .bundled_program .schema as bp_schema
12
- from pyre_extensions import none_throws
13
12
14
13
import executorch .exir .schema as core_schema
15
14
@@ -44,10 +43,12 @@ class BundledProgram:
44
43
45
44
def __init__ (
46
45
self ,
47
- executorch_program : Optional [Union [
48
- ExecutorchProgram ,
49
- ExecutorchProgramManager ,
50
- ]],
46
+ executorch_program : Optional [
47
+ Union [
48
+ ExecutorchProgram ,
49
+ ExecutorchProgramManager ,
50
+ ]
51
+ ],
51
52
method_test_suites : Sequence [MethodTestSuite ],
52
53
pte_file_path : Optional [str ] = None ,
53
54
):
@@ -59,18 +60,24 @@ def __init__(
59
60
pte_file_path: The path to pte file to deserialize program if executorch_program is not provided.
60
61
"""
61
62
if not executorch_program and not pte_file_path :
62
- raise RuntimeError ("Either executorch_program or pte_file_path must be provided" )
63
+ raise RuntimeError (
64
+ "Either executorch_program or pte_file_path must be provided"
65
+ )
63
66
64
67
if executorch_program and pte_file_path :
65
- raise RuntimeError ("Only one of executorch_program or pte_file_path can be used" )
68
+ raise RuntimeError (
69
+ "Only one of executorch_program or pte_file_path can be used"
70
+ )
66
71
67
72
method_test_suites = sorted (method_test_suites , key = lambda x : x .method_name )
68
73
if executorch_program :
69
74
self ._assert_valid_bundle (executorch_program , method_test_suites )
70
- self .executorch_program : Optional [Union [
71
- ExecutorchProgram ,
72
- ExecutorchProgramManager ,
73
- ]] = executorch_program
75
+ self .executorch_program : Optional [
76
+ Union [
77
+ ExecutorchProgram ,
78
+ ExecutorchProgramManager ,
79
+ ]
80
+ ] = executorch_program
74
81
self ._pte_file_path : Optional [str ] = pte_file_path
75
82
76
83
self .method_test_suites = method_test_suites
@@ -88,7 +95,8 @@ def serialize_to_schema(self) -> bp_schema.BundledProgram:
88
95
if self .executorch_program :
89
96
program = self ._extract_program (self .executorch_program )
90
97
else :
91
- with open (none_throws (self ._pte_file_path ), "rb" ) as f :
98
+ assert self ._pte_file_path is not None
99
+ with open (self ._pte_file_path , "rb" ) as f :
92
100
p_bytes = f .read ()
93
101
program = _deserialize_pte_binary (p_bytes )
94
102
0 commit comments