You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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