FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix the issue of sys.argv being cleared on import clr. by filmor · Pull Request #405 · pythonnet/pythonnet · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 10 additions & 4 deletions src/runtime/pythonengine.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ public static int RunSimpleString(string code)

public static void Initialize()
{
Initialize(Enumerable.Empty<string>());
Initialize(setSysArgv: true);
}

public static void Initialize(bool setSysArgv = true)
{
Initialize(Enumerable.Empty<string>(), setSysArgv: setSysArgv);
}

/// <summary>
Expand All @@ -134,7 +139,7 @@ public static void Initialize()
/// first call. It is *not* necessary to hold the Python global
/// interpreter lock (GIL) to call this method.
/// </remarks>
public static void Initialize(IEnumerable<string> args)
public static void Initialize(IEnumerable<string> args, bool setSysArgv = true)
{
if (!initialized)
{
Expand All @@ -148,7 +153,8 @@ public static void Initialize(IEnumerable<string> args)
initialized = true;
Exceptions.Clear();

Py.SetArgv(args);
if (setSysArgv)
Py.SetArgv(args);

// register the atexit callback (this doesn't use Py_AtExit as the C atexit
// callbacks are called after python is fully finalized but the python ones
Expand Down Expand Up @@ -213,7 +219,7 @@ public static void InitExt()
{
try
{
Initialize();
Initialize(setSysArgv: false);

// Trickery - when the import hook is installed into an already
// running Python, the standard import machinery is still in
Expand Down
3 changes: 0 additions & 3 deletions src/tests/test_sysargv.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

import sys

import pytest

from ._compat import check_output


@pytest.mark.xfail(reason="argv being reset on import clr. See gh#404")
def test_sys_argv_state(filepath):
"""Test sys.argv state doesn't change after clr import.
To better control the arguments being passed, test on a fresh python
Expand Down

Back | FazBrowse Home | New Git URL