Skip to content

Commit e6a8854

Browse files
arturkamienieckimichalpelka
authored andcommitted
continuationof python text extraction
Signed-off-by: Artur Kamieniecki <[email protected]>
1 parent df6baf0 commit e6a8854

34 files changed

+195
-146
lines changed
File renamed without changes.

Gems/EditorPythonBindings/Code/Source/PythonUtility.h renamed to Gems/EditorPythonBindings/Code/Include/EditorPythonBindings/PythonUtility.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <AzCore/RTTI/BehaviorContext.h>
1212
#include <AzCore/std/optional.h>
1313
#include <AzCore/std/string/string_view.h>
14-
#include <Source/PythonCommon.h>
14+
#include <EditorPythonBindings/PythonCommon.h>
1515
#include <pybind11/pybind11.h>
1616

1717
namespace AZ
@@ -158,12 +158,22 @@ namespace EditorPythonBindings
158158
const AZStd::string methodName, const AZ::BehaviorMethod& behaviorMethod, const AZ::BehaviorClass* behaviorClass = nullptr);
159159

160160
//! Creates a string with class definition and documentation.
161-
AZStd::string ClassDefinition(const AZ::BehaviorClass* behaviorClass, const AZStd::string className);
161+
AZStd::string ClassDefinition(
162+
const AZ::BehaviorClass* behaviorClass,
163+
const AZStd::string className,
164+
bool defineProperties = true,
165+
bool defineMethods = true);
162166

163167
//! Creates a property definition
164168
AZStd::string PropertyDefinition(
165169
AZStd::string_view propertyName, int level, const AZ::BehaviorProperty& property, const AZ::BehaviorClass* behaviorClass);
166170

171+
AZStd::string GlobalPropertyDefinition(
172+
const AZStd::string moduleName,
173+
const AZStd::string propertyName,
174+
const AZ::BehaviorProperty& behaviorProperty,
175+
bool needsHeader = true);
176+
167177
private:
168178
AZStd::string FetchListType(const AZ::TypeId& typeId);
169179
AZStd::string FetchMapType(const AZ::TypeId& typeId);

Gems/EditorPythonBindings/Code/Source/ActionManager/PythonActionManagerHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <AzToolsFramework/ActionManager/Action/ActionManagerInterface.h>
1212
#include <AzToolsFramework/ActionManager/ToolBar/ToolBarManagerInterface.h>
13-
#include <Source/PythonCommon.h>
13+
#include <EditorPythonBindings/PythonCommon.h>
1414
#include <pybind11/pybind11.h>
1515

1616
namespace EditorPythonBindings

Gems/EditorPythonBindings/Code/Source/ActionManager/PythonEditorAction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <AzCore/Memory/SystemAllocator.h>
1212
#include <AzCore/std/function/function_template.h>
1313

14-
#include <Source/PythonCommon.h>
14+
#include <EditorPythonBindings/PythonCommon.h>
1515
#include <pybind11/pybind11.h>
1616

1717
namespace EditorPythonBindings

Gems/EditorPythonBindings/Code/Source/PythonLogSymbolsComponent.cpp

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
#include <PythonLogSymbolsComponent.h>
1010

11-
#include <Source/PythonCommon.h>
11+
#include <EditorPythonBindings/PythonCommon.h>
12+
#include <EditorPythonBindings/PythonUtility.h>
1213
#include <Source/PythonProxyBus.h>
1314
#include <Source/PythonProxyObject.h>
1415
#include <Source/PythonTypeCasters.h>
15-
#include <Source/PythonUtility.h>
1616
#include <pybind11/embed.h>
1717

1818
#include <AzCore/IO/FileIO.h>
@@ -150,42 +150,8 @@ namespace EditorPythonBindings
150150
auto fileHandle = OpenModuleAt(moduleName);
151151
if (fileHandle->IsValid())
152152
{
153-
// Behavior Class types with member methods and properties
154-
AZStd::string buffer;
155-
AzFramework::StringFunc::Append(buffer, "class ");
156-
AzFramework::StringFunc::Append(buffer, className.data());
157-
AzFramework::StringFunc::Append(buffer, ":\n");
153+
AZStd::string buffer = m_pythonBehaviorDescription.ClassDefinition(behaviorClass, className);
158154
AZ::IO::FileIOBase::GetInstance()->Write(*fileHandle, buffer.c_str(), buffer.size());
159-
buffer.clear();
160-
161-
if (behaviorClass->m_methods.empty() && behaviorClass->m_properties.empty())
162-
{
163-
AZStd::string body{ " # behavior class type with no methods or properties \n" };
164-
Text::Indent(1, body);
165-
AzFramework::StringFunc::Append(body, "pass\n\n");
166-
AZ::IO::FileIOBase::GetInstance()->Write(*fileHandle, body.c_str(), body.size());
167-
}
168-
else
169-
{
170-
for (const auto& properyEntry : behaviorClass->m_properties)
171-
{
172-
AZ::BehaviorProperty* property = properyEntry.second;
173-
AZStd::string propertyName{ properyEntry.first };
174-
Scope::FetchScriptName(property->m_attributes, propertyName);
175-
WriteProperty(*fileHandle, 1, propertyName, *property, behaviorClass);
176-
}
177-
178-
for (const auto& methodEntry : behaviorClass->m_methods)
179-
{
180-
AZ::BehaviorMethod* method = methodEntry.second;
181-
if (method && PythonProxyObjectManagement::IsMemberLike(*method, behaviorClass->m_typeId))
182-
{
183-
AZStd::string baseMethodName{ methodEntry.first };
184-
Scope::FetchScriptName(method->m_attributes, baseMethodName);
185-
WriteMethod(*fileHandle, baseMethodName, *method, behaviorClass);
186-
}
187-
}
188-
}
189155
}
190156
}
191157

