@@ -1454,7 +1454,7 @@ def _find_library_internal(
1454
1454
robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
1455
1455
1456
1456
try :
1457
- name = robot_variables .replace_string (name . replace ( " \\ " , " \\ \\ " ) , ignore_errors = False )
1457
+ name = robot_variables .replace_string (name , ignore_errors = False )
1458
1458
except DataError as error :
1459
1459
raise DataError (f"Replacing variables from setting 'Library' failed: { error } " )
1460
1460
@@ -1518,6 +1518,7 @@ def get_library_doc(
1518
1518
) -> LibraryDoc :
1519
1519
import robot .running .testlibraries
1520
1520
from robot .libdocpkg .robotbuilder import KeywordDocBuilder
1521
+ from robot .libraries import STDLIBS
1521
1522
from robot .output import LOGGER
1522
1523
from robot .output .loggerhelper import AbstractLogger
1523
1524
from robot .running .outputcapture import OutputCapturer
@@ -1604,7 +1605,14 @@ def get_test_library(
1604
1605
python_path = sys .path ,
1605
1606
)
1606
1607
1607
- library_name = name
1608
+ if name in STDLIBS and import_name .startswith (ROBOT_LIBRARY_PACKAGE + "." ):
1609
+ library_name = name
1610
+ else :
1611
+ if import_name .startswith (ROBOT_LIBRARY_PACKAGE + "." ):
1612
+ library_name = import_name [len (ROBOT_LIBRARY_PACKAGE + "." ) :]
1613
+ else :
1614
+ library_name = import_name
1615
+
1608
1616
library_name_path = Path (import_name )
1609
1617
if library_name_path .exists ():
1610
1618
library_name = library_name_path .stem
@@ -1821,7 +1829,7 @@ def _find_variables_internal(
1821
1829
robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
1822
1830
1823
1831
try :
1824
- name = robot_variables .replace_string (name . replace ( " \\ " , " \\ \\ " ) , ignore_errors = False )
1832
+ name = robot_variables .replace_string (name , ignore_errors = False )
1825
1833
except DataError as error :
1826
1834
raise DataError (f"Replacing variables from setting 'Variables' failed: { error } " )
1827
1835
@@ -2094,7 +2102,7 @@ def find_file(
2094
2102
2095
2103
robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
2096
2104
try :
2097
- name = robot_variables .replace_string (name . replace ( " \\ " , " \\ \\ " ) , ignore_errors = False )
2105
+ name = robot_variables .replace_string (name , ignore_errors = False )
2098
2106
except DataError as error :
2099
2107
raise DataError (f"Replacing variables from setting '{ file_type } ' failed: { error } " )
2100
2108
@@ -2118,7 +2126,11 @@ class CompleteResult(NamedTuple):
2118
2126
2119
2127
2120
2128
def is_file_like (name : Optional [str ]) -> bool :
2121
- return name is not None and (name .startswith (("." , "/" , os .sep )) or "/" in name or os .sep in name )
2129
+ if name is None :
2130
+ return False
2131
+
2132
+ base , filename = os .path .split (name )
2133
+ return name .startswith ("." ) or bool (base ) and filename != name
2122
2134
2123
2135
2124
2136
def iter_module_names (name : Optional [str ] = None ) -> Iterator [str ]:
@@ -2154,13 +2166,18 @@ def iter_modules_from_python_path(
2154
2166
2155
2167
path = path .replace ("." , os .sep ) if path is not None and not path .startswith (("." , "/" , os .sep )) else path
2156
2168
2169
+ needs_init = False
2157
2170
if path is None :
2158
2171
paths = sys .path
2159
2172
else :
2160
2173
paths = [str (Path (s , path )) for s in sys .path ]
2174
+ needs_init = True
2161
2175
2162
2176
for e in [Path (p ) for p in set (paths )]:
2163
2177
if e .is_dir ():
2178
+ if needs_init and not (e / "__init__.py" ).is_file ():
2179
+ continue
2180
+
2164
2181
for f in e .iterdir ():
2165
2182
if not f .name .startswith (("_" , "." )) and (
2166
2183
f .is_file ()
@@ -2199,12 +2216,14 @@ def complete_library_import(
2199
2216
if name is not None :
2200
2217
robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
2201
2218
2202
- name = robot_variables .replace_string (name .replace ("\\ " , "\\ \\ " ), ignore_errors = True )
2219
+ name = robot_variables .replace_string (name , ignore_errors = True )
2220
+
2221
+ file_like = is_file_like (name )
2203
2222
2204
- if name is None or not name . startswith (( "." , "/" , os . sep )) :
2223
+ if name is None or not file_like :
2205
2224
result += list (iter_modules_from_python_path (name ))
2206
2225
2207
- if name is None or ( is_file_like ( name ) and ( name . endswith (( "/" , os . sep )))) :
2226
+ if name is None or file_like :
2208
2227
name_path = Path (name if name else base_dir )
2209
2228
if name_path .is_absolute ():
2210
2229
path = name_path
@@ -2264,7 +2283,7 @@ def complete_resource_import(
2264
2283
if name is not None :
2265
2284
robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
2266
2285
2267
- name = robot_variables .replace_string (name . replace ( " \\ " , " \\ \\ " ) , ignore_errors = True )
2286
+ name = robot_variables .replace_string (name , ignore_errors = True )
2268
2287
2269
2288
if name is None or not name .startswith ("." ) and not name .startswith ("/" ) and not name .startswith (os .sep ):
2270
2289
result += list (iter_resources_from_python_path (name ))
@@ -2299,14 +2318,18 @@ def iter_variables_from_python_path(
2299
2318
2300
2319
path = path .replace ("." , os .sep ) if path is not None and not path .startswith (("." , "/" , os .sep )) else path
2301
2320
2321
+ needs_init = False
2302
2322
if path is None :
2303
2323
paths = sys .path
2304
2324
else :
2305
2325
paths = [str (Path (s , path )) for s in sys .path ]
2326
+ needs_init = True
2306
2327
2307
2328
for e in [Path (p ) for p in set (paths )]:
2308
2329
if e .is_dir ():
2309
2330
for f in e .iterdir ():
2331
+ if needs_init and not (e / "__init__.py" ).is_file ():
2332
+ continue
2310
2333
if not f .name .startswith (("_" , "." )) and (
2311
2334
f .is_file ()
2312
2335
and f .suffix in ALLOWED_VARIABLES_FILE_EXTENSIONS
@@ -2360,12 +2383,14 @@ def complete_variables_import(
2360
2383
if name is not None :
2361
2384
robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
2362
2385
2363
- name = robot_variables .replace_string (name . replace ( " \\ " , " \\ \\ " ) , ignore_errors = True )
2386
+ name = robot_variables .replace_string (name , ignore_errors = True )
2364
2387
2365
- if name is None or not name .startswith ("." ) and not name .startswith ("/" ) and not name .startswith (os .sep ):
2388
+ file_like = is_file_like (name )
2389
+
2390
+ if name is None or not file_like :
2366
2391
result += list (iter_variables_from_python_path (name ))
2367
2392
2368
- if name is None or name . startswith (( "." , "/" , os . sep )) :
2393
+ if name is None or file_like :
2369
2394
name_path = Path (name if name else base_dir )
2370
2395
if name_path .is_absolute ():
2371
2396
path = name_path .resolve ()
0 commit comments