PythonBindingsInterface.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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 <AzCore/EBus/EBus.h>
  10. #include <AzCore/Interface/Interface.h>
  11. #include <AzCore/std/string/string.h>
  12. #include <AzCore/std/containers/vector.h>
  13. #include <AzCore/Outcome/Outcome.h>
  14. #include <EngineInfo.h>
  15. #include <GemCatalog/GemInfo.h>
  16. #include <ProjectInfo.h>
  17. #include <ProjectTemplateInfo.h>
  18. #include <GemRepo/GemRepoInfo.h>
  19. #if !defined(Q_MOC_RUN)
  20. #include <QHash>
  21. #endif
  22. namespace O3DE::ProjectManager
  23. {
  24. //! Interface used to interact with the o3de cli python functions
  25. class IPythonBindings
  26. {
  27. public:
  28. AZ_RTTI(O3DE::ProjectManager::IPythonBindings, "{C2B72CA4-56A9-4601-A584-3B40E83AA17C}");
  29. AZ_DISABLE_COPY_MOVE(IPythonBindings);
  30. IPythonBindings() = default;
  31. virtual ~IPythonBindings() = default;
  32. //! First string in pair is general error, second is detailed
  33. using ErrorPair = AZStd::pair<AZStd::string, AZStd::string>;
  34. using DetailedOutcome = AZ::Outcome<void, ErrorPair>;
  35. /**
  36. * Get whether Python was started or not. All Python functionality will fail if Python
  37. * failed to start.
  38. * @return true if Python was started successfully, false on failure
  39. */
  40. virtual bool PythonStarted() = 0;
  41. /**
  42. * Attempt to start Python. Normally, Python is started when the bindings are created,
  43. * but this method allows you to attempt to retry starting Python in case the configuration
  44. * has changed.
  45. * @return true if Python was started successfully, false on failure
  46. */
  47. virtual bool StartPython() = 0;
  48. // Engine
  49. /**
  50. * Get info about all registered engines
  51. * @return an outcome with a vector of EngineInfos on success
  52. */
  53. virtual AZ::Outcome<QVector<EngineInfo>> GetAllEngineInfos() = 0;
  54. /**
  55. * Get info about the current engine
  56. * @return an outcome with EngineInfo on success
  57. */
  58. virtual AZ::Outcome<EngineInfo> GetEngineInfo() = 0;
  59. /**
  60. * Get info about an engine by name
  61. * @param engineName The name of the engine to get info about
  62. * @return an outcome with EngineInfo on success
  63. */
  64. virtual AZ::Outcome<EngineInfo> GetEngineInfo(const QString& engineName) = 0;
  65. /**
  66. * Get info about an engine the provided project is registered with
  67. * @param projectPath The path of the project
  68. * @return an outcome with EngineInfo on success
  69. */
  70. virtual AZ::Outcome<EngineInfo> GetProjectEngine(const QString& projectPath) = 0;
  71. /**
  72. * Set info about the engine
  73. * @param force True to force registration even if an engine with the same name is already registered
  74. * @param engineInfo an EngineInfo object
  75. * @return a detailed error outcome on failure.
  76. */
  77. virtual DetailedOutcome SetEngineInfo(const EngineInfo& engineInfo, bool force = false) = 0;
  78. // Remote source
  79. /**
  80. * Validates a repository without adding it.
  81. * @param repoUri the absolute filesystem path or url to the repo.
  82. * @return bool, true if the repository is valid
  83. */
  84. virtual bool ValidateRepository(const QString& repoUri) = 0;
  85. // Gems
  86. /**
  87. * Create a Gem from the Create A Gem Wizard
  88. * @param templatePath the path to the gem template to use
  89. * @param gemInfo the gem info to use
  90. * @param registerGem whether to register the gem or not
  91. * @return an outcome with GemInfo on success
  92. */
  93. virtual AZ::Outcome<GemInfo> CreateGem(const QString& templatePath, const GemInfo& gemInfo, bool registerGem = true) = 0;
  94. /**
  95. * Edit a Gem from the Edit Gem Wizard
  96. * @param oldGemName the gem name that existed prior to the update request
  97. * @param newGemInfo the gem updates that the user is requesting
  98. * @return an outcome with GemInfo on success
  99. */
  100. virtual AZ::Outcome<GemInfo> EditGem(const QString& oldGemName, const GemInfo& newGemInfo) = 0;
  101. /**
  102. * Get info about a Gem.
  103. * @param path The absolute path to the Gem
  104. * @param projectPath (Optional) The absolute path to the Gem project
  105. * @return an outcome with GemInfo on success
  106. */
  107. virtual AZ::Outcome<GemInfo> GetGemInfo(const QString& path, const QString& projectPath = {}) = 0;
  108. /**
  109. * Get info about all known gem templates
  110. * @return an outcome with a vector of TemplateInfos on success
  111. */
  112. virtual AZ::Outcome<QVector<TemplateInfo>> GetGemTemplates() = 0;
  113. /**
  114. * Get all available gem infos. This concatenates gems registered by the engine and the project.
  115. * @param projectPath The absolute path to the project.
  116. * @return A list of gem infos.
  117. */
  118. virtual AZ::Outcome<QVector<GemInfo>, AZStd::string> GetAllGemInfos(const QString& projectPath) = 0;
  119. /**
  120. * Get engine gem infos.
  121. * @return A list of all registered gem infos.
  122. */
  123. virtual AZ::Outcome<QVector<GemInfo>, AZStd::string> GetEngineGemInfos() = 0;
  124. /**
  125. * Get a list of all enabled gem names for a given project.
  126. * @param projectPath Absolute file path to the project.
  127. * @param includeDependencies Whether to return gem dependencies or only gems listed in project.json
  128. * and the deprecated enabled_gems.cmake file if it exists
  129. * @return A QHash of gem names with optional version specifiers and gem paths of all
  130. the enabled gems for a given project or a error message on failure.
  131. */
  132. virtual AZ::Outcome<QHash<QString /*gem name with specifier*/, QString /* gem path */>, AZStd::string> GetEnabledGems(
  133. const QString& projectPath, bool includeDependencies = true) const = 0;
  134. /**
  135. * Registers the gem to the specified project, or to the o3de_manifest.json if no project path is given
  136. * @param gemPath the path to the gem
  137. * @param projectPath the path to the project. If empty, will register the external path in o3de_manifest.json
  138. * @return An outcome with the success flag as well as an error message in case of a failure.
  139. */
  140. virtual AZ::Outcome<void, AZStd::string> RegisterGem(const QString& gemPath, const QString& projectPath = {}) = 0;
  141. /**
  142. * Unregisters the gem from the specified project, or from the o3de_manifest.json if no project path is given
  143. * @param gemPath the path to the gem
  144. * @param projectPath the path to the project. If empty, will unregister the external path in o3de_manifest.json
  145. * @return An outcome with the success flag as well as an error message in case of a failure.
  146. */
  147. virtual AZ::Outcome<void, AZStd::string> UnregisterGem(const QString& gemPath, const QString& projectPath = {}) = 0;
  148. // Projects
  149. /**
  150. * Create a project
  151. * @param projectTemplatePath the path to the project template to use
  152. * @param projectInfo the project info to use
  153. * @param registerProject whether to register the project or not
  154. * @return an outcome with ProjectInfo on success
  155. */
  156. virtual AZ::Outcome<ProjectInfo> CreateProject(const QString& projectTemplatePath, const ProjectInfo& projectInfo, bool registerProject = true) = 0;
  157. /**
  158. * Get info about a project
  159. * @param path the absolute path to the project
  160. * @return an outcome with ProjectInfo on success
  161. */
  162. virtual AZ::Outcome<ProjectInfo> GetProject(const QString& path) = 0;
  163. /**
  164. * Get info about all known projects
  165. * @return an outcome with ProjectInfos on success
  166. */
  167. virtual AZ::Outcome<QVector<ProjectInfo>> GetProjects() = 0;
  168. /**
  169. * Gathers all projects from the provided repo
  170. * @param repoUri the absolute filesystem path or url to the gem repo.
  171. * @return A list of project infos or an error string on failure.
  172. */
  173. virtual AZ::Outcome<QVector<ProjectInfo>, AZStd::string> GetProjectsForRepo(const QString& repoUri) = 0;
  174. /**
  175. * Gathers all projects from all registered repos
  176. * @return A list of project infos or an error string on failure.
  177. */
  178. virtual AZ::Outcome<QVector<ProjectInfo>, AZStd::string> GetProjectsForAllRepos() = 0;
  179. /**
  180. * Adds existing project on disk
  181. * @param path the absolute path to the project
  182. * @return An outcome with the success flag as well as an error message in case of a failure.
  183. */
  184. virtual DetailedOutcome AddProject(const QString& path) = 0;
  185. /**
  186. * Adds existing project on disk
  187. * @param path the absolute path to the project
  188. * @return An outcome with the success flag as well as an error message in case of a failure.
  189. */
  190. virtual DetailedOutcome RemoveProject(const QString& path) = 0;
  191. /**
  192. * Update a project
  193. * @param projectInfo the info to use to update the project
  194. * @return An outcome with the success flag as well as an error message in case of a failure.
  195. */
  196. virtual AZ::Outcome<void, AZStd::string> UpdateProject(const ProjectInfo& projectInfo) = 0;
  197. /**
  198. * Add a gem to a project
  199. * @param gemPath the absolute path to the gem
  200. * @param projectPath the absolute path to the project
  201. * @return An outcome with the success flag as well as an error message in case of a failure.
  202. */
  203. virtual AZ::Outcome<void, AZStd::string> AddGemToProject(const QString& gemPath, const QString& projectPath) = 0;
  204. /**
  205. * Remove gem to a project
  206. * @param gemPath the absolute path to the gem
  207. * @param projectPath the absolute path to the project
  208. * @return An outcome with the success flag as well as an error message in case of a failure.
  209. */
  210. virtual AZ::Outcome<void, AZStd::string> RemoveGemFromProject(const QString& gemPath, const QString& projectPath) = 0;
  211. /**
  212. * Removes invalid projects from the manifest
  213. */
  214. virtual bool RemoveInvalidProjects() = 0;
  215. // Project Templates
  216. /**
  217. * Get info about all known project templates
  218. * @return an outcome with ProjectTemplateInfos on success
  219. */
  220. virtual AZ::Outcome<QVector<ProjectTemplateInfo>> GetProjectTemplates() = 0;
  221. /**
  222. * Gathers all project templates for the given repo.
  223. * @return An outcome with a list of all ProjectTemplateInfos from the given repo on success
  224. */
  225. virtual AZ::Outcome<QVector<ProjectTemplateInfo>> GetProjectTemplatesForRepo(const QString& repoUri) const = 0;
  226. /**
  227. * Gathers all project templates for all templates registered from repos.
  228. * @return An outcome with a list of all ProjectTemplateInfos on success
  229. */
  230. virtual AZ::Outcome<QVector<ProjectTemplateInfo>> GetProjectTemplatesForAllRepos() const = 0;
  231. // Gem Repos
  232. /**
  233. * Refresh gem repo in the current engine.
  234. * @param repoUri the absolute filesystem path or url to the gem repo.
  235. * @return An outcome with the success flag as well as an error message in case of a failure.
  236. */
  237. virtual AZ::Outcome<void, AZStd::string> RefreshGemRepo(const QString& repoUri) = 0;
  238. /**
  239. * Refresh all gem repos in the current engine.
  240. * @return true on success, false on failure.
  241. */
  242. virtual bool RefreshAllGemRepos() = 0;
  243. /**
  244. * Registers this gem repo with the current engine.
  245. * @param repoUri the absolute filesystem path or url to the gem repo.
  246. * @return an outcome with a pair of string error and detailed messages on failure.
  247. */
  248. virtual DetailedOutcome AddGemRepo(const QString& repoUri) = 0;
  249. /**
  250. * Unregisters this gem repo with the current engine.
  251. * @param repoUri the absolute filesystem path or url to the gem repo.
  252. * @return true on success, false on failure.
  253. */
  254. virtual bool RemoveGemRepo(const QString& repoUri) = 0;
  255. /**
  256. * Get all available gem repo infos. Gathers all repos registered with the engine.
  257. * @return A list of gem repo infos.
  258. */
  259. virtual AZ::Outcome<QVector<GemRepoInfo>, AZStd::string> GetAllGemRepoInfos() = 0;
  260. /**
  261. * Gathers all gem infos from the provided repo
  262. * @param repoUri the absolute filesystem path or url to the gem repo.
  263. * @return A list of gem infos.
  264. */
  265. virtual AZ::Outcome<QVector<GemInfo>, AZStd::string> GetGemInfosForRepo(const QString& repoUri) = 0;
  266. /**
  267. * Gathers all gem infos for all gems registered from repos.
  268. * @return A list of gem infos.
  269. */
  270. virtual AZ::Outcome<QVector<GemInfo>, AZStd::string> GetGemInfosForAllRepos() = 0;
  271. /**
  272. * Downloads and registers a Gem.
  273. * @param gemName the name of the Gem to download.
  274. * @param gemProgressCallback a callback function that is called with an int percentage download value.
  275. * @param force should we forcibly overwrite the old version of the gem.
  276. * @return an outcome with a pair of string error and detailed messages on failure.
  277. */
  278. virtual DetailedOutcome DownloadGem(
  279. const QString& gemName, const QString& path, std::function<void(int, int)> gemProgressCallback, bool force = false) = 0;
  280. /**
  281. * Downloads and registers a project.
  282. * @param gemName the name of the project to download.
  283. * @param projectProgressCallback a callback function that is called with an int percentage download value.
  284. * @param force should we forcibly overwrite the old version of the project.
  285. * @return an outcome with a pair of string error and detailed messages on failure.
  286. */
  287. virtual DetailedOutcome DownloadProject(
  288. const QString& projectName, const QString& path, std::function<void(int, int)> projectProgressCallback, bool force = false) = 0;
  289. /**
  290. * Downloads and registers a template.
  291. * @param gemName the name of the template to download.
  292. * @param templateProgressCallback a callback function that is called with an int percentage download value.
  293. * @param force should we forcibly overwrite the old version of the template.
  294. * @return an outcome with a pair of string error and detailed messages on failure.
  295. */
  296. virtual DetailedOutcome DownloadTemplate(
  297. const QString& templateName, const QString& path, std::function<void(int, int)> templateProgressCallback, bool force = false) = 0;
  298. /**
  299. * Cancels the current download.
  300. */
  301. virtual void CancelDownload() = 0;
  302. /**
  303. * Checks if there is an update avaliable for a gem on a repo.
  304. * @param gemName the name of the gem to check.
  305. * @param lastUpdated last time the gem was update.
  306. * @return true if update is avaliable, false if not.
  307. */
  308. virtual bool IsGemUpdateAvaliable(const QString& gemName, const QString& lastUpdated) = 0;
  309. /**
  310. * Add an error string to be returned when the current python call is complete.
  311. * @param The error string to be displayed.
  312. */
  313. virtual void AddErrorString(AZStd::string errorString) = 0;
  314. };
  315. using PythonBindingsInterface = AZ::Interface<IPythonBindings>;
  316. } // namespace O3DE::ProjectManager