Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP8 compliant stubs #19

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions QuantConnectStubsGenerator/Model/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ namespace QuantConnectStubsGenerator.Model
public class Property
{
public string Name { get; }

public PythonType Type { get; set; }

public bool Static { get; set; }

public bool Abstract { get; set; }

public bool Constant { get; set; }

public string Value { get; set; }

public string Summary { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions QuantConnectStubsGenerator/Parser/PropertyParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node
: _currentClass.Properties.Count.ToString(),
Static = true,
Abstract = _currentClass.Interface || HasModifier(node, "abstract"),
Constant = true,
DeprecationReason = GetDeprecationReason(node)
};

Expand Down Expand Up @@ -169,6 +170,7 @@ private void VisitField(BaseFieldDeclarationSyntax node, PythonType type)
Type = type,
Static = _currentClass.Static || HasModifier(node, "static") || HasModifier(node, "const"),
Abstract = _currentClass.Interface || HasModifier(node, "abstract"),
Constant = HasModifier(node, "const") || HasModifier(node, "readonly"),
DeprecationReason = GetDeprecationReason(node)
};

Expand Down
31 changes: 16 additions & 15 deletions QuantConnectStubsGenerator/QuantConnectStubsGenerator.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.12" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
<PackageReference Include="QuikGraph" Version="2.3.0" />
</ItemGroup>
<ItemGroup>
<None Update="log4net.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.12" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
<PackageReference Include="QuikGraph" Version="2.3.0" />
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.*" />
</ItemGroup>
<ItemGroup>
<None Update="log4net.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
31 changes: 31 additions & 0 deletions QuantConnectStubsGenerator/Renderer/MethodRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Python.Runtime;
using QuantConnectStubsGenerator.Model;
using QuantConnectStubsGenerator.Utility;

Expand All @@ -14,6 +15,13 @@

public override void Render(Method method)
{
var snakeCasedMethod = GetSnakeCasedMethod(method);
if (snakeCasedMethod.Name != method.Name)
{
Render(snakeCasedMethod);
return;
}

if (method.Static)
{
WriteLine("@staticmethod");
Expand Down Expand Up @@ -82,5 +90,28 @@

return str;
}

private static Method GetSnakeCasedMethod(Method method)
{
var snakeCasedMethod = new Method(method.Name.ToSnakeCase(), method.ReturnType)

Check failure on line 96 in QuantConnectStubsGenerator/Renderer/MethodRenderer.cs

View workflow job for this annotation

GitHub Actions / build

'string' does not contain a definition for 'ToSnakeCase' and no accessible extension method 'ToSnakeCase' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in QuantConnectStubsGenerator/Renderer/MethodRenderer.cs

View workflow job for this annotation

GitHub Actions / build

'string' does not contain a definition for 'ToSnakeCase' and no accessible extension method 'ToSnakeCase' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
{
Static = method.Static,
Overload = method.Overload,
Summary = method.Summary,
File = method.File,
DeprecationReason = method.DeprecationReason
};

foreach (var parameter in method.Parameters)
{
snakeCasedMethod.Parameters.Add(new Parameter(parameter.Name.ToSnakeCase(), parameter.Type)

Check failure on line 107 in QuantConnectStubsGenerator/Renderer/MethodRenderer.cs

View workflow job for this annotation

GitHub Actions / build

'string' does not contain a definition for 'ToSnakeCase' and no accessible extension method 'ToSnakeCase' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 107 in QuantConnectStubsGenerator/Renderer/MethodRenderer.cs

View workflow job for this annotation

GitHub Actions / build

'string' does not contain a definition for 'ToSnakeCase' and no accessible extension method 'ToSnakeCase' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
{
VarArgs = parameter.VarArgs,
Value = parameter.Value
});
}

return snakeCasedMethod;
}
}
}
28 changes: 28 additions & 0 deletions QuantConnectStubsGenerator/Renderer/PropertyRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using Python.Runtime;
using QuantConnectStubsGenerator.Model;
using QuantConnectStubsGenerator.Utility;

Expand All @@ -12,6 +13,13 @@

public override void Render(Property property)
{
var snakeCasedProperty = GetSnakeCasedProperty(property);
if (snakeCasedProperty.Name != property.Name)
{
Render(snakeCasedProperty);
return;
}

if (property.Static)
{
RenderAttribute(property);
Expand All @@ -22,6 +30,26 @@
}
}

private static Property GetSnakeCasedProperty(Property property)
{
var name = property.Name.ToSnakeCase();

Check failure on line 35 in QuantConnectStubsGenerator/Renderer/PropertyRenderer.cs

View workflow job for this annotation

GitHub Actions / build

'string' does not contain a definition for 'ToSnakeCase' and no accessible extension method 'ToSnakeCase' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 35 in QuantConnectStubsGenerator/Renderer/PropertyRenderer.cs

View workflow job for this annotation

GitHub Actions / build

'string' does not contain a definition for 'ToSnakeCase' and no accessible extension method 'ToSnakeCase' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
if (property.Constant)
{
name = name.ToUpper();
}

return new Property(name)
{
Type = property.Type,
Static = property.Static,
Abstract = property.Abstract,
Constant = property.Constant,
Value = property.Value,
Summary = property.Summary,
DeprecationReason = property.DeprecationReason
};
}

private void RenderAttribute(Property property)
{
// Some attributes have names in C# that are illegal in Python
Expand Down
Loading