您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #
  2. # Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import dotenv
  17. import typing
  18. import subprocess
  19. def get_versions() -> typing.Mapping[str, typing.Any]:
  20. dotenv.load_dotenv(dotenv.find_dotenv())
  21. return dotenv.dotenv_values()
  22. def get_rag_version() -> typing.Optional[str]:
  23. return get_versions().get("RAGFLOW_IMAGE", "infiniflow/ragflow:dev").split(":")[-1]
  24. RAGFLOW_VERSION_INFO = "dev"
  25. def get_closest_tag_and_count():
  26. # Get the current commit hash
  27. commit_id = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip().decode('utf-8')
  28. # Get the closest tag
  29. closest_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).strip().decode('utf-8')
  30. # Get the commit hash of the closest tag
  31. closest_tag_commit = subprocess.check_output(['git', 'rev-list', '-n', '1', closest_tag]).strip().decode('utf-8')
  32. # Get the commit count since the closest tag
  33. process = subprocess.Popen(['git', 'rev-list', '--count', f'{closest_tag}..HEAD'], stdout=subprocess.PIPE)
  34. commits_count, _ = process.communicate()
  35. commits_count = int(commits_count.strip())
  36. if commits_count == 0:
  37. return closest_tag
  38. else:
  39. return f"{commit_id}({closest_tag}~{commits_count})"
  40. if RAGFLOW_VERSION_INFO == 'dev':
  41. RAGFLOW_VERSION_INFO = get_closest_tag_and_count()