version.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. __all__ = ['get_pdx_version', 'get_version_dict', 'show_versions']
  16. def get_pdx_version():
  17. """ get_pdx_version """
  18. with open(
  19. os.path.join(os.path.dirname(__file__), ".version"),
  20. 'r',
  21. encoding='ascii') as fv:
  22. ver = fv.read().rstrip()
  23. return ver
  24. def get_version_dict():
  25. """ get_version_dict """
  26. import paddle
  27. from . import repo_manager
  28. ver_dict = dict()
  29. ver_dict['pdx'] = get_pdx_version()
  30. ver_dict['paddle'] = paddle.__version__
  31. ver_dict['devkits'] = repo_manager.get_versions()
  32. return ver_dict
  33. def show_versions():
  34. """ show_versions """
  35. ver_dict = get_version_dict()
  36. pdx_ver = f"PDX version: {ver_dict['pdx']}\n"
  37. paddle_ver = f"PaddlePaddle version: {ver_dict['paddle']}\n"
  38. repo_vers = []
  39. for repo_name, vers in ver_dict['devkits'].items():
  40. sta_ver = vers[0]
  41. commit = vers[1]
  42. repo_vers.append(
  43. f"{repo_name}:\nversion: {sta_ver}\ncommit id: {commit}\n")
  44. all_vers = [pdx_ver, paddle_ver, *repo_vers]
  45. ver_str = '\n'.join(all_vers)
  46. print(ver_str)