base_utils.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #
  2. # Copyright 2019 The FATE 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 os
  17. from fate_arch.common.base_utils import json_dumps
  18. FATE_FLOW_BASE = os.getenv("FATE_FLOW_BASE")
  19. def get_fate_flow_directory(*args):
  20. global FATE_FLOW_BASE
  21. if FATE_FLOW_BASE is None:
  22. FATE_FLOW_BASE = os.path.abspath(
  23. os.path.join(
  24. os.path.dirname(os.path.realpath(__file__)),
  25. os.pardir,
  26. os.pardir,
  27. os.pardir,
  28. )
  29. )
  30. if args:
  31. return os.path.join(FATE_FLOW_BASE, *args)
  32. return FATE_FLOW_BASE
  33. def get_fate_flow_python_directory(*args):
  34. return get_fate_flow_directory("python", *args)
  35. def jprint(src: dict, indent: int = 4):
  36. print(json_dumps(src, indent=indent))
  37. def compare_version(version: str, target_version: str):
  38. ver_list = version.split('.')
  39. tar_ver_list = target_version.split('.')
  40. if int(ver_list[0]) >= int(tar_ver_list[0]):
  41. if int(ver_list[1]) > int(tar_ver_list[1]):
  42. return 'gt'
  43. elif int(ver_list[1]) < int(tar_ver_list[1]):
  44. return 'lt'
  45. else:
  46. if int(ver_list[2]) > int(tar_ver_list[2]):
  47. return 'gt'
  48. elif int(ver_list[2]) == int(tar_ver_list[2]):
  49. return 'eq'
  50. else:
  51. return 'lt'
  52. return 'lt'