Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions packages/python-packages/api-stub-generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release History

## Version 0.2.11 (2022-04-06)
Added __main__ to execute as module

## Version 0.2.10 (2022-03-09)
Added support for TypedDict classes.
Added support to parse defaults from docstrings. Example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@


def console_entry_point():
print("Running api-stub-generator version {}".format(__version__))
stub_generator = StubGenerator()
apiview = stub_generator.generate_tokens()
json_tokens = stub_generator.serialize(apiview)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from apistub import console_entry_point

if __name__ == "__main__":
console_entry_point()
exit(0)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

VERSION = "0.2.10"
VERSION = "0.2.11"
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,27 @@ public class PythonLanguageService : LanguageProcessor
{
public override string Name { get; } = "Python";
public override string Extension { get; } = ".whl";
public override string VersionString { get; } = "0.2.8";
public override string VersionString { get; } = "0.2.11";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this needed for (I can see I haven't updated it--oops)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already published 0.2.10 to feed. I need latest changes in this PR to integrate published package to APIVIew to run stubgen as a module. So only option is to publish a new version and refer the same when generating/ checking if update is required.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property is still used to check if we need to auto update an existing review or not.


private readonly string _pythonExecutablePath;
public override string ProcessName => _pythonExecutablePath;
private readonly string _apiScriptPath;
public override string ProcessName => _pythonExecutablePath;

static TelemetryClient _telemetryClient = new TelemetryClient(TelemetryConfiguration.CreateDefault());

public PythonLanguageService(IConfiguration configuration)
{
_pythonExecutablePath = configuration["PYTHONEXECUTABLEPATH"] ?? "python";
_apiScriptPath = Path.Combine(Path.GetDirectoryName(typeof(PythonLanguageService).Assembly.Location), "api-stub-generator", "apistubgen.py");
}
public override string GetProcessorArguments(string originalName, string tempDirectory, string jsonPath)
{
return $"{_apiScriptPath} --pkg-path {originalName} --temp-path {tempDirectory}" +
return $" -m apistub --pkg-path {originalName} --temp-path {tempDirectory}" +
$" --out-path {jsonPath} --hide-report";
}

private string GetPythonVirtualEnv(string tempDirectory)
{
// Create virtual instance
RunProcess(tempDirectory, ProcessName, $" -m virtualenv {tempDirectory} --system-site-packages");
RunProcess(tempDirectory, ProcessName, $" -m virtualenv {tempDirectory} --system-site-packages --seeder app-data --symlink-app-data");
return Path.Combine(tempDirectory, "Scripts", "python.exe");
}

Expand All @@ -59,9 +57,9 @@ public override async Task<CodeFile> GetCodeFileAsync(string originalName, Strea
}
try
{
var apiStubGenPath = GetPythonVirtualEnv(tempDirectory);
var pythonVenvPath = GetPythonVirtualEnv(tempDirectory);
var arguments = GetProcessorArguments(originalName, tempDirectory, jsonFilePath);
RunProcess(tempDirectory, apiStubGenPath, arguments);
RunProcess(tempDirectory, pythonVenvPath, arguments);
_telemetryClient.TrackEvent("Completed Python process run to parse " + originalName);
using (var codeFileStream = File.OpenRead(jsonFilePath))
{
Expand Down