1414import re
1515from inspect import getcallargs
1616from socket import error as socket_error , timeout as timeout_error
17- from typing import (
18- TYPE_CHECKING ,
19- Any ,
20- Callable ,
21- Generic ,
22- Iterable ,
23- Optional ,
24- Type ,
25- TypeVar ,
26- Union ,
27- cast ,
28- )
17+ from typing import TYPE_CHECKING , Any , Callable , Generic , Iterable , Optional , Type , TypeVar , cast
2918
3019import click
3120import gevent
3827 get_kwargs_str ,
3928 log_error_or_warning ,
4029 log_host_command_error ,
41- make_hash ,
4230 print_host_combined_output ,
4331)
4432from pyinfra .connectors .util import CommandOutput
@@ -66,11 +54,12 @@ class FactBase(Generic[T]):
6654
6755 abstract : bool = True
6856
69- shell_executable : Optional [ str ] = None
57+ shell_executable : str | None = None
7058
71- requires_command : Optional [ str ] = None
59+ command : Callable [..., str | StringCommand ]
7260
73- command : Union [str , Callable ]
61+ def requires_command (self , * args , ** kwargs ) -> str | None :
62+ return None
7463
7564 def __init_subclass__ (cls ) -> None :
7665 super ().__init_subclass__ ()
@@ -113,8 +102,7 @@ def __init_subclass__(cls) -> None:
113102 module_name = cls .__module__ .replace ("pyinfra.facts." , "" )
114103 cls .name = f"{ module_name } .{ cls .__name__ } "
115104
116- @staticmethod
117- def process_data (data ):
105+ def process_data (self , data ):
118106 return data
119107
120108
@@ -130,30 +118,6 @@ def _make_command(command_attribute, host_args):
130118 return command_attribute
131119
132120
133- def _get_executor_kwargs (
134- state : "State" ,
135- host : "Host" ,
136- override_kwargs : Optional [dict [str , Any ]] = None ,
137- override_kwarg_keys : Optional [list [str ]] = None ,
138- ):
139- if override_kwargs is None :
140- override_kwargs = {}
141- if override_kwarg_keys is None :
142- override_kwarg_keys = []
143-
144- # Use the current operation global kwargs, or generate defaults
145- global_kwargs = host .current_op_global_arguments
146- if not global_kwargs :
147- global_kwargs , _ = pop_global_arguments ({}, state , host )
148-
149- # Apply any current op kwargs that *weren't* found in the overrides
150- override_kwargs .update (
151- {key : value for key , value in global_kwargs .items () if key not in override_kwarg_keys },
152- )
153-
154- return {key : value for key , value in override_kwargs .items () if key in CONNECTOR_ARGUMENT_KEYS }
155-
156-
157121def _handle_fact_kwargs (state , host , cls , args , kwargs ):
158122 args = args or []
159123 kwargs = kwargs or {}
@@ -296,7 +260,7 @@ def _get_fact(
296260 log_host_command_error (
297261 host ,
298262 e ,
299- timeout = global_kwargs [ "_timeout" ] ,
263+ timeout = global_kwargs . get ( "_timeout" ) ,
300264 )
301265
302266 stdout_lines , stderr_lines = output .stdout_lines , output .stderr_lines
@@ -346,13 +310,6 @@ def _get_fact(
346310 return data
347311
348312
349- def _get_fact_hash (state : "State" , host : "Host" , cls , args , kwargs ):
350- if issubclass (cls , ShortFactBase ):
351- cls = cls .fact
352- fact_kwargs , executor_kwargs = _handle_fact_kwargs (state , host , cls , args , kwargs )
353- return make_hash ((cls , fact_kwargs , executor_kwargs ))
354-
355-
356313def get_host_fact (
357314 state : "State" ,
358315 host : "Host" ,
0 commit comments