23
23
# of Comet
24
24
25
25
import os
26
+ from pathlib import Path
26
27
27
- for version in ["0.8" , "0.9" ]:
28
- os .system (f"git clone --depth 1 https://github.com/apache/datafusion-comet.git -b branch-{ version } comet-{ version } " )
29
- os .system (f"mkdir temp/user-guide/{ version } " )
30
- os .system (f"cp -rf comet-{ version } /docs/source/user-guide/* temp/user-guide/{ version } " )
28
+ def get_major_minor_version (version : str ):
29
+ parts = version .split ('.' )
30
+ return f"{ parts [0 ]} .{ parts [1 ]} "
31
+
32
+ def replace_in_files (root : str , filename_pattern : str , search : str , replace : str ):
33
+ root_path = Path (root )
34
+ for file in root_path .rglob (filename_pattern ):
35
+ text = file .read_text (encoding = "utf-8" )
36
+ updated = text .replace (search , replace )
37
+ if text != updated :
38
+ file .write_text (updated , encoding = "utf-8" )
39
+ print (f"Replaced { search } with { replace } in { file } " )
40
+
41
+ def insert_warning_after_asf_header (root : str , warning : str ):
42
+ root_path = Path (root )
43
+ for file in root_path .rglob ("*.md" ):
44
+ lines = file .read_text (encoding = "utf-8" ).splitlines (keepends = True )
45
+ new_lines = []
46
+ inserted = False
47
+ for line in lines :
48
+ new_lines .append (line )
49
+ if not inserted and "-->" in line :
50
+ new_lines .append (warning + "\n " )
51
+ inserted = True
52
+ file .write_text ("" .join (new_lines ), encoding = "utf-8" )
53
+
54
+ def publish_released_version (version : str ):
55
+ major_minor = get_major_minor_version (version )
56
+ os .system (f"git clone --depth 1 https://github.com/apache/datafusion-comet.git -b branch-{ major_minor } comet-{ major_minor } " )
57
+ os .system (f"mkdir temp/user-guide/{ major_minor } " )
58
+ os .system (f"cp -rf comet-{ major_minor } /docs/source/user-guide/* temp/user-guide/{ major_minor } " )
59
+ # Replace $COMET_VERSION with actual version
60
+ for file_pattern in ["*.md" , "*.rst" ]:
61
+ replace_in_files (f"temp/user-guide/{ major_minor } " , file_pattern , "$COMET_VERSION" , version )
62
+
63
+ def generate_docs (snapshot_version : str , latest_released_version : str , previous_versions : list [str ]):
64
+
65
+ # Replace $COMET_VERSION with actual version for snapshot version
66
+ for file_pattern in ["*.md" , "*.rst" ]:
67
+ replace_in_files (f"temp/user-guide/latest" , file_pattern , "$COMET_VERSION" , snapshot_version )
68
+
69
+ # Add user guide content for latest released versions
70
+ publish_released_version (latest_released_version )
71
+
72
+ # Add user guide content for older released versions
73
+ for version in previous_versions :
74
+ publish_released_version (version )
75
+ # add warning that this is out-of-date documentation
76
+ warning = f"""```{{warning}}
77
+ This is **out-of-date** documentation. The latest Comet release is version { latest_released_version } .
78
+ ```"""
79
+ major_minor = get_major_minor_version (version )
80
+ insert_warning_after_asf_header (f"temp/user-guide/{ major_minor } " , warning )
81
+
82
+ if __name__ == "__main__" :
83
+ print ("Generating versioned user guide docs..." )
84
+ snapshot_version = "0.10.0-SNAPSHOT"
85
+ latest_released_version = "0.9.1"
86
+ previous_versions = ["0.8.0" ]
87
+ generate_docs (snapshot_version , latest_released_version , previous_versions )
0 commit comments