Coverage for src/git_dag/constants.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-08 12:49 +0200

1"""Constants.""" 

2 

3import os 

4from enum import Enum 

5from pathlib import Path 

6from typing import Final 

7 

8DictStrStr = dict[str, str] 

9 

10 

11class DagBackends(Enum): 

12 """Backend libraries for DAG visualisation.""" 

13 

14 GRAPHVIZ = 1 #: https://github.com/xflr6/graphviz 

15 

16 

17#: A standard commit date to use 

18COMMIT_DATE = "01/01/25 09:00 +0100" 

19 

20#: Regex patterx for SHA-1 hash. 

21SHA_PATTERN: Final[str] = "(?P<sha>[0-9a-f]{40})" 

22 

23#: See https://stackoverflow.com/a/21868228 

24TAG_FORMAT_FIELDS: Final[list[str]] = [ 

25 "refname", # short name of lightweight tag (LWT) 

26 "sha", # SHA of tag object (for annotated tags) or pointed object for LWT 

27 "object", # SHA of pointed object 

28 "type", # type of pointed object 

29 "tag", # name of annotated tag 

30 "taggername", 

31 "taggeremail", 

32 "taggerdate", 

33 "contents", 

34] 

35 

36#: Plumbing command to get tag info. 

37CMD_TAGS_INFO: Final[str] = ( 

38 "for-each-ref --python --format '" 

39 "%(refname:short) %(objectname) %(object) %(type) %(tag) " 

40 "%(taggername) %(taggeremail) %(taggerdate) %(contents)" 

41 "' refs/tags" 

42) 

43 

44#: Empty git tree object. 

45GIT_EMPTY_TREE_OBJECT_SHA: Final[str] = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" 

46 

47#: HTML template to embed SVG 

48HTML_EMBED_SVG: Final[ 

49 str 

50] = """ 

51<!DOCTYPE html> 

52<!-- serve using python -m http.server -d /path/to/src --> 

53<html lang="en"> 

54 <head> 

55 <meta charset="UTF-8"> 

56 <title>Embed SVG</title> 

57 <style> 

58 .svg-object {{ 

59 height: 97vh; 

60 width: 100%; 

61 border: 1px solid black; 

62 }} 

63 </style> 

64 <script> 

65 {svg_pan_zoom_js} 

66 </script> 

67 <script> 

68 {custom_js} 

69 </script> 

70 </head> 

71 <body> 

72 <object class="svg-object" data="{svg_filename}" type="image/svg+xml"></object> 

73 </body> 

74</html> 

75""" 

76 

77#: Configuration file. 

78CONFIG_FILE: Final[Path] = Path( 

79 os.getenv("GIT_DAG_CONFIG_FILE", os.path.expandvars("$HOME/.git-dag.yml")) 

80)