-
Notifications
You must be signed in to change notification settings - Fork 49
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
python: add bindings for libflux-idset,hostlist #3341
python: add bindings for libflux-idset,hostlist #3341
Conversation
This pull request introduces 3 alerts when merging 26b22c2 into 5945183 - view on LGTM.com new alerts:
|
26b22c2
to
7b6a3a1
Compare
Force-pushed fixes for the python errors caught by LGTM. |
Just playing with this a little. I can't seem make |
No, and I thought I had tests for that but I must have accidentally dropped them at some point. Nice catch. I'll work on a fix. |
ec02323
to
5132efb
Compare
This pull request introduces 1 alert when merging 5132efb into 02ee7a1 - view on LGTM.com new alerts:
|
1069ec8
to
bad84d9
Compare
src/bindings/python/flux/hostlist.py
Outdated
@@ -167,6 +201,6 @@ def copy(self): | |||
return Hostlist(handle=self.pimpl.copy()) | |||
|
|||
|
|||
def decode(string): | |||
def decode(arg): | |||
"""Decode a string in RFC 29 hostlist format to a Hostlist object""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this comment be updated to string or iterable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, thanks. I'm actually not sure of Python idioms, if hostlist.decode()
just directly calls hostlist.Hostlist()
is it even useful to separately provide that function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point. can't speak for whats common, but since there is an encode
, i think it's nice to have a decode
, minimally so people can search for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good point! It doesn't do any harm at least...
bad84d9
to
64f0e24
Compare
Ok, pushed some fixup commits to address comments and improve interface and tests:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! That fixed my problem and offhand I'm not finding anything else.
It's really cool to be able to use these "natively" in python!
I'll give my approval although someone with stronger python-fu like @chu11 probably ought to give a nod also.
Thanks. As I noted above in a comment, I'm not sure if the separate I was going to stop here for now and then see if an extra interfaces or minor interface changes popped out of work in Python-based flux utilities like |
Ok, perhaps I'll squash the fixup commits unless there is any objection? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but my python-fu is probably not much better than @garlick
96e9929
to
5099f14
Compare
Actually, I'm not sure the approach used here (idset and hostlist each under their own ffi instance) will work. The I really don't know anything about cffi yet, so I wonder if either @trws or @SteVwonder can give a hint on what might be the right approach here. Note that the use case is that an Right now when I attempt that I get the error:
|
Ah, just after the call I found that using from _hostlist_build import ffi as hostlist_ffi
from _idset_build import ffi as idset_ffi
ffi = FFI()
ffi.include(hostlist_ffi)
ffi.include(idset_ffi) Then I am able to instantiate def nodelist(self):
return Hostlist(handle=self.pimpl.nodelist())
def ranks(self):
return IDset(handle=self.pimpl.ranks()) |
Ok, since there is a path forward for composing FFI objects from multiple sources, I think this one is ok to go in as is. We can add minor tweaks as we come up with users of these new classes. I added one more commit here. I noticed the asan builder was timing out when it seemed like the build would have completed given more time. Perhaps with the addition of extra tests the 40m timeout was not quite enough, so I've added a commit to increase the timeout to 50m. |
Sounds good! Set MWP? |
This is exactly what you want here I think. If they’re included the
ffi objects and type-identifiers are cross-compatible. We used to do
this for several flux core components before re-working the build to
build all of the standard core components as one module.
…On 16 Nov 2020, at 14:29, Mark Grondona wrote:
Ah, just after the call I found that using `ffi.include()` "seems" to
work, e.g. in the new `_idset_build.py` the `hostlist` and `idset`
FFIs are included via
```python
from _hostlist_build import ffi as hostlist_ffi
from _idset_build import ffi as idset_ffi
ffi = FFI()
ffi.include(hostlist_ffi)
ffi.include(idset_ffi)
```
Then I am able to instantiate `Hostlist` and `IDset` objects in the
`rlist.py` module with simply:
```python
def nodelist(self):
return Hostlist(handle=self.pimpl.nodelist())
def ranks(self):
return IDset(handle=self.pimpl.ranks())
```
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#3341 (comment)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @grondo for putting this together. LGTM! Two totally optional comments below:
b999641
to
7952de7
Compare
Ok, I've pushed an update that replaces the use of |
7952de7
to
538173f
Compare
Codecov Report
@@ Coverage Diff @@
## master #3341 +/- ##
==========================================
+ Coverage 81.84% 81.96% +0.11%
==========================================
Files 298 300 +2
Lines 46146 46394 +248
==========================================
+ Hits 37767 38025 +258
+ Misses 8379 8369 -10
|
LGTM! Ready for the MWP label? |
Ok, sure, thanks! |
Ah, this will have to be manually merged since I've modified Let me rebase first. |
Problem: There is no Python interface for RFC29 hostlist format, which is now used in Rv1 in flux-core. Make a simple Hostlist class which wraps Flux's libhostlist, so that Python programs can operate on hostlists with exact compatibility with C code. Fixes flux-framework#3250
Problem: There is no Python interface for RFC22 Idset encoding. Add a simple Python IDset class which wraps libidset so that Python programs can encode/decode and manipulate idsets with full compatibility with the C library.
Add unit tests for the Python hostlist bindings
Add unit tests for the Python idset bindings.
Problem: The cffi emit_c_code() function does not update the target if it believes the generated .c file is already up-to-date. This causes make confusion because the file is never updated if one of its other prerequisites changes (e.g. Makefile), so the rule will continually be rerun on each make invocation. Ensure the target file mtime is updated in the *_build.py scripts by "touching" the file after ffi.emit_c_code() is complete. This way make won't unnecessarily re-run the rule to update the target.
Wrap rules in src/bindings/python/_flux/Makefile.am in necessary automake variables to make the output quiet by default. As with the rest of the build system `make V=1` will restore the extra-chatty build.
Problem: mypy complains about the _flux.* generated bindings with the error "Cannot find implementation or library stub for module". Add 'ignore_missing_imports' for _flux._hostlist and _flux._idset.
Problem: As we add more tests to the full `make check`, the ASan github workflow build is taking longer. The current time limit is 40m, but sometimes this is not quite long enough. Add another 10 minutes to the asan builder timeout to avoid premature timeouts of this workflow run.
538173f
to
e7bd68a
Compare
All the tests pass, so I'm going to push the button. Thanks @grondo! |
Thanks!! |
This PR is pretty straightforward. It adds basic
IDset
andHostlist
Python classes which wrap libflux-idset.so and libflux-hostlist.so.I was also going to make automated bindings for librlist to make an Rv1 class, however I decided to stop here and make the Rv1 class a separate PR.