| 
									
										
										
										
											2024-08-15 09:17:36 +08:00
										 |  |  | # | 
					
						
							|  |  |  | #  Copyright 2024 The InfiniFlow Authors. All Rights Reserved. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  | #  you may not use this file except in compliance with the License. | 
					
						
							|  |  |  | #  You may obtain a copy of the License at | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #      http://www.apache.org/licenses/LICENSE-2.0 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  | #  distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  | #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  | #  See the License for the specific language governing permissions and | 
					
						
							|  |  |  | #  limitations under the License. | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2024-11-22 20:24:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import os | 
					
						
							| 
									
										
										
										
											2024-11-14 15:51:30 +08:00
										 |  |  | import subprocess | 
					
						
							| 
									
										
										
										
											2024-08-15 09:17:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-22 20:24:32 +08:00
										 |  |  | RAGFLOW_VERSION_INFO = "unknown" | 
					
						
							| 
									
										
										
										
											2024-11-14 15:51:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-22 20:24:32 +08:00
										 |  |  | def get_ragflow_version() -> str: | 
					
						
							|  |  |  |     global RAGFLOW_VERSION_INFO | 
					
						
							|  |  |  |     if RAGFLOW_VERSION_INFO != "unknown": | 
					
						
							|  |  |  |         return RAGFLOW_VERSION_INFO | 
					
						
							|  |  |  |     version_path = os.path.abspath( | 
					
						
							|  |  |  |         os.path.join( | 
					
						
							|  |  |  |             os.path.dirname(os.path.realpath(__file__)), os.pardir, "VERSION" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     if os.path.exists(version_path): | 
					
						
							|  |  |  |         with open(version_path, "r") as f: | 
					
						
							|  |  |  |             RAGFLOW_VERSION_INFO = f.read().strip() | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         RAGFLOW_VERSION_INFO = get_closest_tag_and_count() | 
					
						
							|  |  |  |         LIGHTEN = int(os.environ.get("LIGHTEN", "0")) | 
					
						
							|  |  |  |         RAGFLOW_VERSION_INFO += " slim" if LIGHTEN == 1 else " full" | 
					
						
							|  |  |  |     return RAGFLOW_VERSION_INFO | 
					
						
							| 
									
										
										
										
											2024-11-14 15:51:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_closest_tag_and_count(): | 
					
						
							| 
									
										
										
										
											2024-11-14 17:51:21 +08:00
										 |  |  |     try: | 
					
						
							|  |  |  |         # Get the current commit hash | 
					
						
							| 
									
										
										
										
											2024-12-06 14:05:30 +08:00
										 |  |  |         version_info = ( | 
					
						
							| 
									
										
										
										
											2024-12-07 16:56:34 +08:00
										 |  |  |             subprocess.check_output(["git", "describe", "--tags", "--match=v*", "--first-parent", "--always"]) | 
					
						
							| 
									
										
										
										
											2024-11-22 20:24:32 +08:00
										 |  |  |             .strip() | 
					
						
							|  |  |  |             .decode("utf-8") | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2024-12-06 14:05:30 +08:00
										 |  |  |         return version_info | 
					
						
							| 
									
										
										
										
											2024-11-18 17:38:17 +08:00
										 |  |  |     except Exception: | 
					
						
							| 
									
										
										
										
											2024-11-22 20:24:32 +08:00
										 |  |  |         return "unknown" |