Skip to content

Commit

Permalink
Use PYTHONDONTWRITEBYTECODE instead of -B flag when running Python pl…
Browse files Browse the repository at this point in the history
…ugins
  • Loading branch information
Yusyuriv committed Dec 5, 2024
1 parent fa8cd54 commit d5dd7b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 6 additions & 5 deletions Flow.Launcher.Core/Plugin/PythonPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public PythonPlugin(string filename)

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

_startInfo.EnvironmentVariables["FLOW_VERSION"] = Constant.Version;
_startInfo.EnvironmentVariables["FLOW_PROGRAM_DIRECTORY"] = Constant.ProgramDirectory;
Expand Down Expand Up @@ -76,15 +79,13 @@ import runpy
// Plugins always expect the JSON data to be in the third argument
// (we're always setting it as _startInfo.ArgumentList[2] = ...).
_startInfo.ArgumentList.Add("");
// Because plugins always expect the JSON data to be in the third argument, and specifying -c <code>
// takes up two arguments, we have to move `-B` to the end.
_startInfo.ArgumentList.Add("-B");
}
// Run .pyz files as is
else
{
// -B flag is needed to tell python not to write .py[co] files.
// Because .pyc contains location infos which will prevent python portable
// No need for -B flag because we're using PYTHONDONTWRITEBYTECODE env variable now,
// but the plugins still expect data to be sent as the third argument, so we're keeping
// the flag here, even though it's not necessary anymore.
_startInfo.ArgumentList.Add("-B");
_startInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath);
// Plugins always expect the JSON data to be in the third argument
Expand Down
4 changes: 1 addition & 3 deletions Flow.Launcher.Core/Plugin/PythonPluginV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public PythonPluginV2(string filename)

var path = Path.Combine(Constant.ProgramDirectory, JsonRpc);
StartInfo.EnvironmentVariables["PYTHONPATH"] = path;

//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
StartInfo.ArgumentList.Add("-B");
StartInfo.EnvironmentVariables["PYTHONDONTWRITEBYTECODE"] = "1";
}

public override async Task InitAsync(PluginInitContext context)
Expand Down

0 comments on commit d5dd7b4

Please sign in to comment.