-
Notifications
You must be signed in to change notification settings - Fork 292
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
New python bindings #1087
New python bindings #1087
Conversation
This pull request introduces 1 alert when merging bb7695a into 9267156 - view on LGTM.com new alerts:
|
As I expected, the static build does not work... I'll disable it for the time being. |
So |
@michalvasko would that be OK to export Also, would that be OK to add one utility function: /**
* @brief Return the data path with list key placeholders.
*
* @param[in] node Schema node for which to get the data path.
* @param[in] placeholder String that will be inserted in place of the list key values.
* @return NULL on error, on success the buffer for the resulting path is
* allocated and caller is supposed to free it with free().
*/
char *lys_data_path_pattern(const struct lys_node *node, const char *placeholder); Example of use for the Python bindings: p = lib.lys_data_path_pattern(self._snode, b'"%s"')
p = ffi.string(p).decode('utf-8')
# /module1:container/module2:list[key1="%s"]/sublist[key2="%s"]/leaf
p %= ('val1', 'val2')
# /module1:container/module2:list[key1="val1"]/sublist[key2="val2"]/leaf
p = lib.lys_data_path_pattern(self._snode, b'%r')
p = ffi.string(p).decode('utf-8')
# /module1:container/module2:list[key1=%r]/sublist[key2=%r]/leaf
p %= ('val1', 'val2')
# /module1:container/module2:list[key1='val1']/sublist[key2='val2']/leaf
p = lib.lys_data_path_pattern(self._snode, b'{!r}')
p = ffi.string(p).decode('utf-8')
# /module1:container/module2:list[key1={!r}]/sublist[key2={!r}]/leaf
p = p.format('val1', 'val2')
# /module1:container/module2:list[key1='val1']/sublist[key2='val2']/leaf |
@michalvasko I have made some additional commits to address what I mentioned about new functions in the C library. Please tell me if you prefer that I push them into a separate pull request. Also, I'd like to support
|
... for schema nodes. Refs #1087 Signed-off-by: Robin Jarry <[email protected]>
Hi, Regards, |
Thanks Michal, I rebased on the latest |
Hi, would it be possible to keep also the SWIG bindings as an option? There are some ongoing projects already using this API (even our own libnetconf2) and I don't want to break them. I think that a good thing for this is your change of the Python package name, so they can be distinguished. They can be separated options in CMake and probably even both can be built if required. |
@rkrejci I would find that really confusing. What about adding an option that will allow changing to the old swig bindings, by default the CFFI ones would be compiled and installed? |
@michalvasko That's probably what I'm proposing - having an extra option for SWIG as well as for CFFI bindings, the default one can be the CFFI (as it is now set in the PR) and if required the SWIG Python bindings can be enabled the same way as e.g. the java or javascript bindings. But currently, the SWIG Python bindings are being removed completely. |
Right, not allowing to build both bindings was my main point. |
@michalvasko well, by default. But I don't see any reason why to disable such a setup when I want to build both bindings to support old and new projects depending on different libyang bindings. If I understand it correctly, the old bindings are built as Python yang package while the CFFI bindings are Python libyang package, so they are different even by name. Is it right @rjarry ? |
Like I said, I would simply find it confusing. You could then even use both bindings in a single project, for example. But, as I will likely not be using them or maintaining them, it is not my decision to make. |
Hi @rkrejci, Sure I can leave the SWIG python bindings. However, leaving both bindings enabled by default may be confusing. Building both python bindings should be possible but not the default in my opinion. The question is: which binding is enabled by default? And with which cmake option? I am on vacation today, I'll have a closer look tomorrow. |
@rjarry sure, only one of them will be the default, but I'm not sure which one it should be. I probably slightly tend to have SWIG bindings as the default one. They are there for some time already and if someone is already using python bindings, he will expect the SWIG version. On the other hand, in README or somewhere in doc I would strongly recommend trying the CFFI version since it is expected to be more Pythonic (so it should provide better user experience). |
@rkrejci I have pushed a new version with SWIG bindings left as they are. The default is to build only the legacy bindings. The new CFFI bindings can be enabled (independently from any other SWIG binding) with Following this, I have not modified anything in |
e0801b0
to
a1294ec
Compare
Hi Michal, I have pushed some modifications in the packaging scripts. I only tested the Also, I have modified |
Hi @rkrejci @michalvasko, I have removed the Did you have any more comments on the changes? |
Hi, Other than that, I suppose you could have come up with better names for the test modules but you have your name there :) Also, maybe some simple examples would be nice. Regards, |
Hi Michal, I have built the deb packages only. Not the rpms. About the test module names, I can change them but I am not sure what names would be more appropriate. I have put minimalist examples in the README file. I can add other examples if you want but I figured that the unit tests are good examples. |
Haha you were talking about YANG module names! I thought you were talking about python files. Well a bit of fantasy cannot hurt from time to time :) |
Hi, Regards, |
Glad to hear that, let me know if there is something to do on my end. |
EditorConfig is a file format and collection of text editor plugins for maintaining consistent coding styles between different editors and IDEs. Initialize the file following the current coding style in existing files. In order for this file to be taken into account (unless they use an editor with built-in EditorConfig support), developers will have to install a plugin. Link: https://editorconfig.org/ Link: https://github.com/editorconfig/editorconfig-emacs Link: https://github.com/editorconfig/editorconfig-vim Signed-off-by: Robin Jarry <[email protected]>
Signed-off-by: Robin Jarry <[email protected]>
This is the integration of https://github.com/rjarry/libyang-cffi In the long term, it is intended to replace the existing SWIG bindings. Some highlights: * Uses CFFI for interaction with libyang.so. * More "pythonic" API. Should be easier to use for Python developers. * All high-level code is in Python. Should ease maintenance. * Virtualenv/pip friendly. * Schema diff feature. * New "print" data format: python dict. To enable the generation, add the -DGEN_PYTHON_CFFI_BINDINGS=ON cmake option. It does not depend on SWIG nor on the CPP bindings. It may be enabled even if -DGEN_LANGUAGE_BINDINGS is OFF. Signed-off-by: Robin Jarry <[email protected]>
Hi Michal, I have fixed a minor problem. Seen by code review. Also, I rebased the commits on the latest devel. When do you think this can be merged? |
Hi Robin, sorry, I'm still blocking it wanting to look at that. I tried to compile and import the module, but I'm getting the following error. Am I doing something wrong? The build process seemed fine to me.
|
Hi Radek, it looks like you have the C Maybe you are executing python3 from inside the build dir? |
If you want to try the bindings without installing them you need to export the proper env vars. As it is done for the test commands: |
ok, I fine with it and going to merge it |
Thanks for your work, Robin! |
Thanks Radek! And thank you Michal for the review! |
@rkrejci @michalvasko it looks like the deployment does not work: https://travis-ci.org/github/CESNET/libyang/jobs/693729586#L3715-L3832 There are multiple errors: https://travis-ci.org/github/CESNET/libyang/jobs/693729586#L3737-L3738 https://travis-ci.org/github/CESNET/libyang/jobs/693729586#L3812-L3817 https://travis-ci.org/github/CESNET/libyang/jobs/693729586#L3829 I'm sorry about that, it looks like it is because of commit f7a859a. I don't know how to test this and fix it properly. Can you help? |
The twine error seems related to this: pypa/twine#342 |
The codecov error seems related to this: codecov/codecov-python#261 |
Hi, Regards, |
Yes I'll submit another PR with the fix. |
Hi @michalvasko @rkrejci @Dajvid,
As promised, here is a first draft of the integration of https://github.com/rjarry/libyang-cffi.
Few notes:
.pydistutils.cfg
) and force a value toHOME
during the build so that distutils/setuptools load it. This approach was borrowed from Piotr Ożarowski's pybuild which is used extensively in Debian and Ubuntu to generate Python .deb packages.What is missing:
packages
subfolder (for automatic upload to pypi.org)What do you think?