1
- #! /usr/bin/env python
1
+ from __future__ import annotations
2
+
2
3
import argparse
3
4
import os
4
5
import pathlib
@@ -96,6 +97,10 @@ def main(argv: tuple[str, ...] | None = None) -> int:
96
97
args = parser .parse_args (argv )
97
98
98
99
if args .root_dir :
100
+ if not args .config_file :
101
+ err ("using --root-dir but no config file specified (use --config-file)" )
102
+ return - 1
103
+
99
104
stage = Stage (
100
105
args .root_dir ,
101
106
config_file = args .config_file ,
@@ -123,31 +128,34 @@ def main(argv: tuple[str, ...] | None = None) -> int:
123
128
124
129
class Stage :
125
130
def __init__ (
126
- self , stage_dir , config_file , manifest : str | Iterator [str ] | None = None
131
+ self ,
132
+ stage_dir : str ,
133
+ config_file : str ,
134
+ manifest : str | Iterator [str ] | None = None ,
127
135
):
128
136
self ._stage_dir = stage_dir
129
137
self ._config_file = config_file
130
138
if manifest is None :
131
139
manifest = stage_dir
132
140
if isinstance (manifest , str ):
133
- self ._manifest = os .listdir (manifest )
141
+ self ._manifest = tuple ( os .listdir (manifest ) )
134
142
else :
135
- self ._manifest = list (manifest )
143
+ self ._manifest = tuple (manifest )
136
144
137
145
@property
138
- def dir (self ):
146
+ def dir (self ) -> str :
139
147
return self ._stage_dir
140
148
141
149
@property
142
- def manifest (self ):
150
+ def manifest (self ) -> tuple [ str , ...] :
143
151
return self ._manifest
144
152
145
153
@property
146
- def config_file (self ):
154
+ def config_file (self ) -> str :
147
155
return self ._config_file
148
156
149
157
@classmethod
150
- def from_entry_point (cls , entry_point ) :
158
+ def from_entry_point (cls , entry_point : str ) -> Stage :
151
159
module_name , class_name = parse_entry_point (entry_point )
152
160
try :
153
161
Bmi = load_component (module_name , class_name )
@@ -156,7 +164,7 @@ def from_entry_point(cls, entry_point):
156
164
f"unable to import BMI implementation, { class_name } ,"
157
165
f" from { module_name } "
158
166
)
159
- return 1
167
+ raise
160
168
161
169
stage_dir = tempfile .mkdtemp ()
162
170
manifest = stage (Bmi , str (stage_dir ))
@@ -168,7 +176,7 @@ def from_entry_point(cls, entry_point):
168
176
def run_the_tests (
169
177
entry_point : str ,
170
178
config_file : str ,
171
- manifest : str ,
179
+ manifest : tuple [ str , ...] ,
172
180
bmi_version : str = "2.0" ,
173
181
pytest_help : bool = False ,
174
182
) -> int :
@@ -229,7 +237,8 @@ def __call__(
229
237
230
238
path = values
231
239
232
- if not os .path .isdir (path ):
240
+ # if not os.path.isdir(path):
241
+ if not os .path .exists (path ):
233
242
parser .error (f"{ path } : path does not exist" )
234
243
else :
235
244
setattr (namespace , self .dest , path )
@@ -241,3 +250,7 @@ def _tree(files):
241
250
for p , fname in zip (prefix , files ):
242
251
tree .append (f"{ p } { fname } " )
243
252
return os .linesep .join (tree )
253
+
254
+
255
+ if __name__ == "__main__" :
256
+ SystemExit (main ())
0 commit comments