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
7 changes: 7 additions & 0 deletions Frends.Python.ExecuteScript/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [1.1.0] - 2025-12-05

### Changed

- Add more specific error message when python is not installed or not found in PATH.


## [1.0.0] - 2025-09-11

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,4 @@ public async Task ResultContainsStandardError()
};

private static Options DefaultOptions() => new() { ThrowErrorOnFailure = true, ErrorMessageOnFailure = null };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public static async Task<Result> ExecuteScript(
var stdError = string.Empty;
var stdOutput = string.Empty;
using var process = new Process();

try
{
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
await ValidatePythonAvailability(cancellationToken);

var command = GenerateCommand(isWindows, input);
var argumentsPrefix = isWindows ? "/C" : "-c";
var command = GenerateCommand(IsWindows(), input);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
var psi = new ProcessStartInfo
{
FileName = isWindows ? "cmd" : "/bin/bash",
Arguments = $"{argumentsPrefix} {command}",
FileName = IsWindows() ? "cmd" : "/bin/bash",
Arguments = $"{GetArgumentsPrefix()} {command}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
Expand Down Expand Up @@ -104,6 +104,7 @@ private static string GenerateCommand(bool isWindows, Input input)
};

string fullCommand;

if (input.IsPreparationNeeded)
{
fullCommand = isWindows
Expand All @@ -117,4 +118,36 @@ private static string GenerateCommand(bool isWindows, Input input)

return fullCommand;
}

private static async Task ValidatePythonAvailability(CancellationToken cancellationToken)
{
using var process = new Process();
var psi = new ProcessStartInfo
{
FileName = IsWindows() ? "cmd" : "/bin/bash",
Arguments = $"{GetArgumentsPrefix()} python --version",
UseShellExecute = true,
CreateNoWindow = true,
};
process.StartInfo = psi;

try
{
process.Start();
await process.WaitForExitAsync(cancellationToken);
}
finally
{
if (!process.HasExited) process.Kill(true);
}

var exitCode = process.ExitCode;

if (exitCode != 0)
throw new Exception($"Python is not installed or not added to PATH. Exit code: {exitCode}.");
}
Comment thread
MatteoDelOmbra marked this conversation as resolved.

private static string GetArgumentsPrefix() => IsWindows() ? "/C" : "-c";

private static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
<Authors>Frends</Authors>
<Copyright>Copyright (c) 2025 Frends EiPaaS</Copyright>
<Company>Frends</Company>
Expand Down
Loading