Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/graphviz/_defaults.py: 30%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

23 statements  

1"""Set package-wide default parameters and IPython/Jupyter display format.""" 

2 

3from typing import Final 

4 

5__all_ = ['DEFAULT_SOURCE_EXTENSION', 

6 'set_default_engine', 'set_default_format', 'set_jupyter_format'] 

7 

8DEFAULT_SOURCE_EXTENSION: Final = 'gv' 

9 

10 

11def set_default_engine(engine: str) -> str: 

12 """Change the default ``engine`` and return the old default value. 

13 

14 Args: 

15 engine: new default ``engine`` 

16 used by all present and newly created instances 

17 without explicitly set ``engine`` 

18 (``'dot'``, ``'neato'``, ...). 

19 

20 Returns: 

21 The old default value used for ``engine``. 

22 """ 

23 from . import parameters 

24 

25 parameters.verify_engine(engine) 

26 

27 old_default_engine = parameters.Parameters._engine 

28 parameters.Parameters._engine = engine 

29 return old_default_engine 

30 

31 

32def set_default_format(format: str) -> str: 

33 """Change the default ``format`` and return the old default value. 

34 

35 Args: 

36 format: new default ``format`` 

37 used by all present and newly created instances 

38 without explicitly set ``format`` 

39 (``'pdf'``, ``'png'``, ...). 

40 

41 Returns: 

42 The old default value used for ``format``. 

43 """ 

44 from . import parameters 

45 

46 parameters.verify_format(format) 

47 

48 old_default_format = parameters.Parameters._format 

49 parameters.Parameters._format = format 

50 return old_default_format 

51 

52 

53def set_jupyter_format(jupyter_format: str) -> str: 

54 """Change the default mimetype format for ``_repr_mimebundle_()`` and return the old value. 

55 

56 Args: 

57 jupyter_format: new default IPython/Jupyter display format 

58 used by all present and newly created instances 

59 (``'svg'``, ``'png'``, ...). 

60 

61 Returns: 

62 The old default value used for IPython/Jupyter display format. 

63 """ 

64 from . import jupyter_integration 

65 

66 mimetype = jupyter_integration.get_jupyter_format_mimetype(jupyter_format) 

67 

68 old_mimetype = jupyter_integration.JupyterIntegration._jupyter_mimetype 

69 old_format = jupyter_integration.get_jupyter_mimetype_format(old_mimetype) 

70 

71 jupyter_integration.JupyterIntegration._jupyter_mimetype = mimetype 

72 return old_format