1use crate::bundle::Bundle;
4use crate::invocation::InvocationDescriptor;
5use once_cell::sync::OnceCell;
6use std::sync::Arc;
7
8pub struct PySession {
10 bundle: Bundle,
11 descriptor: InvocationDescriptor,
12 rawctx_spec_json: OnceCell<Option<Arc<String>>>,
13}
14
15impl PySession {
16 pub(crate) fn new(bundle: Bundle, descriptor: InvocationDescriptor) -> Self {
17 Self {
18 bundle,
19 descriptor,
20 rawctx_spec_json: OnceCell::new(),
21 }
22 }
23
24 pub fn entrypoint(&self) -> &str {
26 self.descriptor.entrypoint()
27 }
28
29 pub fn bundle(&self) -> &Bundle {
31 &self.bundle
32 }
33
34 pub fn descriptor(&self) -> &InvocationDescriptor {
36 &self.descriptor
37 }
38
39 pub(crate) fn rawctx_spec_json<E, F>(&self, build: F) -> Result<Option<Arc<String>>, E>
40 where
41 F: FnOnce() -> Result<Option<String>, E>,
42 {
43 Ok(self
44 .rawctx_spec_json
45 .get_or_try_init(|| build().map(|value| value.map(Arc::new)))?
46 .clone())
47 }
48
49 pub fn manifest(&self) -> impl Iterator<Item = (&str, usize)> {
51 self.bundle
52 .entries()
53 .iter()
54 .map(|entry| (entry.path(), entry.contents().len()))
55 }
56}