PythonBindings.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <PythonBindingsInterface.h>
  10. #include <AzCore/IO/Path/Path.h>
  11. #include <AzCore/std/parallel/semaphore.h>
  12. // Qt defines slots, which interferes with the use here.
  13. #pragma push_macro("slots")
  14. #undef slots
  15. #include <Python.h>
  16. #include <pybind11/pybind11.h>
  17. #pragma pop_macro("slots")
  18. namespace O3DE::ProjectManager
  19. {
  20. class PythonBindings
  21. : public PythonBindingsInterface::Registrar
  22. {
  23. public:
  24. PythonBindings() = default;
  25. PythonBindings(const AZ::IO::PathView& enginePath);
  26. ~PythonBindings() override;
  27. // PythonBindings overrides
  28. bool PythonStarted() override;
  29. // Engine
  30. AZ::Outcome<EngineInfo> GetEngineInfo() override;
  31. bool SetEngineInfo(const EngineInfo& engineInfo) override;
  32. // Gem
  33. AZ::Outcome<GemInfo> GetGemInfo(const QString& path, const QString& projectPath = {}) override;
  34. AZ::Outcome<QVector<GemInfo>, AZStd::string> GetEngineGemInfos() override;
  35. AZ::Outcome<QVector<GemInfo>, AZStd::string> GetAllGemInfos(const QString& projectPath) override;
  36. AZ::Outcome<QVector<AZStd::string>, AZStd::string> GetEnabledGemNames(const QString& projectPath) override;
  37. // Project
  38. AZ::Outcome<ProjectInfo> CreateProject(const QString& projectTemplatePath, const ProjectInfo& projectInfo) override;
  39. AZ::Outcome<ProjectInfo> GetProject(const QString& path) override;
  40. AZ::Outcome<QVector<ProjectInfo>> GetProjects() override;
  41. bool AddProject(const QString& path) override;
  42. bool RemoveProject(const QString& path) override;
  43. AZ::Outcome<void, AZStd::string> UpdateProject(const ProjectInfo& projectInfo) override;
  44. AZ::Outcome<void, AZStd::string> AddGemToProject(const QString& gemPath, const QString& projectPath) override;
  45. AZ::Outcome<void, AZStd::string> RemoveGemFromProject(const QString& gemPath, const QString& projectPath) override;
  46. bool RemoveInvalidProjects() override;
  47. // ProjectTemplate
  48. AZ::Outcome<QVector<ProjectTemplateInfo>> GetProjectTemplates(const QString& projectPath = {}) override;
  49. // Gem Repos
  50. AZ::Outcome<QVector<GemRepoInfo>, AZStd::string> GetAllGemRepoInfos() override;
  51. private:
  52. AZ_DISABLE_COPY_MOVE(PythonBindings);
  53. AZ::Outcome<void, AZStd::string> ExecuteWithLockErrorHandling(AZStd::function<void()> executionCallback);
  54. bool ExecuteWithLock(AZStd::function<void()> executionCallback);
  55. GemInfo GemInfoFromPath(pybind11::handle path, pybind11::handle pyProjectPath);
  56. GemRepoInfo GemRepoInfoFromPath(pybind11::handle path, pybind11::handle pyEnginePath);
  57. ProjectInfo ProjectInfoFromPath(pybind11::handle path);
  58. ProjectTemplateInfo ProjectTemplateInfoFromPath(pybind11::handle path, pybind11::handle pyProjectPath);
  59. bool RegisterThisEngine();
  60. bool StartPython();
  61. bool StopPython();
  62. bool m_pythonStarted = false;
  63. AZ::IO::FixedMaxPath m_enginePath;
  64. AZStd::recursive_mutex m_lock;
  65. pybind11::handle m_engineTemplate;
  66. pybind11::handle m_cmake;
  67. pybind11::handle m_register;
  68. pybind11::handle m_manifest;
  69. pybind11::handle m_enableGemProject;
  70. pybind11::handle m_disableGemProject;
  71. pybind11::handle m_editProjectProperties;
  72. pybind11::handle m_pathlib;
  73. };
  74. }