#![allow(dead_code, unused_imports, clippy::too_many_arguments)]
#[allow(dead_code, unused_imports, clippy::too_many_arguments)]
pub mod catalog;
#[allow(dead_code, unused_imports, clippy::too_many_arguments)]
pub mod schema;
pub mod error;
pub mod runtime;
use std::collections::HashMap;
use futures::stream::TryStreamExt;
use pyo3::prelude::*;
use example_client::ExampleClient;
use crate::codegen::error::{PyExampleError, PyExampleResult};
use example_common::models::catalog::v1::*;
use example_common::models::schemas::v1::*;
use example_common::models::tags::v1::*;
use example_common::models::*;
use crate::codegen::catalog::PyCatalogClient;
use crate::codegen::schema::PySchemaClient;
#[pyclass(name = "ExampleClient", module = "example._core")]
pub struct PyExampleClient {
pub(crate) client: ExampleClient,
}
#[pymethods]
impl PyExampleClient {
#[new]
#[pyo3(signature = (base_url, token = None))]
pub fn new(base_url: String, token: Option<String>) -> PyResult<Self> {
let base_url = base_url.parse().map_err(PyExampleError::from)?;
let client = match token {
Some(token) => ExampleClient::new_with_token(base_url, token),
None => ExampleClient::new_unauthenticated(base_url),
};
Ok(Self { client })
}
#[pyo3(signature = (catalog = None))]
pub fn create_catalog(
&self,
py: Python,
catalog: ::core::option::Option<PyCatalog>,
) -> PyExampleResult<PyCatalog> {
let request = self
.client
.create_catalog()
.with_catalog(catalog.map(::core::convert::Into::into));
#[allow(clippy::let_unit_value)]
let result = crate::codegen::runtime::block_on(py, request.into_future())??;
Ok(PyCatalog::from(result))
}
#[pyo3(signature = (max_results))]
pub fn list_catalogs(
&self,
py: Python,
max_results: i32,
) -> PyExampleResult<::std::vec::Vec<PyCatalog>> {
let request = self
.client
.list_catalogs(max_results, ::std::string::String::new());
#[allow(clippy::let_unit_value)]
let result = crate::codegen::runtime::block_on(
py,
async move {
request.into_stream().try_collect::<::std::vec::Vec<_>>().await
},
)??;
Ok(result.into_iter().map(PyCatalog::from).collect::<::std::vec::Vec<_>>())
}
#[pyo3(signature = (catalog_id))]
pub fn generate_catalog_token(
&self,
py: Python,
catalog_id: String,
) -> PyExampleResult<PyCatalogToken> {
let request = self.client.generate_catalog_token(catalog_id);
#[allow(clippy::let_unit_value)]
let result = crate::codegen::runtime::block_on(py, request.into_future())??;
Ok(PyCatalogToken::from(result))
}
#[pyo3(signature = (tags, max_results))]
pub fn list_by_tags(
&self,
py: Python,
tags: Vec<String>,
max_results: i32,
) -> PyExampleResult<PyListByTagsResponse> {
let request = self.client.list_by_tags(tags, max_results);
#[allow(clippy::let_unit_value)]
let result = crate::codegen::runtime::block_on(py, request.into_future())??;
Ok(PyListByTagsResponse::from(result))
}
#[pyo3(signature = (catalog_type))]
pub fn list_by_catalog_type(
&self,
py: Python,
catalog_type: PyCatalogType,
) -> PyExampleResult<PyListByTagsResponse> {
let request = self.client.list_by_catalog_type(catalog_type.into());
#[allow(clippy::let_unit_value)]
let result = crate::codegen::runtime::block_on(py, request.into_future())??;
Ok(PyListByTagsResponse::from(result))
}
#[pyo3(signature = (name, catalog_name, schema_type))]
pub fn create_schema(
&self,
py: Python,
name: String,
catalog_name: String,
schema_type: PySchemaType,
) -> PyExampleResult<PySchema> {
let request = self.client.create_schema(name, catalog_name, schema_type.into());
#[allow(clippy::let_unit_value)]
let result = crate::codegen::runtime::block_on(py, request.into_future())??;
Ok(PySchema::from(result))
}
#[pyo3(signature = (catalog_name, max_results))]
pub fn list_schemas(
&self,
py: Python,
catalog_name: String,
max_results: i32,
) -> PyExampleResult<::std::vec::Vec<PySchema>> {
let request = self
.client
.list_schemas(catalog_name, max_results, ::std::string::String::new());
#[allow(clippy::let_unit_value)]
let result = crate::codegen::runtime::block_on(
py,
async move {
request.into_stream().try_collect::<::std::vec::Vec<_>>().await
},
)??;
Ok(result.into_iter().map(PySchema::from).collect::<::std::vec::Vec<_>>())
}
#[pyo3(signature = (entity_type, entity_name, max_results, page_token))]
pub fn list_tag_assignments(
&self,
py: Python,
entity_type: String,
entity_name: String,
max_results: i32,
page_token: String,
) -> PyExampleResult<PyListTagAssignmentsResponse> {
let request = self
.client
.list_tag_assignments(entity_type, entity_name, max_results, page_token);
#[allow(clippy::let_unit_value)]
let result = crate::codegen::runtime::block_on(py, request.into_future())??;
Ok(PyListTagAssignmentsResponse::from(result))
}
#[pyo3(signature = (entity_type, entity_name, tag = None))]
pub fn create_tag_assignment(
&self,
py: Python,
entity_type: String,
entity_name: String,
tag: ::core::option::Option<PyTagAssignment>,
) -> PyExampleResult<PyTagAssignment> {
let request = self
.client
.create_tag_assignment(entity_type, entity_name)
.with_tag(tag.map(::core::convert::Into::into));
#[allow(clippy::let_unit_value)]
let result = crate::codegen::runtime::block_on(py, request.into_future())??;
Ok(PyTagAssignment::from(result))
}
#[pyo3(signature = (entity_type, entity_name, tag_key))]
pub fn fetch_tag_assignment(
&self,
py: Python,
entity_type: String,
entity_name: String,
tag_key: String,
) -> PyExampleResult<PyTagAssignment> {
let request = self.client.get_tag_assignment(entity_type, entity_name, tag_key);
#[allow(clippy::let_unit_value)]
let result = crate::codegen::runtime::block_on(py, request.into_future())??;
Ok(PyTagAssignment::from(result))
}
#[pyo3(signature = (entity_type, entity_name, tag_key))]
pub fn delete_tag_assignment(
&self,
py: Python,
entity_type: String,
entity_name: String,
tag_key: String,
) -> PyExampleResult<PyDeleteTagAssignmentResponse> {
let request = self
.client
.delete_tag_assignment(entity_type, entity_name, tag_key);
#[allow(clippy::let_unit_value)]
let result = crate::codegen::runtime::block_on(py, request.into_future())??;
Ok(PyDeleteTagAssignmentResponse::from(result))
}
#[pyo3(signature = (entity_type, entity_name, tag_key))]
pub fn touch_tag_assignment(
&self,
py: Python,
entity_type: String,
entity_name: String,
tag_key: String,
) -> PyExampleResult<()> {
let request = self
.client
.touch_tag_assignment(entity_type, entity_name, tag_key);
#[allow(clippy::let_unit_value)]
let result = crate::codegen::runtime::block_on(py, request.into_future())??;
Ok(result)
}
pub fn catalog(&self, catalog_name: String) -> PyCatalogClient {
PyCatalogClient {
client: self.client.catalog(catalog_name),
}
}
pub fn schema(&self, catalog_name: String, schema_name: String) -> PySchemaClient {
let full_name = format!("{}.{}", catalog_name, schema_name);
PySchemaClient {
client: self.client.schema_from_full_name(full_name),
}
}
}
pub const CORE_MODULE: &str = "example._core";
const SUBMODULES: &[&str] = &["catalog", "schemas", "tags"];
#[::pyo3::pymodule]
#[pyo3(name = "_core", module = "example")]
pub mod extension_module {
use ::pyo3::prelude::*;
#[pymodule_export]
#[allow(non_upper_case_globals)]
const __version__: &str = env!("CARGO_PKG_VERSION");
#[pymodule_export]
use super::PyExampleClient;
#[pymodule_export]
use crate::codegen::error::{
ExampleError, BadRequestError, UnauthenticatedError, PermissionDeniedError,
NotFoundError, ConflictError, RateLimitError, ServerError,
};
#[pymodule]
pub mod catalog {
#[pymodule_export]
use super::super::{
PyAzureConfig, PyCatalog, PyCatalogStatus, PyCatalogToken,
PyDeleteCatalogResponse, PyListByTagsResponse, PyListCatalogsResponse,
PyS3Config, PyStorageConfig, PyCatalogClient,
};
}
#[pymodule]
pub mod schemas {
#[pymodule_export]
use super::super::{
PyDeleteSchemaResponse, PyListSchemasResponse, PySchema, PySchemaClient,
};
}
#[pymodule]
pub mod tags {
#[pymodule_export]
use super::super::{
PyDeleteTagAssignmentResponse, PyListTagAssignmentsResponse, PyTagAssignment,
};
}
#[pymodule_init]
fn init(py: Python<'_>) -> PyResult<()> {
let modules = py.import("sys")?.getattr("modules")?;
match modules.get_item(super::CORE_MODULE) {
Ok(module) => super::add_submodules_to_sys_modules(module.cast()?),
Err(_) => Ok(()),
}
}
}
pub fn add_submodules_to_sys_modules(
module: &::pyo3::Bound<'_, ::pyo3::types::PyModule>,
) -> ::pyo3::PyResult<()> {
let modules = module.py().import("sys")?.getattr("modules")?;
let name = module.name()?;
for submodule in SUBMODULES {
modules.set_item(format!("{name}.{submodule}"), module.getattr(*submodule)?)?;
}
Ok(())
}