Coverage for phml\compiler\steps\base.py: 100%

5 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-04-06 14:03 -0500

1from functools import wraps 

2from inspect import getfullargspec 

3from typing import Any, Callable 

4 

5from phml.components import ComponentManager 

6from phml.nodes import AST, Parent 

7 

8 

9def comp_step(func: Callable[[Parent, ComponentManager, dict[str, Any]], None]): # pragma: no cover 

10 """Wrapper for compilation steps. This wraps a function that takes a parent node, 

11 the current context, and component manager. The function is expected to mutate the children nodes. 

12 It is also expected that the function is not recursive and only mutates the direct children of the node 

13 passed in. 

14 

15 Args: 

16 Node (Parent): The parent node that is the current scope 

17 components (ComponentManager): The manager instance for the components 

18 context (dict[str, Any]): Additional global context from parent objects 

19 

20 Note: 

21 There may be any combination of arguments, keyword only arguments, or catch alls with *arg and **kwarg. 

22 This wrapper will predictably and automatically pass the arguments that are specified. 

23 """ 

24 

25 @wraps(func) 

26 def inner( 

27 node: Parent, 

28 components: ComponentManager, 

29 context: dict[str, Any], 

30 ): 

31 return func(node, components, context) 

32 return inner 

33 

34 

35def boundry_step(func: Callable[[AST, ComponentManager, dict[str, Any]], None]): # pragma: no cover 

36 """Wrapper for setup and post compile steps. This wraps a function that takes an AST node, 

37 the current context, and the component manager. The funciton is expected to mutate the AST recursively 

38 

39 Args: 

40 Node (Parent): The parent node that is the current scope 

41 components (ComponentManager): The manager instance for the components 

42 context (dict[str, Any]): Additional global context from parent objects 

43 

44 Note: 

45 There may be any combination of arguments, keyword only arguments, or catch alls with *arg and **kwarg. 

46 This wrapper will predictably and automatically pass the arguments that are specified. 

47 """ 

48 

49 @wraps(func) 

50 def inner( 

51 node: AST, 

52 components: ComponentManager, 

53 context: dict[str, Any], 

54 ): 

55 return func(node, components, context) 

56 return inner