elixir-cloud-aai / ga4gh-sdk

Generic SDK and CLI for GA4GH API services
Apache License 2.0
13 stars 2 forks source link

feat: add Python bindings #42

Closed aaravm closed 3 weeks ago

aaravm commented 1 month ago

Adding python bindings for creating structs: Configuration, Transport, ServiceInfo, TES, and adding tests for testing the python bindings. This is done using maturin and pytest, inspired from https://github.com/vemonet/nanopub-rs

Summary by Sourcery

Add Python bindings for the GA4GH SDK using PyO3, enabling interaction with GA4GH services from Python. Implement a Rust module for the TES API, providing task management functionalities. Include comprehensive tests for both the Python bindings and the Rust TES client.

New Features:

Enhancements:

Documentation:

Tests:

sourcery-ai[bot] commented 1 month ago

Reviewer's Guide by Sourcery

This pull request adds Python bindings for the GA4GH SDK, focusing on creating structs like Configuration, Transport, ServiceInfo, TES, and adding tests for these bindings. The implementation uses maturin for building Python extensions and pytest for testing. The changes include modifications to the Rust TES client, addition of Python bindings, and creation of Python tests and documentation.

Class diagram for TES and Task structs with Python bindings

classDiagram
    class TES {
        +Configuration config
        +Result<Service, Box<dyn std::error::Error>> service
        +Transport transport
        +new(config: &Configuration) Result<Self, Box<dyn std::error::Error>>
        +create(task: TesTask) Result<Task, Box<dyn std::error::Error>>
        +get(view: &str, id: &str) Result<TesTask, Box<dyn std::error::Error>>
        +list_tasks(params: Option<ListTasksParams>) Result<TesListTasksResponse, Box<dyn std::error::Error>>
    }
    class Task {
        +String id
        +Transport transport
        +new(id: String, transport: Transport) Self
        +status() Result<TesState, Box<dyn std::error::Error>>
        +cancel() Result<serde_json::Value, Box<dyn std::error::Error>>
    }
    TES --> Task
    TES --> Transport
    TES --> Configuration
    TES --> Service
    Task --> Transport
    class PyTES {
        +TES inner
        +new(config: &PyConfiguration) PyResult<Self>
        +create(task: &PyTesTask) PyResult<PyTask>
        +get(view: &str, id: &str) PyResult<PyTesTask>
    }
    class PyTask {
        +Task inner
        +new(id: String, transport: &PyTransport) PyResult<Self>
        +status() PyResult<String>
        +cancel() PyResult<String>
    }
    PyTES --> TES
    PyTask --> Task
    class PyConfiguration {
        +Configuration inner
        +new(base_path: String) PyResult<Self>
        +set_base_path(base_path: String) PyResult<()>
        +get_base_path() String
    }
    class PyTransport {
        +Transport inner
        +new(py_config: &PyConfiguration) PyResult<Self>
        +get(endpoint: String, params: Option<String>) PyResult<String>
        +post(endpoint: String, data: Option<String>) PyResult<String>
        +put(endpoint: String, data: String) PyResult<String>
        +delete(endpoint: String) PyResult<String>
    }
    PyConfiguration --> Configuration
    PyTransport --> Transport

File-Level Changes

Change Details Files
Implemented Python bindings for GA4GH SDK structs
  • Created PyO3 bindings for Configuration, Transport, ServiceInfo, TES, and Task structs
  • Implemented methods for each struct to expose functionality to Python
  • Added error handling and conversion between Rust and Python types
  • Created a Python module initialization function
python/src/lib.rs
Modified TES client implementation in Rust
  • Added documentation for TES client methods
  • Implemented new methods for TES client (create, get, list_tasks)
  • Added structs for ListTasksParams and TesListTasksResponse
  • Improved error handling and added more comprehensive tests
lib/src/clients/tes/mod.rs
lib/src/clients/tes/model.rs
Added Python tests for the new bindings
  • Created test cases for Configuration, Transport, ServiceInfo, and TES classes
  • Implemented mock objects and patching for testing HTTP requests
  • Added tests for various HTTP methods (GET, POST, PUT, DELETE)
python/tests/test_all.py
python/tests/__init__.py
Added documentation and build instructions for Python bindings
  • Created a README with installation and usage instructions
  • Added information about development and testing processes
  • Included instructions for building the wheel using maturin
python/README.md

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).
pavelnikonorov commented 3 weeks ago

@Xforsa thanks for reviewing!