_component_provider.py 1.8 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_flow.entity.types import ComponentProviderName
  18. from fate_flow.entity import BaseEntity
  19. class ComponentProvider(BaseEntity):
  20. def __init__(self, name: str, version: str, path: str, class_path: dict, _python_env="",**kwargs):
  21. if not ComponentProviderName.valid(name):
  22. raise ValueError(f"not support {name} provider")
  23. self._name = name
  24. self._version = version
  25. self._path = os.path.abspath(path)
  26. self._class_path = class_path
  27. self._python_env = _python_env
  28. self._env = {}
  29. self.init_env()
  30. def init_env(self):
  31. self._env["PYTHONPATH"] = os.path.dirname(self._path)
  32. self._env["PYTHON_ENV"] = self.python_env
  33. @property
  34. def name(self):
  35. return self._name
  36. @property
  37. def version(self):
  38. return self._version
  39. @property
  40. def path(self):
  41. return self._path
  42. @property
  43. def class_path(self):
  44. return self._class_path
  45. @property
  46. def env(self):
  47. return self._env
  48. @property
  49. def python_env(self):
  50. return self._python_env
  51. def __eq__(self, other):
  52. return self.name == other.name and self.version == other.version