Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add pysetargv #347

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 5 commits into from
Feb 1, 2017
Merged

Add pysetargv #347

merged 5 commits into from
Feb 1, 2017

Conversation

filmor
Copy link
Member

@filmor filmor commented Jan 31, 2017

What does this implement/fix? Explain your changes.

Implements an overload of Initialize and a Py.SetArgv function that allow the user to issue a PySys_SetArgvEx call. By default, this call is done on Initialize with a list that contains a single empty string (['']), using the arguments supplied to the .NET process if available.

Does this close any currently open issues?

#299.

Any other comments?

Based on the fix-shutdown branch as otherwise I'm not able to run the unit-tests reliably..

@vmuriart
Copy link
Contributor

This replaces #301?

@@ -2027,11 +2027,26 @@ internal unsafe static extern IntPtr
internal unsafe static extern IntPtr
PyImport_GetModuleDict();


#if !(PYTHON26 || PYTHON27)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be #if PYTHON3 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll change it.

@filmor
Copy link
Member Author

filmor commented Jan 31, 2017

Yes, it's an alternative using directly the Python API function.

using (new PythonEngine())
using (var argv = new PyList(Runtime.Runtime.PySys_GetObject("argv")))
{
Assert.That(argv.Length() != 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first need to check that it is not null

Copy link
Member Author

@filmor filmor Jan 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? If it is null, this will fail with a NullReferenceException, perfectly fine. This PR is supposed to ensure that sys.argv is always initialised.

@@ -92,6 +92,7 @@
<Optimize>false</Optimize>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<DefineConstants>TRACE;DEBUG;PYTHON3;PYTHON35;UCS2</DefineConstants>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this gets overwritten by setup.py or specific needs of the user, so no need to update this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He probably added that during his development and forgot to remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated #346 to include configuration for PY3 development.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, exactly that, I'll remove this line.

@den-run-ai
Copy link
Contributor

I'm OK with merging this version as long as comments are addressed

@vmuriart
Copy link
Contributor

@filmor rebased your work here

https://github.com/pythonnet/pythonnet/tree/pysetargv

@codecov-io
Copy link

codecov-io commented Feb 1, 2017

Codecov Report

Merging #347 into master will increase coverage by -0.08%.

@@            Coverage Diff             @@
##           master     #347      +/-   ##
==========================================
- Coverage   61.45%   61.37%   -0.08%     
==========================================
  Files          61       61              
  Lines        5336     5369      +33     
  Branches      900      896       -4     
==========================================
+ Hits         3279     3295      +16     
- Misses       1819     1853      +34     
+ Partials      238      221      -17
Impacted Files Coverage Δ
src/runtime/runtime.cs 81.32% <ø> (ø)
src/runtime/pythonengine.cs 54.16% <36.36%> (-1.18%)
src/runtime/managedtype.cs 46.15% <ø> (ø)
src/runtime/delegatemanager.cs 87.6% <ø> (ø)
src/runtime/converter.cs 75.38% <ø> (ø)
src/runtime/interfaceobject.cs 43.75% <ø> (ø)
src/runtime/classderived.cs 0% <ø> (ø)
src/runtime/pyobject.cs 22.22% <ø> (ø)
src/runtime/exceptions.cs 72.8% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f7f2fc0...3785c40. Read the comment docs.

@vmuriart vmuriart merged commit 3785c40 into pythonnet:master Feb 1, 2017
vmuriart added a commit that referenced this pull request Feb 1, 2017
@den-run-ai
Copy link
Contributor

@filmor the coverage on pythonengine.cs reduced

@vmuriart
Copy link
Contributor

vmuriart commented Feb 1, 2017

It's probably the refactoring he did. The coverage needs some fine tuning, its definetly not as robust as python's coverage engine.

@@ -227,7 +227,7 @@ static ModuleDefOffset()
byte[] ascii = Encoding.ASCII.GetBytes(modulename);
int size = name + ascii.Length + 1;
IntPtr ptr = Marshal.AllocHGlobal(size);
for (int i = 0; i <= m_free; i += IntPtr.Size)
for (int i = 0; i < m_free; i += IntPtr.Size)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where m_free is set?


namespace Python.Runtime
{
/// <summary>
/// This class provides the public interface of the Python runtime.
/// </summary>
public class PythonEngine
public class PythonEngine : IDisposable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this now IDisposable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that's easier to use correctly than Initialize and Shutdown.

{
throw new PythonException();
}
Py.Throw();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not also check for IntPtr.Zero?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this function either returns null and sets an exception, or it returns a module.

{
Initialize(Enumerable.Empty<string>());
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we need to check if sys.argv is non-empty in the case of extending with import clr? @filmor @vmuriart anyway let's see if this passes my tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i did not click submit review few weeks ago

@filmor filmor deleted the add-pysetargv branch March 6, 2019 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants