Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

versions.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 subprocess
  17. def get_ragflow_version() -> str:
  18. return RAGFLOW_VERSION_INFO
  19. RAGFLOW_VERSION_INFO = "dev"
  20. def get_closest_tag_and_count():
  21. try:
  22. # Get the current commit hash
  23. commit_id = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip().decode('utf-8')
  24. # Get the closest tag
  25. closest_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).strip().decode('utf-8')
  26. # Get the commit hash of the closest tag
  27. closest_tag_commit = subprocess.check_output(['git', 'rev-list', '-n', '1', closest_tag]).strip().decode(
  28. 'utf-8')
  29. # Get the commit count since the closest tag
  30. process = subprocess.Popen(['git', 'rev-list', '--count', f'{closest_tag}..HEAD'], stdout=subprocess.PIPE)
  31. commits_count, _ = process.communicate()
  32. commits_count = int(commits_count.strip())
  33. if commits_count == 0:
  34. return closest_tag
  35. else:
  36. return f"{commit_id}({closest_tag}~{commits_count})"
  37. except Exception:
  38. return 'unknown'
  39. if RAGFLOW_VERSION_INFO == 'dev':
  40. RAGFLOW_VERSION_INFO = get_closest_tag_and_count()