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

Samwelkanda/codegen python #1200

Merged
merged 84 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
1056db4
Add path segmenter for python
samwelkanda Feb 8, 2022
efb2a5c
Update path segmenter for python files
samwelkanda Feb 14, 2022
45439da
Update path segmenter for python
samwelkanda Feb 14, 2022
6ffba0a
Add a reseved names provider for python
samwelkanda Feb 14, 2022
7b121c9
Add a language refiner for python
samwelkanda Feb 14, 2022
5f00381
Add python option in language refiners
samwelkanda Jun 15, 2022
f225e65
- fixes merges mishaps
baywet Mar 2, 2022
9dd501e
Update python pathsegementer
samwelkanda Apr 26, 2022
72d0e18
Update python reserved names
samwelkanda Apr 26, 2022
f54c595
Update python refiner
samwelkanda Apr 27, 2022
c29fd69
Add a convention service file for python
samwelkanda Apr 27, 2022
c5207ef
Add writer for code block ends
samwelkanda Apr 27, 2022
6b4e6c6
Add writer for python Enum classes
samwelkanda Apr 27, 2022
b3ae227
Add python namespace file writer
samwelkanda Apr 27, 2022
8e80b6f
Add writer for declaring python classes
samwelkanda Apr 27, 2022
d7c1e75
Add writer for declaring python properties
samwelkanda Apr 27, 2022
b6cb995
Add a custom relative import manager for python
samwelkanda Apr 27, 2022
3259e91
Update class declaration not to add default imports for inner classes
samwelkanda May 23, 2022
ded9f53
Add writer for class methods
samwelkanda May 23, 2022
b708c2d
Replace # with / in generated descriptions
samwelkanda May 23, 2022
e1ae352
Update language writer for python
samwelkanda May 23, 2022
680bf4f
Add python option in main language writer
samwelkanda May 23, 2022
91644c5
Add unit tests for python code generation
samwelkanda Jul 19, 2022
1afac94
Fix typo errors
samwelkanda May 24, 2022
d7aedb2
Adds mapping for missing types in python
samwelkanda May 24, 2022
3b4b08b
Add checks to prevent overwriting base url if exists
samwelkanda May 25, 2022
a68a67f
Simplify deserializers in generated code
samwelkanda May 25, 2022
43947db
Request configuration revamp
samwelkanda Jun 15, 2022
c9b503c
Update api error using with right class name
samwelkanda Jul 14, 2022
a1fafb3
Use correct http method class name from abstractions
samwelkanda Jul 14, 2022
58ef12a
Update query parameter class type to camel case
samwelkanda Jul 14, 2022
d438aa8
Update relative import manager to use modules over class imports
samwelkanda Jul 14, 2022
de916c0
Update class writer for usings with no path
samwelkanda Jul 14, 2022
c36c3b5
Rearrage parameter order in request builder call
samwelkanda Jul 14, 2022
f40247d
Update parameter signature with none as default
samwelkanda Jul 14, 2022
91e8b67
Add helper method to fix type annotation if elements exists with the …
samwelkanda Jul 14, 2022
ad4df88
Refactor method to translate types to cater for internal and external…
samwelkanda Jul 14, 2022
f0632e5
Update property writer to exclude instance attributes
samwelkanda Jul 14, 2022
6dc6740
Add custom parameter order comparer for python
samwelkanda Jul 14, 2022
fc7603e
Update constructor writer to write instance properties
samwelkanda Jul 14, 2022
7d09924
Fix generation issues from end to end testing
samwelkanda Jul 14, 2022
ec977af
Update python languge refiner and tests
samwelkanda Jul 20, 2022
af676e7
Update refiner tests to check for escaped method names
samwelkanda Jul 20, 2022
5f09d50
Update code class declarationwriter and tests
samwelkanda Jul 20, 2022
1ce9b7a
Update code property writer and tests
samwelkanda Jul 20, 2022
5d3f1b8
Update relative import manager tests
samwelkanda Jul 20, 2022
3f99af9
Update code method writer testes
samwelkanda Jul 20, 2022
c5aabe4
Add python option to launch json
samwelkanda Jul 20, 2022
d3123dd
Resolve code smells
samwelkanda Jul 21, 2022
77a72c6
Bump test coverage
samwelkanda Jul 21, 2022
c540672
Bump test coverage
samwelkanda Jul 21, 2022
d0c91af
Bump test coverage
samwelkanda Jul 21, 2022
f18591c
Add an entry to the changelog
samwelkanda Jul 21, 2022
f9ec66f
Update readme with python progress
samwelkanda Jul 21, 2022
d3a30aa
Move case statements across multiple lines
samwelkanda Jul 22, 2022
6b2be8c
Rename methods to write internal and external imports
samwelkanda Jul 22, 2022
02b1e0c
Reuse existing instance of convention service in method writer
samwelkanda Jul 22, 2022
2de8de1
Update src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs
samwelkanda Jul 22, 2022
0a812f5
Update src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs
samwelkanda Jul 22, 2022
5d9e383
Fix failing tests
samwelkanda Jul 22, 2022
2d4ac89
Update src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs
samwelkanda Aug 1, 2022
0ad7333
Update PythonRelativeImportManager to inherit from RelativeImportManager
samwelkanda Aug 1, 2022
44c52d9
Fix indentation
samwelkanda Aug 1, 2022
3e9fda7
Use file scoped namespace style
samwelkanda Aug 1, 2022
f8703d3
Remove unnecessary castings
samwelkanda Aug 1, 2022
e2791af
Add null check for namespace files
samwelkanda Aug 5, 2022
1577e59
Add optional writer to convention service for writing inline descript…
samwelkanda Aug 5, 2022
20931c0
Fix code issues in convention service
samwelkanda Aug 5, 2022
1ce8717
Update src/Kiota.Builder/Writers/Python/CodeBlockEndWriter.cs
samwelkanda Aug 11, 2022
d84e0c2
Update src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs
samwelkanda Aug 11, 2022
e1661ff
Update src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs
samwelkanda Aug 11, 2022
cc585b8
Refactor null check in codeclassdeclarationwriter
samwelkanda Aug 11, 2022
d18b088
Merge branch 'main' into samwelkanda/codegen-python
baywet Aug 11, 2022
d9b3b56
Move parse node property type repacement in factory method to refiner
samwelkanda Aug 11, 2022
3f126cb
Merge branch 'samwelkanda/codegen-python' of https://github.com/micro…
samwelkanda Aug 11, 2022
8b87870
Merge branch 'main' into samwelkanda/codegen-python
baywet Aug 12, 2022
5b9f6c6
Add optional writer parameter to getparametersignature method
samwelkanda Aug 13, 2022
367e6fd
Merge branch 'samwelkanda/codegen-python' of https://github.com/micro…
samwelkanda Aug 13, 2022
f619cbb
Reuse method to add properties and method types imports from common r…
samwelkanda Aug 17, 2022
29afb23
Update src/Kiota.Builder/Refiners/PythonRefiner.cs
samwelkanda Aug 18, 2022
160e0f5
Update src/Kiota.Builder/Refiners/PythonRefiner.cs
samwelkanda Aug 18, 2022
9abb0ad
Update src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs
samwelkanda Aug 18, 2022
28ba977
Merge branch 'main' into samwelkanda/codegen-python
samwelkanda Aug 18, 2022
e0e0641
Fix minor format issues
samwelkanda Aug 18, 2022
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
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": "Launch Python",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net6.0/kiota.dll",
"args": ["--openapi",
"https://raw.githubusercontent.com/microsoftgraph/msgraph-sdk-powershell/dev/openApiDocs/v1.0/Mail.yml",
"--language",
"python",
"-o",
"${workspaceFolder}/samples/msgraph-mail/python",
"-n",
"GraphPythonv1" ],
"cwd": "${workspaceFolder}/src/kiota",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support for no-content responses in python abstractions and http packages. [#1630](https://github.com/microsoft/kiota/issues/1459)
- Added support for vendor-specific content types in python. [#1631](https://github.com/microsoft/kiota/issues/1463)
- Simplified field deserializers for json in Python. [#1632](https://github.com/microsoft/kiota/issues/1492)
- Adds python code generation support. [#1200](https://github.com/microsoft/kiota/issues/163)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The following table provides an overview of the languages supported by Kiota and
| Go | [✔](https://github.com/microsoft/kiota/projects/8) | [✔](https://github.com/microsoft/kiota-abstractions-go) | [JSON](https://github.com/microsoft/kiota-serialization-json-go), [TEXT](https://github.com/microsoft/kiota-serialization-text-go) | [Anonymous](https://github.com/microsoft/kiota-abstractions-go/blob/main/authentication/anonymous_authentication_provider.go), [Azure](https://github.com/microsoft/kiota-authentication-azure-go/) | [✔](https://github.com/microsoft/kiota-http-go/) | [link](https://microsoft.github.io/kiota/get-started/go) |
| Java | [✔](https://github.com/microsoft/kiota/projects/7) | [✔](https://github.com/microsoft/kiota-java/tree/main/components/abstractions) | [JSON](https://github.com/microsoft/kiota-java/tree/main/components/serialization/json), [TEXT](https://github.com/microsoft/kiota-java/tree/main/components/serialization/text) | [Anonymous](https://github.com/microsoft/kiota-java/blob/main/components/abstractions/src/main/java/com/microsoft/kiota/authentication/AnonymousAuthenticationProvider.java), [Azure](https://github.com/microsoft/kiota-java/tree/main/components/authentication/azure) | [✔](https://github.com/microsoft/kiota-java/tree/main/components/http/okHttp) | [link](https://microsoft.github.io/kiota/get-started/java) |
| PHP | [✔](https://github.com/microsoft/kiota/projects/4) | [✔](https://github.com/microsoft/kiota-abstractions-php) | [JSON](https://github.com/microsoft/kiota-serialization-json-php), [TEXT](https://github.com/microsoft/kiota-serialization-text-php) | [Anonymous](https://github.com/microsoft/kiota-abstractions-php/blob/main/src/Authentication/AnonymousAuthenticationProvider.php), [✔️ PHP League](https://github.com/microsoft/kiota-authentication-phpleague-php) | [✔](https://github.com/microsoft/kiota-http-guzzle-php) | [link](https://microsoft.github.io/kiota/get-started/php) |
| Python | [](https://github.com/microsoft/kiota/projects/3) | [✔](./abstractions/python) | [JSON](./serialization/python/json), [❌ TEXT](https://github.com/microsoft/kiota/issues/1406) | [Anonymous](./abstractions/python/kiota/abstractions/authentication/anonymous_authentication_provider.py), [Azure](./authentication/python/azure) | [✔](./http/python/requests) | |
| Python | [](https://github.com/microsoft/kiota/projects/3) | [✔](./abstractions/python) | [JSON](./serialization/python/json), [❌ TEXT](https://github.com/microsoft/kiota/issues/1406) | [Anonymous](./abstractions/python/kiota/abstractions/authentication/anonymous_authentication_provider.py), [Azure](./authentication/python/azure) | [✔](./http/python/requests) | |
| Ruby | [✔](https://github.com/microsoft/kiota/projects/6) | [✔](./abstractions/ruby) | [JSON](./serialization/ruby/json/microsoft_kiota_serialization), [❌ TEXT](https://github.com/microsoft/kiota/issues/1049) | [Anonymous](./abstractions/ruby/microsoft_kiota_abstractions/lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb), [❌ Azure](https://github.com/microsoft/kiota/issues/421) | [✔](./http/ruby/nethttp/microsoft_kiota_nethttplibrary)| [link](https://microsoft.github.io/kiota/get-started/ruby) |
| TypeScript/JavaScript | [✔](https://github.com/microsoft/kiota/projects/2) | [✔](https://github.com/microsoft/kiota-typescript/tree/main/packages/abstractions) | [JSON](https://github.com/microsoft/kiota-typescript/tree/main/packages/serialization/json), [TEXT](https://github.com/microsoft/kiota-typescript/tree/main/packages/serialization/text) | [Anonymous](https://github.com/microsoft/kiota-typescript/blob/main/packages/abstractions/src/authentication/anonymousAuthenticationProvider.ts), [Azure](https://github.com/microsoft/kiota-typescript/tree/main/packages/authentication/azure) | [✔](https://github.com/microsoft/kiota-typescript/tree/main/packages/http/fetch) | [link](https://microsoft.github.io/kiota/get-started/typescript) |
| Shell | [✔](https://github.com/microsoft/kiota/projects/10) | [✔](./abstractions/dotnet), [✔](./cli/commonc) | [JSON](./serialization/dotnet/json), [TEXT](./serialization/dotnet/text) | [Anonymous](./abstractions/dotnet/src/authentication/AnonymousAuthenticationProvider.cs), [Azure](./authentication/dotnet/azure) | [✔](./http/dotnet/httpclient) | [link](https://microsoft.github.io/kiota/get-started/dotnet) |
Expand Down
17 changes: 17 additions & 0 deletions src/Kiota.Builder/PathSegmenters/PythonPathSegmenter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Kiota.Builder.Extensions;

namespace Kiota.Builder;
public class PythonPathSegmenter : CommonPathSegmenter
{
public PythonPathSegmenter(string rootPath, string clientNamespaceName) : base(rootPath, clientNamespaceName) { }
public override string FileSuffix => ".py";
public override string NormalizeFileName(CodeElement currentElement) {
return currentElement switch
{
CodeNamespace => "__init__",
_ => GetDefaultFileName(currentElement)
};
}
private static string GetDefaultFileName(CodeElement currentElement) => GetLastFileNameSegment(currentElement).ToSnakeCase();
public override string NormalizeNamespaceSegment(string segmentName) => segmentName.ToSnakeCase();
}
3 changes: 3 additions & 0 deletions src/Kiota.Builder/Refiners/ILanguageRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public static void Refine(GenerationConfiguration config, CodeNamespace generate
case GenerationLanguage.Swift:
new SwiftRefiner(config).Refine(generatedCode);
break;
case GenerationLanguage.Python:
new PythonRefiner(config).Refine(generatedCode);
break;
default:
break; //Do nothing
}
Expand Down
Loading