Skip to content

Commit d5dd7b4

Browse files
committed
Use PYTHONDONTWRITEBYTECODE instead of -B flag when running Python plugins
1 parent fa8cd54 commit d5dd7b4

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

Flow.Launcher.Core/Plugin/PythonPlugin.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public PythonPlugin(string filename)
2626

2727
var path = Path.Combine(Constant.ProgramDirectory, JsonRPC);
2828
_startInfo.EnvironmentVariables["PYTHONPATH"] = path;
29+
// Prevent Python from writing .py[co] files.
30+
// Because .pyc contains location infos which will prevent python portable.
31+
_startInfo.EnvironmentVariables["PYTHONDONTWRITEBYTECODE"] = "1";
2932

3033
_startInfo.EnvironmentVariables["FLOW_VERSION"] = Constant.Version;
3134
_startInfo.EnvironmentVariables["FLOW_PROGRAM_DIRECTORY"] = Constant.ProgramDirectory;
@@ -76,15 +79,13 @@ import runpy
7679
// Plugins always expect the JSON data to be in the third argument
7780
// (we're always setting it as _startInfo.ArgumentList[2] = ...).
7881
_startInfo.ArgumentList.Add("");
79-
// Because plugins always expect the JSON data to be in the third argument, and specifying -c <code>
80-
// takes up two arguments, we have to move `-B` to the end.
81-
_startInfo.ArgumentList.Add("-B");
8282
}
8383
// Run .pyz files as is
8484
else
8585
{
86-
// -B flag is needed to tell python not to write .py[co] files.
87-
// Because .pyc contains location infos which will prevent python portable
86+
// No need for -B flag because we're using PYTHONDONTWRITEBYTECODE env variable now,
87+
// but the plugins still expect data to be sent as the third argument, so we're keeping
88+
// the flag here, even though it's not necessary anymore.
8889
_startInfo.ArgumentList.Add("-B");
8990
_startInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath);
9091
// Plugins always expect the JSON data to be in the third argument

Flow.Launcher.Core/Plugin/PythonPluginV2.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ public PythonPluginV2(string filename)
2626

2727
var path = Path.Combine(Constant.ProgramDirectory, JsonRpc);
2828
StartInfo.EnvironmentVariables["PYTHONPATH"] = path;
29-
30-
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
31-
StartInfo.ArgumentList.Add("-B");
29+
StartInfo.EnvironmentVariables["PYTHONDONTWRITEBYTECODE"] = "1";
3230
}
3331

3432
public override async Task InitAsync(PluginInitContext context)

0 commit comments

Comments
 (0)