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

Add pysetargv by filmor · Pull Request #347 · pythonnet/pythonnet · GitHub

Add pysetargv - #347

Merged
vmuriart merged 5 commits into
pythonnet:masterfrom
filmor:add-pysetargv
Feb 1, 2017
Merged

Add pysetargv#347
vmuriart merged 5 commits into
pythonnet:masterfrom
filmor:add-pysetargv

Conversation

filmor commented Jan 31, 2017
edited
Loading

Copy link
Copy Markdown
Member

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..

Copy link
Copy Markdown
Contributor

This replaces #301?

Comment thread src/runtime/runtime.cs Outdated
PyImport_GetModuleDict();


#if !(PYTHON26 || PYTHON27)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can this be #if PYTHON3 ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, I'll change it.

filmor commented Jan 31, 2017

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

first need to check that it is not null

filmor Jan 31, 2017
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Comment thread src/runtime/Python.Runtime.csproj Outdated
<Optimize>false</Optimize>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<DefineConstants>TRACE;DEBUG;PYTHON3;PYTHON35;UCS2</DefineConstants>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Updated #346 to include configuration for PY3 development.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

@filmor rebased your work here

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

codecov-io commented Feb 1, 2017
edited
Loading

Copy link
Copy Markdown

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 merged commit 3785c40 into pythonnet:master Feb 1, 2017
vmuriart added a commit that referenced this pull request Feb 1, 2017

Copy link
Copy Markdown
Contributor

@filmor the coverage on pythonengine.cs reduced

vmuriart commented Feb 1, 2017

Copy link
Copy Markdown
Contributor

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

Comment thread src/runtime/interop.cs
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

where m_free is set?

/// This class provides the public interface of the Python runtime.
/// </summary>
public class PythonEngine
public class PythonEngine : IDisposable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

why is this now IDisposable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

{
throw new PythonException();
}
Py.Throw();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

why not also check for IntPtr.Zero?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

i did not click submit review few weeks ago

filmor deleted the add-pysetargv branch March 6, 2019 16:20
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
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


Back | FazBrowse Home | New Git URL