Skip to content
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

Forward port old bindings code which handled python import from ruby/perl, etc #21

Merged
merged 32 commits into from
Jan 18, 2019
Merged

Conversation

dmulder
Copy link
Member

@dmulder dmulder commented Jan 9, 2019

Importing python modules from ruby/perl is now possible using this old code that's been re-integrated (and builds via python3).

@dmulder
Copy link
Member Author

dmulder commented Jan 9, 2019

This version builds and works with python2 and python3.

Python yast modules most be declared like this:

from yast import Declare
  
@Declare("integer")
def Test():
    print('this is python test code')
    return 0

@Declare("string", "string")
def Test2(input):
    return input + 'something'

The parameters to Declare are the return type, followed by the types of the parameters. Valid types include any, boolean, string, integer, term, symbol, path, float, void, map, and list (the YCP types).

@dmulder dmulder requested a review from noelpower January 9, 2019 20:45
@dmulder
Copy link
Member Author

dmulder commented Jan 9, 2019

Well, importing a python module via python code succeeds. I just got a segfault import python from ruby.

@dmulder
Copy link
Member Author

dmulder commented Jan 9, 2019

Well, importing a python module via python code succeeds. I just got a segfault import python from ruby.

I mistakenly removed the python initialization code (which isn't needed when a python module is called from python). Added this back and now python import from ruby is working.

dmulder and others added 26 commits January 17, 2019 01:54
… YPythonNamespace

These components allow python to be imported from ruby/perl bindings
We need all the bindings available in py2lang in
order for python import from ruby/perl to work.
Import from file and path doesn't work in py3
-       int ret = PyDict_SetItem(YPython::_pMainDicts, pModuleName, PyModule_GetDict(pMain));
+       int ret = PyDict_SetItemString(YPython::_pMainDicts, module_name.c_str(), PyModule_GetDict(pMain));

Had to change the Dict access above because it didn't work from py3 when
getting called from ruby. OTOH it worked fined from python (where the python
client was calling import_module "aPythonModule"
* Make private data private
* limit access to static methods, try and force access via the
  singleton instance

These changes should make it easier to control access to the dirty
internals such as pMainDicts. Probably there should be only one
place where pMainDicts is created (the ctor ?).
Instead make sure there is just a single instance of _pMainDicts
owned by the YPython singleton. This should make it easier to track
problems
create new independant module (to store the references to the actual
python module) This will avoid clashes with internal dictionaries for
module objects created with the same name as already imported modules
Following the previous fix decrementing the Module pointer causes a
crash on exit
For simplification lets remove stuff we don't use
Copy link
Contributor

@noelpower noelpower left a comment

Choose a reason for hiding this comment

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

LGTM good steps forward (more to go :-))

@dmulder dmulder merged commit afb2465 into yast:master Jan 18, 2019
@dmulder dmulder deleted the ypython branch January 18, 2019 19:06
@yast-bot
Copy link
Contributor

❌ Internal Jenkins job #8 failed

@yast-bot
Copy link
Contributor

❌ Public Jenkins job #7 failed

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.

3 participants