12
12
Any ,
13
13
Callable ,
14
14
Coroutine ,
15
+ Dict ,
15
16
List ,
16
17
Optional ,
17
18
Tuple ,
52
53
get_library_doc ,
53
54
get_variables_doc ,
54
55
is_embedded_keyword ,
56
+ resolve_variable ,
55
57
)
56
58
57
59
RESOURCE_EXTENSIONS = (".resource" , ".robot" , ".txt" , ".tsv" , ".rst" , ".rest" )
@@ -475,8 +477,8 @@ def get_command_line_variables(self) -> List[VariableDefinition]:
475
477
self ._command_line_variables = []
476
478
else :
477
479
self ._command_line_variables = [
478
- CommandLineVariableDefinition (0 , 0 , 0 , 0 , "" , f"${{{ k } }}" , None )
479
- for k in self .config .variables .keys ()
480
+ CommandLineVariableDefinition (0 , 0 , 0 , 0 , "" , f"${{{ k } }}" , None , has_value = True , value = ( v ,) )
481
+ for k , v in self .config .variables .items ()
480
482
]
481
483
482
484
return self ._command_line_variables
@@ -616,7 +618,7 @@ async def remove(k: _VariablesEntryKey, e: _VariablesEntry) -> None:
616
618
pass
617
619
618
620
@_logger .call
619
- async def find_library (self , name : str , base_dir : str ) -> str :
621
+ async def find_library (self , name : str , base_dir : str , variables : Optional [ Dict [ str , Any ]] = None ) -> str :
620
622
return await asyncio .wait_for (
621
623
asyncio .get_running_loop ().run_in_executor (
622
624
self .process_pool ,
@@ -626,17 +628,26 @@ async def find_library(self, name: str, base_dir: str) -> str:
626
628
base_dir ,
627
629
self .config .python_path if self .config is not None else None ,
628
630
self .config .env if self .config is not None else None ,
629
- self .config .variables if self .config is not None else None ,
631
+ variables if variables is not None else self .config .variables if self .config is not None else None ,
630
632
),
631
633
FIND_FILE_TIME_OUT ,
632
634
)
633
635
634
636
@_logger .call
635
637
async def get_libdoc_for_library_import (
636
- self , name : str , args : Tuple [Any , ...], base_dir : str , sentinel : Any = None
638
+ self ,
639
+ name : str ,
640
+ args : Tuple [Any , ...],
641
+ base_dir : str ,
642
+ sentinel : Any = None ,
643
+ variables : Optional [Dict [str , Any ]] = None ,
637
644
) -> LibraryDoc :
638
645
639
- source = await self .find_library (name , base_dir )
646
+ source = await self .find_library (
647
+ name ,
648
+ base_dir ,
649
+ variables ,
650
+ )
640
651
641
652
async def _get_libdoc () -> LibraryDoc :
642
653
self ._logger .debug (lambda : f"Load Library { source } { repr (args )} " )
@@ -651,7 +662,7 @@ async def _get_libdoc() -> LibraryDoc:
651
662
base_dir ,
652
663
self .config .python_path if self .config is not None else None ,
653
664
self .config .env if self .config is not None else None ,
654
- self .config .variables if self .config is not None else None ,
665
+ variables if variables is not None else self .config .variables if self .config is not None else None ,
655
666
),
656
667
LOAD_LIBRARY_TIME_OUT ,
657
668
)
@@ -785,9 +796,19 @@ def _create_handler(self, kw: Any) -> Any:
785
796
786
797
@_logger .call
787
798
async def get_libdoc_for_variables_import (
788
- self , name : str , args : Tuple [Any , ...], base_dir : str , sentinel : Any = None
799
+ self ,
800
+ name : str ,
801
+ args : Tuple [Any , ...],
802
+ base_dir : str ,
803
+ sentinel : Any = None ,
804
+ variables : Optional [Dict [str , Any ]] = None ,
789
805
) -> VariablesDoc :
790
- source = await self .find_file (name , base_dir , "Variables" )
806
+ source = await self .find_file (
807
+ name ,
808
+ base_dir ,
809
+ "Variables" ,
810
+ variables ,
811
+ )
791
812
792
813
async def _get_libdoc () -> VariablesDoc :
793
814
self ._logger .debug (lambda : f"Load variables { source } { repr (args )} " )
@@ -829,7 +850,9 @@ async def _get_libdoc() -> VariablesDoc:
829
850
return await entry .get_libdoc ()
830
851
831
852
@_logger .call
832
- async def find_file (self , name : str , base_dir : str , file_type : str = "Resource" ) -> str :
853
+ async def find_file (
854
+ self , name : str , base_dir : str , file_type : str = "Resource" , variables : Optional [Dict [str , Any ]] = None
855
+ ) -> str :
833
856
result = await asyncio .wait_for (
834
857
asyncio .get_running_loop ().run_in_executor (
835
858
self .process_pool ,
@@ -839,7 +862,7 @@ async def find_file(self, name: str, base_dir: str, file_type: str = "Resource")
839
862
base_dir ,
840
863
self .config .python_path if self .config is not None else None ,
841
864
self .config .env if self .config is not None else None ,
842
- self .config .variables if self .config is not None else None ,
865
+ variables if variables is not None else self .config .variables if self .config is not None else None ,
843
866
file_type ,
844
867
),
845
868
FIND_FILE_TIME_OUT ,
@@ -848,8 +871,10 @@ async def find_file(self, name: str, base_dir: str, file_type: str = "Resource")
848
871
return result
849
872
850
873
@_logger .call
851
- async def _get_entry_for_resource_import (self , name : str , base_dir : str , sentinel : Any = None ) -> _ResourcesEntry :
852
- source = await self .find_file (name , base_dir )
874
+ async def _get_entry_for_resource_import (
875
+ self , name : str , base_dir : str , sentinel : Any = None , variables : Optional [Dict [str , Any ]] = None
876
+ ) -> _ResourcesEntry :
877
+ source = await self .find_file (name , base_dir , variables = variables )
853
878
854
879
async def _get_document () -> TextDocument :
855
880
self ._logger .debug (lambda : f"Load resource { name } from source { source } " )
@@ -880,23 +905,38 @@ async def _get_document() -> TextDocument:
880
905
881
906
return entry
882
907
883
- @_logger .call
884
- async def get_document_for_resource_import (self , name : str , base_dir : str , sentinel : Any = None ) -> TextDocument :
885
- entry = await self ._get_entry_for_resource_import (name , base_dir , sentinel )
908
+ async def get_namespace_and_libdoc_for_resource_import (
909
+ self ,
910
+ name : str ,
911
+ base_dir : str ,
912
+ sentinel : Any = None ,
913
+ variables : Optional [Dict [str , Any ]] = None ,
914
+ ) -> Tuple ["Namespace" , LibraryDoc ]:
915
+ entry = await self ._get_entry_for_resource_import (name , base_dir , sentinel , variables )
886
916
887
- return await entry .get_document ()
917
+ return await entry .get_namespace (), await entry . get_libdoc ()
888
918
889
- async def get_namespace_for_resource_import (self , name : str , base_dir : str , sentinel : Any = None ) -> "Namespace" :
890
- entry = await self ._get_entry_for_resource_import (name , base_dir , sentinel )
919
+ async def get_namespace_for_resource_import (
920
+ self ,
921
+ name : str ,
922
+ base_dir : str ,
923
+ sentinel : Any = None ,
924
+ variables : Optional [Dict [str , Any ]] = None ,
925
+ ) -> "Namespace" :
926
+ entry = await self ._get_entry_for_resource_import (name , base_dir , sentinel , variables )
891
927
892
928
return await entry .get_namespace ()
893
929
894
- async def get_libdoc_for_resource_import (self , name : str , base_dir : str , sentinel : Any = None ) -> LibraryDoc :
895
- entry = await self ._get_entry_for_resource_import (name , base_dir , sentinel )
930
+ async def get_libdoc_for_resource_import (
931
+ self , name : str , base_dir : str , sentinel : Any = None , variables : Optional [Dict [str , Any ]] = None
932
+ ) -> LibraryDoc :
933
+ entry = await self ._get_entry_for_resource_import (name , base_dir , sentinel , variables )
896
934
897
935
return await entry .get_libdoc ()
898
936
899
- async def complete_library_import (self , name : Optional [str ], base_dir : str = "." ) -> Optional [List [CompleteResult ]]:
937
+ async def complete_library_import (
938
+ self , name : Optional [str ], base_dir : str = "." , variables : Optional [Dict [str , Any ]] = None
939
+ ) -> Optional [List [CompleteResult ]]:
900
940
result = await asyncio .wait_for (
901
941
asyncio .get_running_loop ().run_in_executor (
902
942
self .process_pool ,
@@ -906,15 +946,15 @@ async def complete_library_import(self, name: Optional[str], base_dir: str = "."
906
946
base_dir ,
907
947
self .config .python_path if self .config is not None else None ,
908
948
self .config .env if self .config is not None else None ,
909
- self .config .variables if self .config is not None else None ,
949
+ variables if variables is not None else self .config .variables if self .config is not None else None ,
910
950
),
911
951
COMPLETE_LIBRARY_IMPORT_TIME_OUT ,
912
952
)
913
953
914
954
return result
915
955
916
956
async def complete_resource_import (
917
- self , name : Optional [str ], base_dir : str = "."
957
+ self , name : Optional [str ], base_dir : str = "." , variables : Optional [ Dict [ str , Any ]] = None
918
958
) -> Optional [List [CompleteResult ]]:
919
959
result = await asyncio .wait_for (
920
960
asyncio .get_running_loop ().run_in_executor (
@@ -925,15 +965,15 @@ async def complete_resource_import(
925
965
base_dir ,
926
966
self .config .python_path if self .config is not None else None ,
927
967
self .config .env if self .config is not None else None ,
928
- self .config .variables if self .config is not None else None ,
968
+ variables if variables is not None else self .config .variables if self .config is not None else None ,
929
969
),
930
970
COMPLETE_RESOURCE_IMPORT_TIME_OUT ,
931
971
)
932
972
933
973
return result
934
974
935
975
async def complete_variables_import (
936
- self , name : Optional [str ], base_dir : str = "."
976
+ self , name : Optional [str ], base_dir : str = "." , variables : Optional [ Dict [ str , Any ]] = None
937
977
) -> Optional [List [CompleteResult ]]:
938
978
result = await asyncio .wait_for (
939
979
asyncio .get_running_loop ().run_in_executor (
@@ -944,7 +984,25 @@ async def complete_variables_import(
944
984
base_dir ,
945
985
self .config .python_path if self .config is not None else None ,
946
986
self .config .env if self .config is not None else None ,
947
- self .config .variables if self .config is not None else None ,
987
+ variables if variables is not None else self .config .variables if self .config is not None else None ,
988
+ ),
989
+ COMPLETE_VARIABLES_IMPORT_TIME_OUT ,
990
+ )
991
+
992
+ return result
993
+
994
+ async def resolve_variable (
995
+ self , name : str , base_dir : str = "." , variables : Optional [Dict [str , Any ]] = None , ignore_errors : bool = True
996
+ ) -> Any :
997
+ result = await asyncio .wait_for (
998
+ asyncio .get_running_loop ().run_in_executor (
999
+ self .process_pool ,
1000
+ resolve_variable ,
1001
+ name ,
1002
+ str (self .folder .to_path ()),
1003
+ base_dir ,
1004
+ variables if variables is not None else self .config .variables if self .config is not None else None ,
1005
+ ignore_errors ,
948
1006
),
949
1007
COMPLETE_VARIABLES_IMPORT_TIME_OUT ,
950
1008
)
0 commit comments