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

Avoid PATH overflow from SetupPython calls #11215

Merged
merged 1 commit into from
Oct 29, 2020
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
17 changes: 16 additions & 1 deletion src/Libraries/DSCPython/CPythonEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static object EvaluatePythonScript(
return null;
}

Python.Included.Installer.SetupPython().Wait();
InstallPython();

if (!PythonEngine.IsInitialized)
{
Expand Down Expand Up @@ -246,6 +246,21 @@ public static object EvaluatePythonScript(
}
}

private static bool isPythonInstalled = false;
/// <summary>
/// Makes sure Python is installed on the system and it's location added to the path.
/// NOTE: Calling SetupPython multiple times will add the install location to the path many times,
/// potentially causing the environment variable to overflow.
/// </summary>
private static void InstallPython()
{
if (!isPythonInstalled)
{
Python.Included.Installer.SetupPython().Wait();
isPythonInstalled = true;
}
}

/// <summary>
/// Creates and initializaes the global Python scope.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static class ScriptMigrator
/// <returns></returns>
internal static string MigrateCode(string code)
{
Installer.SetupPython().Wait();
InstallPython();

if (!PythonEngine.IsInitialized)
{
Expand Down Expand Up @@ -70,6 +70,21 @@ internal static string MigrateCode(string code)
}
}

private static bool isPythonInstalled = false;
/// <summary>
/// Makes sure Python is installed on the system and it's location added to the path.
/// NOTE: Calling SetupPython multiple times will add the install location to the path many times,
/// potentially causing the environment variable to overflow.
/// </summary>
private static void InstallPython()
{
if (!isPythonInstalled)
{
Installer.SetupPython().Wait();
isPythonInstalled = true;
}
}

private static string Get2To3MigrationScript(Assembly asm)
{
return GetEmbeddedScript(asm, "Dynamo.PythonMigration.MigrationAssistant.migrate_2to3.py");
Expand Down