@@ -254,37 +220,13 @@ namespace EditorPythonBindings
254220
auto fileHandle = OpenModuleAt(moduleName);
255221
if (fileHandle->IsValid())
256222
{
257-
AZStd::string buffer;
258-
259223
// add header
260224
AZ::u64 filesize = 0;
261225
AZ::IO::FileIOBase::GetInstance()->Size(fileHandle->m_handle, filesize);
262-
if (filesize == 0)
263-
{
264-
AzFramework::StringFunc::Append(buffer, "class property():\n");
265-
}
226+
bool needsHeader = (filesize == 0);
266227

267-
Text::Indent(1, buffer);
268-
AzFramework::StringFunc::Append(buffer, propertyName.data());
269-
AzFramework::StringFunc::Append(buffer, ": ClassVar[");
270-
271-
const AZ::BehaviorParameter* resultParam = behaviorProperty->m_getter->GetResult();
272-
AZStd::string_view type = FetchPythonTypeAndTraits(resultParam->m_typeId, resultParam->m_traits);
273-
if (type.empty())
274-
{
275-
AzFramework::StringFunc::Append(buffer, "Any");
276-
}
277-
else
278-
{
279-
AzFramework::StringFunc::Append(buffer, type.data());
280-
}
281-
AzFramework::StringFunc::Append(buffer, "] = None");
282-
283-
if (behaviorProperty->m_getter && !behaviorProperty->m_setter)
284-
{
285-
AzFramework::StringFunc::Append(buffer, " # read only");
286-
}
287-
AzFramework::StringFunc::Append(buffer, "\n");
228+
AZStd::string buffer =
229+
m_pythonBehaviorDescription.GlobalPropertyDefinition(moduleName, propertyName, *behaviorProperty, needsHeader);
288230

289231
AZ::IO::FileIOBase::GetInstance()->Write(*fileHandle, buffer.c_str(), buffer.size());
290232
}

Gems/EditorPythonBindings/Code/Source/PythonLogSymbolsComponent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <AzCore/IO/SystemFile.h>
1212
#include <AzCore/IO/FileIO.h>
1313

14-
#include <Source/PythonCommon.h>
15-
#include <Source/PythonUtility.h>
14+
#include <EditorPythonBindings/PythonCommon.h>
15+
#include <EditorPythonBindings/PythonUtility.h>
1616
#include <Source/PythonSymbolsBus.h>
1717

1818
#include <EditorPythonBindings/EditorPythonBindingsBus.h>

Gems/EditorPythonBindings/Code/Source/PythonMarshalComponent.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
*
77
*/
88

9+
#include <EditorPythonBindings/PythonUtility.h>
910
#include <Source/PythonMarshalComponent.h>
1011
#include <Source/PythonMarshalTuple.h>
11-
#include <Source/PythonUtility.h>
1212
#include <Source/PythonProxyObject.h>
1313
#include <Source/PythonTypeCasters.h>
1414

@@ -20,7 +20,7 @@
2020
#include <AzCore/std/smart_ptr/make_shared.h>
2121
#include <AzFramework/StringFunc/StringFunc.h>
2222

23-
#include <Source/PythonCommon.h>
23+
#include <EditorPythonBindings/PythonCommon.h>
2424
#include <pybind11/embed.h>
2525
#include <pybind11/pytypes.h>
2626

Gems/EditorPythonBindings/Code/Source/PythonMarshalComponent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
#include <EditorPythonBindings/EditorPythonBindingsSymbols.h>
1111

12-
#include <Source/PythonUtility.h>
13-
#include <Source/PythonCommon.h>
12+
#include <EditorPythonBindings/PythonCommon.h>
13+
#include <EditorPythonBindings/PythonUtility.h>
1414
#include <pybind11/pybind11.h>
1515

1616
#include <AzCore/Component/Component.h>

Gems/EditorPythonBindings/Code/Source/PythonProxyBus.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
#include <PythonProxyBus.h>
1010

11-
#include <Source/PythonUtility.h>
11+
#include <EditorPythonBindings/PythonUtility.h>
1212
#include <Source/PythonTypeCasters.h>
1313

14-
#include <Source/PythonCommon.h>
14+
#include <EditorPythonBindings/PythonCommon.h>
1515
#include <Source/PythonSymbolsBus.h>
1616
#include <pybind11/embed.h>
1717

Gems/EditorPythonBindings/Code/Source/PythonProxyBus.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
#pragma once
99

10-
#include <Source/PythonCommon.h>
10+
#include <EditorPythonBindings/PythonCommon.h>
1111
#include <pybind11/pybind11.h>
1212

1313
namespace EditorPythonBindings

0 commit comments

Comments
 (0)