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

Python bindings #48

Closed
wants to merge 59 commits into from
Closed

Python bindings #48

wants to merge 59 commits into from

Conversation

larsnaesbye
Copy link
Collaborator

@larsnaesbye larsnaesbye commented Nov 16, 2022

  • expose basic structures like epoch::EpochFlag or observation::LliFlags
  • modules
  • convert record structures (Vec<V> or Map<K, V>)
  • we need a solution for the SBAS nested enum contained in Constellation, pyclass auto derivation does not allow that
  • provide meaningful examples in python
  • wheel auto generation and release
  • readme/docs

@gwbres gwbres added enhancement New feature provided v1.0.0 labels Nov 16, 2022
@gwbres gwbres added this to the v1.0.0 milestone Nov 21, 2022
larsnaesbye and others added 2 commits November 28, 2022 21:05
* 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>
rinex/Cargo.toml Outdated Show resolved Hide resolved
larsnaesbye and others added 3 commits November 28, 2022 22:32
* 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>
/// `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)]
Copy link
Collaborator

@gwbres gwbres Nov 28, 2022

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

Copy link
Collaborator

@gwbres gwbres Nov 30, 2022

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 😄

Copy link
Collaborator

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

@gwbres gwbres self-requested a review November 29, 2022 08:26
larsnaesbye and others added 3 commits November 30, 2022 08:09
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`.
Copy link
Collaborator

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

Copy link
Collaborator Author

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 ?

Copy link
Collaborator

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.

Copy link
Collaborator

@gwbres gwbres Nov 30, 2022

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.

gwbres and others added 11 commits November 30, 2022 19:59
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>()?;
/*
Copy link
Collaborator

@gwbres gwbres Nov 30, 2022

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

@gwbres
Copy link
Collaborator

gwbres commented Dec 1, 2022

For the moment, I will only focus on solving the MacOS builder and unlock the wheel packager.
We have the basis for most of the crate.
We still need to figure out what needs to be done for Record structures (dictionaries, Map<K, V>) and we probably have to submit a PR to PyO3 for the nested Enum case

@larsnaesbye
Copy link
Collaborator Author

and we probably have to submit a PR to PyO3 for the nested Enum case.

Strange that they have not encountered this need before. But I agree.

@larsnaesbye
Copy link
Collaborator Author

@gwbres I resolved the conflict - now on to solving the errors :-D

@larsnaesbye larsnaesbye reopened this Jan 28, 2023
@larsnaesbye
Copy link
Collaborator Author

Rebase done (in a roundabout way, I know...)

@larsnaesbye larsnaesbye added the help wanted Extra attention is needed label May 17, 2023
larsnaesbye and others added 15 commits May 18, 2023 15:39
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>
@larsnaesbye
Copy link
Collaborator Author

Should this work start all over, with the new codebase, new PyO3 and maturin etc.? It's beginning to get a bit hairy....

@gwbres
Copy link
Collaborator

gwbres commented Sep 7, 2023

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.
Cast in both ways must be provided

@larsnaesbye
Copy link
Collaborator Author

Okay, in that case I will close the pull request, so we can start over when we have the time and energy :-)

@larsnaesbye
Copy link
Collaborator Author

Closing to make way for a better PR later.

@larsnaesbye larsnaesbye closed this Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature provided help wanted Extra attention is needed python Python Bindings v1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants