@@ -2155,44 +2155,33 @@ def iter_module_names(name: Optional[str] = None) -> Iterator[str]:
2155
2155
yield e .name
2156
2156
2157
2157
2158
- NOT_WANTED_FILE_EXTENSIONS = [".dist-info" ]
2158
+ NOT_WANTED_DIR_EXTENSIONS = [".dist-info" ]
2159
2159
2160
2160
2161
2161
def iter_modules_from_python_path (
2162
2162
path : Optional [str ] = None ,
2163
2163
) -> Iterator [CompleteResult ]:
2164
- allow_modules = True if not path or not ("/" in path or os .sep in path ) else False
2165
- allow_files = True if not path or "/" in path or os .sep in path else False
2166
-
2167
2164
path = path .replace ("." , os .sep ) if path is not None and not path .startswith (("." , "/" , os .sep )) else path
2168
2165
2169
- needs_init = False
2170
2166
if path is None :
2171
2167
paths = sys .path
2172
2168
else :
2173
2169
paths = [str (Path (s , path )) for s in sys .path ]
2174
- needs_init = True
2175
2170
2176
2171
for e in [Path (p ) for p in set (paths )]:
2177
2172
if e .is_dir ():
2178
- if needs_init and not (e / "__init__.py" ).is_file ():
2179
- continue
2180
-
2181
2173
for f in e .iterdir ():
2182
2174
if not f .name .startswith (("_" , "." )) and (
2183
2175
f .is_file ()
2184
2176
and f .suffix in ALLOWED_LIBRARY_FILE_EXTENSIONS
2185
2177
or f .is_dir ()
2186
- and f .suffix not in NOT_WANTED_FILE_EXTENSIONS
2178
+ and f .suffix not in NOT_WANTED_DIR_EXTENSIONS
2187
2179
):
2188
2180
if f .is_dir ():
2189
2181
yield CompleteResult (f .name , CompleteResultKind .MODULE )
2190
2182
2191
2183
if f .is_file ():
2192
- if allow_modules :
2193
- yield CompleteResult (f .stem , CompleteResultKind .MODULE )
2194
- if allow_files :
2195
- yield CompleteResult (f .name , CompleteResultKind .FILE )
2184
+ yield CompleteResult (f .stem , CompleteResultKind .MODULE )
2196
2185
2197
2186
2198
2187
def complete_library_import (
@@ -2201,7 +2190,7 @@ def complete_library_import(
2201
2190
base_dir : str = "." ,
2202
2191
command_line_variables : Optional [Dict [str , Optional [Any ]]] = None ,
2203
2192
variables : Optional [Dict [str , Optional [Any ]]] = None ,
2204
- ) -> Optional [ List [CompleteResult ] ]:
2193
+ ) -> List [CompleteResult ]:
2205
2194
_update_env (working_dir )
2206
2195
2207
2196
result : List [CompleteResult ] = []
@@ -2225,23 +2214,32 @@ def complete_library_import(
2225
2214
2226
2215
if name is None or file_like :
2227
2216
name_path = Path (name if name else base_dir )
2228
- if name_path .is_absolute ():
2229
- path = name_path
2217
+ if name and name_path .is_absolute ():
2218
+ paths = [ name_path ]
2230
2219
else :
2231
- path = Path (base_dir , name ) if name else Path (base_dir )
2220
+ paths = [
2221
+ Path (base_dir , name ) if name else Path (base_dir ),
2222
+ * ((Path (s ) for s in sys .path ) if not name else []),
2223
+ * ((Path (s , name ) for s in sys .path ) if name and not name .startswith ("." ) else []),
2224
+ ]
2232
2225
2233
- path = path .resolve ()
2226
+ for p in paths :
2227
+ path = p .resolve ()
2234
2228
2235
- if path .exists () and path .is_dir ():
2236
- result += [
2237
- CompleteResult (
2238
- str (f .name ),
2239
- CompleteResultKind .FILE if f .is_file () else CompleteResultKind .FOLDER ,
2240
- )
2241
- for f in path .iterdir ()
2242
- if not f .name .startswith (("_" , "." ))
2243
- and (f .is_dir () or (f .is_file () and f .suffix in ALLOWED_LIBRARY_FILE_EXTENSIONS ))
2244
- ]
2229
+ if path .exists () and path .is_dir ():
2230
+ result += [
2231
+ CompleteResult (
2232
+ str (f .name ),
2233
+ CompleteResultKind .FILE if f .is_file () else CompleteResultKind .FOLDER ,
2234
+ )
2235
+ for f in path .iterdir ()
2236
+ if not f .name .startswith (("_" , "." ))
2237
+ and (
2238
+ (f .is_file () and f .suffix in ALLOWED_LIBRARY_FILE_EXTENSIONS )
2239
+ or f .is_dir ()
2240
+ and f .suffix not in NOT_WANTED_DIR_EXTENSIONS
2241
+ )
2242
+ ]
2245
2243
2246
2244
return list (set (result ))
2247
2245
@@ -2261,7 +2259,7 @@ def iter_resources_from_python_path(
2261
2259
f .is_file ()
2262
2260
and f .suffix in ALLOWED_RESOURCE_FILE_EXTENSIONS
2263
2261
or f .is_dir ()
2264
- and f .suffix not in NOT_WANTED_FILE_EXTENSIONS
2262
+ and f .suffix not in NOT_WANTED_DIR_EXTENSIONS
2265
2263
):
2266
2264
yield CompleteResult (
2267
2265
f .name ,
@@ -2309,66 +2307,6 @@ def complete_resource_import(
2309
2307
return list (set (result ))
2310
2308
2311
2309
2312
- def iter_variables_from_python_path (
2313
- path : Optional [str ] = None ,
2314
- ) -> Iterator [CompleteResult ]:
2315
- if get_robot_version () >= (5 , 0 ):
2316
- allow_modules = True if not path or not ("/" in path or os .sep in path ) else False
2317
- allow_files = True if not path or "/" in path or os .sep in path else False
2318
-
2319
- path = path .replace ("." , os .sep ) if path is not None and not path .startswith (("." , "/" , os .sep )) else path
2320
-
2321
- needs_init = False
2322
- if path is None :
2323
- paths = sys .path
2324
- else :
2325
- paths = [str (Path (s , path )) for s in sys .path ]
2326
- needs_init = True
2327
-
2328
- for e in [Path (p ) for p in set (paths )]:
2329
- if e .is_dir ():
2330
- for f in e .iterdir ():
2331
- if needs_init and not (e / "__init__.py" ).is_file ():
2332
- continue
2333
- if not f .name .startswith (("_" , "." )) and (
2334
- f .is_file ()
2335
- and f .suffix in ALLOWED_VARIABLES_FILE_EXTENSIONS
2336
- or f .is_dir ()
2337
- and f .suffix not in NOT_WANTED_FILE_EXTENSIONS
2338
- ):
2339
- if f .is_dir ():
2340
- yield CompleteResult (f .name , CompleteResultKind .MODULE )
2341
-
2342
- if f .is_file ():
2343
- if allow_modules and f .suffix .lower () not in [
2344
- ".yaml" ,
2345
- ".yml" ,
2346
- * [".json" if get_robot_version () >= (6 , 1 ) else []],
2347
- ]:
2348
- yield CompleteResult (f .stem , CompleteResultKind .VARIABLES_MODULE )
2349
- if allow_files :
2350
- yield CompleteResult (f .name , CompleteResultKind .VARIABLES )
2351
- else :
2352
- if path is None :
2353
- paths = sys .path
2354
- else :
2355
- paths = [str (Path (s , path )) for s in sys .path ]
2356
-
2357
- for e in [Path (p ) for p in set (paths )]:
2358
- if e .is_dir ():
2359
- for f in e .iterdir ():
2360
- if not f .name .startswith (("_" , "." )) and (
2361
- f .is_file ()
2362
- and f .suffix in ALLOWED_VARIABLES_FILE_EXTENSIONS
2363
- or f .is_dir ()
2364
- and f .suffix not in NOT_WANTED_FILE_EXTENSIONS
2365
- ):
2366
- yield CompleteResult (
2367
- f .name ,
2368
- CompleteResultKind .VARIABLES if f .is_file () else CompleteResultKind .FOLDER ,
2369
- )
2370
-
2371
-
2372
2310
def complete_variables_import (
2373
2311
name : Optional [str ],
2374
2312
working_dir : str = "." ,
@@ -2385,29 +2323,40 @@ def complete_variables_import(
2385
2323
2386
2324
name = robot_variables .replace_string (name , ignore_errors = True )
2387
2325
2388
- file_like = is_file_like (name )
2326
+ file_like = get_robot_version () < ( 5 , 0 ) or is_file_like (name )
2389
2327
2390
- if name is None or not file_like :
2391
- result += list (iter_variables_from_python_path (name ))
2328
+ if get_robot_version () >= ( 5 , 0 ) and ( name is None or not file_like ) :
2329
+ result += list (iter_modules_from_python_path (name ))
2392
2330
2393
2331
if name is None or file_like :
2394
2332
name_path = Path (name if name else base_dir )
2395
- if name_path .is_absolute ():
2396
- path = name_path . resolve ()
2333
+ if name and name_path .is_absolute ():
2334
+ paths = [ name_path ]
2397
2335
else :
2398
- path = Path (base_dir , name if name else base_dir ).resolve ()
2399
-
2400
- if path .exists () and (path .is_dir ()):
2401
- result += [
2402
- CompleteResult (
2403
- str (f .name ),
2404
- CompleteResultKind .VARIABLES if f .is_file () else CompleteResultKind .FOLDER ,
2405
- )
2406
- for f in path .iterdir ()
2407
- if not f .name .startswith (("_" , "." ))
2408
- and (f .is_dir () or (f .is_file () and f .suffix in ALLOWED_VARIABLES_FILE_EXTENSIONS ))
2336
+ paths = [
2337
+ Path (base_dir , name ) if name else Path (base_dir ),
2338
+ * ((Path (s ) for s in sys .path ) if not name else []),
2339
+ * ((Path (s , name ) for s in sys .path ) if name and not name .startswith ("." ) else []),
2409
2340
]
2410
2341
2342
+ for p in paths :
2343
+ path = p .resolve ()
2344
+
2345
+ if path .exists () and path .is_dir ():
2346
+ result += [
2347
+ CompleteResult (
2348
+ str (f .name ),
2349
+ CompleteResultKind .FILE if f .is_file () else CompleteResultKind .FOLDER ,
2350
+ )
2351
+ for f in path .iterdir ()
2352
+ if not f .name .startswith (("_" , "." ))
2353
+ and (
2354
+ (f .is_file () and f .suffix in ALLOWED_VARIABLES_FILE_EXTENSIONS )
2355
+ or f .is_dir ()
2356
+ and f .suffix not in NOT_WANTED_DIR_EXTENSIONS
2357
+ )
2358
+ ]
2359
+
2411
2360
return list (set (result ))
2412
2361
2413
2362
0 commit comments