-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathlib.rs
More file actions
79 lines (71 loc) · 4.2 KB
/
lib.rs
File metadata and controls
79 lines (71 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
#![doc = include_str!("../docs/lib.md")]
#![warn(unstable_features)]
mod client;
pub(crate) mod py_async;
mod py_err;
mod server;
pub use client::client_sync::{Client, Table, View};
pub use client::proxy_session::ProxySession;
pub use perspective_client::ViewWindow;
pub use perspective_client::config::ViewConfigUpdate;
use py_err::PyPerspectiveError;
use pyo3::prelude::*;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{EnvFilter, fmt};
/// Create a tracing filter which mimics the default behavior of reading from
/// env, customized to exclude timestamp.
/// [`tracing` filter docs](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/layer/index.html#per-layer-filtering)
fn init_tracing() {
let fmt_layer = fmt::layer().without_time().with_target(true);
let filter_layer = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new("info"))
.unwrap();
tracing_subscriber::registry()
.with(filter_layer)
.with(fmt_layer)
.init();
}
/// Returns the number of threads the internal threadpool will use.
#[pyfunction]
fn num_cpus() -> i32 {
perspective_server::num_cpus()
}
/// Set the number of threads the internal threadpool will use. Can also be set
/// with `NUM_OMP_THREADS` environment variable.
#[pyfunction]
fn set_num_cpus(num_cpus: i32) {
perspective_server::set_num_cpus(num_cpus)
}
/// Perspective Python main module.
#[pymodule]
fn perspective(py: Python, m: &Bound<PyModule>) -> PyResult<()> {
init_tracing();
m.add_class::<client::client_sync::Client>()?;
m.add_class::<server::Server>()?;
m.add_class::<server::AsyncServer>()?;
m.add_class::<server::PySession>()?;
m.add_class::<server::PyAsyncSession>()?;
m.add_class::<client::client_sync::Table>()?;
m.add_class::<client::client_sync::View>()?;
m.add_class::<client::client_async::AsyncClient>()?;
m.add_class::<client::client_async::AsyncTable>()?;
m.add_class::<client::client_async::AsyncView>()?;
m.add_class::<client::proxy_session::ProxySession>()?;
m.add_class::<server::virtual_server_sync::PyVirtualServer>()?;
m.add("PerspectiveError", py.get_type::<PyPerspectiveError>())?;
m.add_function(wrap_pyfunction!(num_cpus, m)?)?;
m.add_function(wrap_pyfunction!(set_num_cpus, m)?)?;
Ok(())
}