-
Notifications
You must be signed in to change notification settings - Fork 21
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 bindings #48
Python bindings #48
Conversation
* Cargo.toml: we need hifitime with "python" * epoch naturally comes included * add basis for "Rinex" struct Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
* Cargo.toml: we need hifitime with "python" * epoch naturally comes included * convert epoch flag to pyobject Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
rinex/src/epoch/flag.rs
Outdated
/// `EpochFlag` validates an epoch, | ||
/// or describes possible events that occurred | ||
#[derive(Copy, Clone, Debug)] | ||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
#[cfg_attr(feature = "pyo3", pyclass)] |
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.
@larsnaesbye ,
let's start easy with basic structures that do not have any dependents.
We'll have to solve several issues before we can derive pyclass
for Rinex
.
We can't derive pyclass
for Constellation
because Pyo3 does not allow nested enums like we have for SBAS description for example. Hopefully this is an open topic on their side? i don't know.
Then we need to describe how to convert "complex" structures. Mainly: all record types and vectorized stuff. Apparently this is doable! but I just don't understand how to do it. An auto derivation method does not seem to exist. I think we need to move on to manual derivation (Trait implementation)
Here is the conversion guideline we should follow for Python<->Rust conversion
that would be something like IntoPyList
for vectors, and IntoPyDict
for all record types ?
Finally, Errors must be converted to PyErr or exceptions. This is more documented and we can find examples easily on the web. If you look at the Hifitime/python.rs, they convert their main Error type to a PyErr
object with a simple manual trait implementation. We will probably have to do that for Rinex::Error
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.
I just pushed the basics, it works :)
An example is attached and will get incremented.
Now we need to tackle the hardest parts 😄
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.
and we probably have to submit a PR to
PyO3
for the nested Enum case
we don't necessarily have to go this far. The immediate problem is the pyclass
auto derivation does not support nested enums, that means this macro cannot dictate the code in this scenario.
We just have to to the job ourselves.
And it's probably a manual IntoPyObject
implementation like these ones
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
@@ -90,6 +95,9 @@ select a SBAS for a given location on Earth. | |||
* `--flate2` | |||
allow native parsing of .gz compressed RINEX files. Otherwise, user must uncompress manually the `.gz` extension first. | |||
|
|||
* `--pyo3` (experimental) | |||
Add Python bindings via `PyO3`. To build the Python package, you must first install maturin and then build it with the pyo3 feature flag. For example, `maturin build -F pyo3`. Maturin will then build and place the resulting .whl file in `/target/wheels/`, after which you can install the package with `pip install rinex`. |
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.
It would be awesome to be able to auto generate the wheel
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.
So it gets included with the release, and later uploaded to pypi.org ?
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.
So it gets included with the release
yes, like the application binaries
and later uploaded to pypi.org ?
i did not think about going this far, but I don't foresee any reasons that would not be doable.
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.
We use maturin-action
The wheels are generated for windows and linux.
The generation for macos is currently failing, due to a linking error when the bindings reach "hifitime".
I turned the publication off but it will easily be added.
First we will attach the wheels to the released package, like we do for the compiled -cli.
We can also add a publication to pypi, if you follow the previous link, some people do that.
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
*/ | ||
m.add_class::<Epoch>()?; | ||
m.add_class::<EpochFlag>()?; | ||
/* |
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.
we should design python modules here, following the crate architecture. This would allow for example, when processing Observations:
from rinex import prelude
from rinex import observation
For the moment, I will only focus on solving the MacOS builder and unlock the wheel packager. |
Strange that they have not encountered this need before. But I agree. |
@gwbres I resolved the conflict - now on to solving the errors :-D |
Rebase done (in a roundabout way, I know...) |
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Should this work start all over, with the new codebase, new PyO3 and maturin etc.? It's beginning to get a bit hairy.... |
We only have a couple of useful commits on this branch, it should not take too long to start again from scratch, and is probably easier. Now I understand that we must provide alternative structures, for structures that cannot be bound right away. |
Okay, in that case I will close the pull request, so we can start over when we have the time and energy :-) |
Closing to make way for a better PR later. |
epoch::EpochFlag
orobservation::LliFlags
Vec<V>
orMap<K, V>
)pyclass
auto derivation does not allow that