PythonBindingsInterface.h 19 KB

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