@@ -1454,7 +1454,7 @@ def _find_library_internal(
14541454 robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
14551455
14561456 try :
1457- name = robot_variables .replace_string (name . replace ( " \\ " , " \\ \\ " ) , ignore_errors = False )
1457+ name = robot_variables .replace_string (name , ignore_errors = False )
14581458 except DataError as error :
14591459 raise DataError (f"Replacing variables from setting 'Library' failed: { error } " )
14601460
@@ -1518,6 +1518,7 @@ def get_library_doc(
15181518) -> LibraryDoc :
15191519 import robot .running .testlibraries
15201520 from robot .libdocpkg .robotbuilder import KeywordDocBuilder
1521+ from robot .libraries import STDLIBS
15211522 from robot .output import LOGGER
15221523 from robot .output .loggerhelper import AbstractLogger
15231524 from robot .running .outputcapture import OutputCapturer
@@ -1604,7 +1605,14 @@ def get_test_library(
16041605 python_path = sys .path ,
16051606 )
16061607
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+
16081616 library_name_path = Path (import_name )
16091617 if library_name_path .exists ():
16101618 library_name = library_name_path .stem
@@ -1821,7 +1829,7 @@ def _find_variables_internal(
18211829 robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
18221830
18231831 try :
1824- name = robot_variables .replace_string (name . replace ( " \\ " , " \\ \\ " ) , ignore_errors = False )
1832+ name = robot_variables .replace_string (name , ignore_errors = False )
18251833 except DataError as error :
18261834 raise DataError (f"Replacing variables from setting 'Variables' failed: { error } " )
18271835
@@ -2094,7 +2102,7 @@ def find_file(
20942102
20952103 robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
20962104 try :
2097- name = robot_variables .replace_string (name . replace ( " \\ " , " \\ \\ " ) , ignore_errors = False )
2105+ name = robot_variables .replace_string (name , ignore_errors = False )
20982106 except DataError as error :
20992107 raise DataError (f"Replacing variables from setting '{ file_type } ' failed: { error } " )
21002108
@@ -2118,7 +2126,11 @@ class CompleteResult(NamedTuple):
21182126
21192127
21202128def 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
21222134
21232135
21242136def iter_module_names (name : Optional [str ] = None ) -> Iterator [str ]:
@@ -2154,13 +2166,18 @@ def iter_modules_from_python_path(
21542166
21552167 path = path .replace ("." , os .sep ) if path is not None and not path .startswith (("." , "/" , os .sep )) else path
21562168
2169+ needs_init = False
21572170 if path is None :
21582171 paths = sys .path
21592172 else :
21602173 paths = [str (Path (s , path )) for s in sys .path ]
2174+ needs_init = True
21612175
21622176 for e in [Path (p ) for p in set (paths )]:
21632177 if e .is_dir ():
2178+ if needs_init and not (e / "__init__.py" ).is_file ():
2179+ continue
2180+
21642181 for f in e .iterdir ():
21652182 if not f .name .startswith (("_" , "." )) and (
21662183 f .is_file ()
@@ -2199,12 +2216,14 @@ def complete_library_import(
21992216 if name is not None :
22002217 robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
22012218
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 )
22032222
2204- if name is None or not name . startswith (( "." , "/" , os . sep )) :
2223+ if name is None or not file_like :
22052224 result += list (iter_modules_from_python_path (name ))
22062225
2207- if name is None or ( is_file_like ( name ) and ( name . endswith (( "/" , os . sep )))) :
2226+ if name is None or file_like :
22082227 name_path = Path (name if name else base_dir )
22092228 if name_path .is_absolute ():
22102229 path = name_path
@@ -2264,7 +2283,7 @@ def complete_resource_import(
22642283 if name is not None :
22652284 robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
22662285
2267- name = robot_variables .replace_string (name . replace ( " \\ " , " \\ \\ " ) , ignore_errors = True )
2286+ name = robot_variables .replace_string (name , ignore_errors = True )
22682287
22692288 if name is None or not name .startswith ("." ) and not name .startswith ("/" ) and not name .startswith (os .sep ):
22702289 result += list (iter_resources_from_python_path (name ))
@@ -2299,14 +2318,18 @@ def iter_variables_from_python_path(
22992318
23002319 path = path .replace ("." , os .sep ) if path is not None and not path .startswith (("." , "/" , os .sep )) else path
23012320
2321+ needs_init = False
23022322 if path is None :
23032323 paths = sys .path
23042324 else :
23052325 paths = [str (Path (s , path )) for s in sys .path ]
2326+ needs_init = True
23062327
23072328 for e in [Path (p ) for p in set (paths )]:
23082329 if e .is_dir ():
23092330 for f in e .iterdir ():
2331+ if needs_init and not (e / "__init__.py" ).is_file ():
2332+ continue
23102333 if not f .name .startswith (("_" , "." )) and (
23112334 f .is_file ()
23122335 and f .suffix in ALLOWED_VARIABLES_FILE_EXTENSIONS
@@ -2360,12 +2383,14 @@ def complete_variables_import(
23602383 if name is not None :
23612384 robot_variables = resolve_robot_variables (working_dir , base_dir , command_line_variables , variables )
23622385
2363- name = robot_variables .replace_string (name . replace ( " \\ " , " \\ \\ " ) , ignore_errors = True )
2386+ name = robot_variables .replace_string (name , ignore_errors = True )
23642387
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 :
23662391 result += list (iter_variables_from_python_path (name ))
23672392
2368- if name is None or name . startswith (( "." , "/" , os . sep )) :
2393+ if name is None or file_like :
23692394 name_path = Path (name if name else base_dir )
23702395 if name_path .is_absolute ():
23712396 path = name_path .resolve ()
0 commit comments