Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

add function codec#1

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
koubaa wants to merge3 commits intopythonnet:masterfromkoubaa:function-codec
Closed

Conversation

@koubaa
Copy link

@koubaakoubaa commentedMar 29, 2020
edited
Loading

@lostmsu While running the test I get the exception "Could not load python37.dll". I wanted to push this first to get a preliminary review while I figure that out. It also appears that vs2019 is needed (for .net core 3.1). I don't mind but wasn't sure if this was intentional.

@lostmsu
Copy link
Member

@koubaa I've added Python installation to CI. Please, rebase your branch.

@koubaa
Copy link
Author

@koubaa I've added Python installation to CI. Please, rebase your branch.

@lostmsu done. Although I suppose this won't fix the issue testing it locally.

@lostmsu
Copy link
Member

@koubaa Locally, you can go to project settings and set PATH environment variable in the Debug section. I personally just have a setup class in the test project, that I never commit:

[SetUpFixture]publicclassLocalTestConfig{[OneTimeSetUp]publicvoidAssemblySetup(){Environment.SetEnvironmentVariable("PATH",@"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\;"+Environment.GetEnvironmentVariable("PATH"));PythonEngine.PythonHome=@"C:\Users\USER\AppData\Local\Programs\Python\Python37";}}

@lostmsu
Copy link
Member

Hm, build still fails to find the library. Let me try to fix it.

@koubaa
Copy link
Author

@lostmsu I can try what you did locally, but ideally this info can be in the wiki

@koubaa
Copy link
Author

@lostmsu AssemblySetup didn't work, I debugged and my TestCallBacks SetUp function is called before AssemblySetup. I think the order NUnit runs these is not deterministic and since you can run individual tests from the test explorer I don't think It'll work in general even if it does run that setup first. I'll see if I can figure out how the pythonnet embedding tests sets up the python environment.

@dnfclas
Copy link

dnfclas commentedApr 12, 2020
edited
Loading

CLA assistant check
All CLA requirements met.

@lostmsu
Copy link
Member

@koubaa you have to manually callTestsRuntimeConfig.Ensure(); in[SetUp] for your tests.

@koubaa
Copy link
Author

@lostmsu done. tests fail due to the issue with the return value of the Func

@koubaakoubaa mentioned this pull requestApr 17, 2020
4 tasks
@koubaa
Copy link
Author

@lostmsu these changes are ready and tests pass locally. I don't know what happened to the CI:
https://github.com/pythonnet/codecs/actions/runs/85878219

Copy link
Member

@lostmsulostmsu left a comment

Choose a reason for hiding this comment

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

I can not take this PR as is for two connected reasons:

  1. It is not generic enough. E.g. it should really support any type of delegate via reflection onInvoke (like you did withGetNumArgs).
  2. It reserves unintuitive meaning for standard C# delegate types, especiallyFunc<object[], object>. One should expect, that a parameter of typeFunc<object[], object> should take a Python function, that has a single argument of typelist or C# array, not an arbitrary Python function, that would get objects from the array as individual arguments.

If you have a very specific use case that this fullfills, I suggest to simply keep this codec in your private codebase. Otherwise, it really needs to be properly generalized.

As for the special handling I mentioned in 2., I recommend to create special delegate types, e.g.

delegatevoidVariadicAction(object[]args);

or even

delegatevoidVariadicAction(PyObject[]args);

and use them instead of the standard types for the scenario in 2.

@koubaa
Copy link
Author

@lostmsu I thought you said these were the reasons you couldn't take it in the pythonnet repo but you could take it in the codecs repo?

@lostmsu
Copy link
Member

@koubaa the reason not to take in the main repo is that conversion is lossy. E.g. decode followed by encode do not give an identical (or at least identically behaving) object back.

I think genericity is not really necessary on its own, but "unintuitive meaning for standard C# delegate types" is a real problem. I just think making a generic solution is easy enough vs going the route of defining custom function types to circumvent "unintuitive meaning for standard C# delegate types", and forcing everyone to use them with this codec.

@lostmsu
Copy link
Member

lostmsu commentedMay 11, 2020
edited
Loading

@koubaa BTW, we can take this if you target it to custom delegate types instead ofFunc<object[], object> and other standard ones to avoid confusion. It should be enough for most use cases, users could then just have lambdas forwarding the custom delegate type to whatever type they need. E.g.

delegateobjectPythonFunction(object[]args);voidFoo(PythonFunctionpyFunc){Func<...,object>sharpFunc=(a,b,...)=>pyFunc(newobject[]{a,b, ...});// use sharpFunc normally}

In fact, you don't even need aPythonAction, because no return Python functions still returnNone.

But I strongly suggest to try generalize this usingReflection andReflection.Emit/LINQ expressions.

@koubaa
Copy link
Author

@lostmsu I'll keep it my private repo then. I don't know how to accomplish what you're looking for

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@lostmsulostmsulostmsu requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@koubaa@lostmsu@dnfclas

[8]ページ先頭

©2009-2025 Movatter.jp