Skip to content

Commit 31c6448

Browse files
Address review comments: remove .NET prefix and hardcode streamlit executable
Co-authored-by: tommasodotNET <[email protected]>
1 parent d19ecb3 commit 31c6448

File tree

4 files changed

+6
-48
lines changed

4 files changed

+6
-48
lines changed

examples/python/streamlit-api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Streamlit API Example
22

3-
This is a simple Streamlit application that demonstrates how to run Streamlit apps in .NET Aspire using the Python Extensions.
3+
This is a simple Streamlit application that demonstrates how to run Streamlit apps in Aspire using the Python Extensions.
44

55
## Prerequisites
66

examples/python/streamlit-api/app.py

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

44
st.title("Hello, Aspire!")
55

6-
st.write("This is a simple Streamlit app running in .NET Aspire.")
6+
st.write("This is a simple Streamlit app running in Aspire.")
77

88
port = os.environ.get("PORT", "8501")
99
st.write(f"Running on port: {port}")

src/CommunityToolkit.Aspire.Hosting.Python.Extensions/StreamlitAppHostingExtension.cs

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Aspire.Hosting.ApplicationModel;
2-
using Aspire.Hosting.Python;
32
using CommunityToolkit.Aspire.Utils;
43

54
namespace Aspire.Hosting;
@@ -46,17 +45,9 @@ private static IResourceBuilder<StreamlitAppResource> AddStreamlitApp(
4645

4746
projectDirectory = PathNormalizer.NormalizePathForCurrentPlatform(Path.Combine(builder.AppHostDirectory, wd));
4847

49-
var virtualEnvironment = new VirtualEnvironment(Path.IsPathRooted(virtualEnvironmentPath)
50-
? virtualEnvironmentPath
51-
: Path.Join(projectDirectory, virtualEnvironmentPath));
48+
var projectResource = new StreamlitAppResource(name, projectDirectory);
5249

53-
var instrumentationExecutable = virtualEnvironment.GetExecutable("opentelemetry-instrument");
54-
var streamlitExecutable = virtualEnvironment.GetExecutable("streamlit") ?? "streamlit";
55-
var projectExecutable = instrumentationExecutable ?? streamlitExecutable;
56-
57-
var projectResource = new StreamlitAppResource(name, projectExecutable, projectDirectory);
58-
59-
var resourceBuilder = builder.AddResource(projectResource)
50+
return builder.AddResource(projectResource)
6051
.WithEnvironment(context =>
6152
{
6253
// Streamlit uses STREAMLIT_SERVER_PORT instead of PORT, so map PORT to STREAMLIT_SERVER_PORT
@@ -67,28 +58,8 @@ private static IResourceBuilder<StreamlitAppResource> AddStreamlitApp(
6758
})
6859
.WithArgs(context =>
6960
{
70-
// If the project is to be automatically instrumented, add the instrumentation executable arguments first.
71-
if (!string.IsNullOrEmpty(instrumentationExecutable))
72-
{
73-
AddOpenTelemetryArguments(context);
74-
75-
// Add the streamlit executable as the next argument so we can run the project.
76-
context.Args.Add("streamlit");
77-
}
78-
7961
AddProjectArguments(scriptPath, args, context);
8062
});
81-
82-
if (!string.IsNullOrEmpty(instrumentationExecutable))
83-
{
84-
resourceBuilder.WithOtlpExporter();
85-
86-
// Make sure to attach the logging instrumentation setting, so we can capture logs.
87-
// Without this you'll need to configure logging yourself. Which is kind of a pain.
88-
resourceBuilder.WithEnvironment("OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED", "true");
89-
}
90-
91-
return resourceBuilder;
9263
}
9364

9465
private static void AddProjectArguments(string scriptPath, string[] scriptArgs, CommandLineArgsCallbackContext context)
@@ -105,16 +76,4 @@ private static void AddProjectArguments(string scriptPath, string[] scriptArgs,
10576
context.Args.Add(arg);
10677
}
10778
}
108-
109-
private static void AddOpenTelemetryArguments(CommandLineArgsCallbackContext context)
110-
{
111-
context.Args.Add("--traces_exporter");
112-
context.Args.Add("otlp");
113-
114-
context.Args.Add("--logs_exporter");
115-
context.Args.Add("console,otlp");
116-
117-
context.Args.Add("--metrics_exporter");
118-
context.Args.Add("otlp");
119-
}
12079
}

src/CommunityToolkit.Aspire.Hosting.Python.Extensions/StreamlitAppResource.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Aspire.Hosting.ApplicationModel;
66
/// Represents a Streamlit application.
77
/// </summary>
88
/// <param name="name">The name of the resource.</param>
9-
/// <param name="executablePath">The path to the executable used to run the python app.</param>
109
/// <param name="workingDirectory">The working directory for streamlit.</param>
11-
public class StreamlitAppResource(string name, string executablePath, string workingDirectory)
12-
: PythonAppResource(name, executablePath, workingDirectory), IResourceWithServiceDiscovery;
10+
public class StreamlitAppResource(string name, string workingDirectory)
11+
: PythonAppResource(name, "streamlit", workingDirectory), IResourceWithServiceDiscovery;

0 commit comments

Comments
 (0)