env_utils.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 sys
  17. from fate_flow.component_env_utils.provider_utils import get_provider_class_object
  18. from fate_flow.entity import ComponentProvider
  19. from fate_flow.manager.provider_manager import ProviderManager
  20. def get_python_path(provider_info):
  21. return provider_info.get("env").get("PYTHONPATH")
  22. def get_fate_algorithm_path(provider_info):
  23. return provider_info.get("path")
  24. def get_class_path(provider_info, name):
  25. return provider_info.get("class_path").get(name)
  26. def import_path(path):
  27. sys.path.append(path)
  28. def import_python_path(provider_info):
  29. import_path(get_python_path(provider_info))
  30. def import_component_output_depend(provider_info=None):
  31. if not provider_info:
  32. provider_info = ProviderManager.get_default_fate_provider().to_dict()
  33. import_python_path(provider_info)
  34. def get_class_object(class_name):
  35. provider_info = ProviderManager.get_default_fate_provider().to_dict()
  36. import_python_path(provider_info)
  37. provider = ComponentProvider(**provider_info)
  38. class_obj = get_provider_class_object(provider, class_name)
  39. return class_obj