8000 Fix the issue of sys.argv being cleared on import clr. by filmor · Pull Request #405 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content
8000

Fix the issue of sys.argv being cleared on import clr. #405

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

Merged
merged 1 commit into from
Feb 24, 2017
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
14 changes: 10 additions & 4 deletions src/runtime/pythonengine.cs
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
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
0