Skip to main content

PythonEmitter

Struct PythonEmitter 

Source
pub struct PythonEmitter;
Expand description

Version-one Python package emitter.

Implementations§

Source§

impl PythonEmitter

Source

pub const fn new() -> Self

Construct the emitter.

Examples found in repository?
examples/emit_python_acceptance.rs (line 36)
16fn main() {
17    let mut arguments = env::args_os().skip(1);
18    let schema_path = PathBuf::from(arguments.next().expect("schema path is required"));
19    let output_path = PathBuf::from(arguments.next().expect("output path is required"));
20    assert!(
21        arguments.next().is_none(),
22        "only schema and output paths are accepted"
23    );
24
25    let source = fs::read_to_string(&schema_path).expect("acceptance schema is readable");
26    let documents = SchemaDocumentSet::parse([(
27        DocumentId::new("python-acceptance.yaml").expect("document ID is valid"),
28        source,
29    )])
30    .expect("acceptance schema parses");
31    let declared = normalize_documents(&documents).expect("acceptance schema normalizes");
32    let profile_name = env::var("TYPE_BRIDGE_ACCEPTANCE_SEMANTIC_PROFILE")
33        .unwrap_or_else(|_| "typedb-3.12.1/v1".to_owned());
34    let profile = SemanticProfileId::new(&profile_name).expect("semantic profile is valid");
35    let resolved = resolve(&declared, &profile).expect("acceptance schema resolves");
36    let emitter = PythonEmitter::new();
37    let handlers = emitter.generator_handlers();
38    let resources = emitter.code_resources().expect("emitter resources hash");
39    let projection = project(
40        &resolved,
41        BindingTarget::Python,
42        &ProjectionConfig::python(),
43        &handlers,
44        &resources,
45    )
46    .expect("acceptance schema projects");
47    let available: CapabilitySet = BUILTIN_SCHEMA_CAPABILITY_IDS
48        .iter()
49        .map(|id| CapabilityId::new(*id).expect("built-in capability ID"))
50        .collect();
51    let context = ManagedDeltaContext::new(
52        ManagedScopeId::new("python-generated-acceptance").expect("acceptance scope"),
53        profile,
54        available,
55    );
56    let authority = build_schema_authority(&declared, declared.required_capabilities(), &context)
57        .expect("acceptance authority builds");
58    let package = emitter
59        .emit(&projection, &authority)
60        .expect("Python package emits");
61
62    fs::create_dir_all(&output_path).expect("output directory is created");
63    for (relative, bytes) in package.files() {
64        fs::write(output_path.join(relative), bytes).expect("generated file is written");
65    }
66}
Source

pub fn generator_handlers(&self) -> Vec<ProjectionHandler>

Return its exact projection-handler evidence.

Examples found in repository?
examples/emit_python_acceptance.rs (line 37)
16fn main() {
17    let mut arguments = env::args_os().skip(1);
18    let schema_path = PathBuf::from(arguments.next().expect("schema path is required"));
19    let output_path = PathBuf::from(arguments.next().expect("output path is required"));
20    assert!(
21        arguments.next().is_none(),
22        "only schema and output paths are accepted"
23    );
24
25    let source = fs::read_to_string(&schema_path).expect("acceptance schema is readable");
26    let documents = SchemaDocumentSet::parse([(
27        DocumentId::new("python-acceptance.yaml").expect("document ID is valid"),
28        source,
29    )])
30    .expect("acceptance schema parses");
31    let declared = normalize_documents(&documents).expect("acceptance schema normalizes");
32    let profile_name = env::var("TYPE_BRIDGE_ACCEPTANCE_SEMANTIC_PROFILE")
33        .unwrap_or_else(|_| "typedb-3.12.1/v1".to_owned());
34    let profile = SemanticProfileId::new(&profile_name).expect("semantic profile is valid");
35    let resolved = resolve(&declared, &profile).expect("acceptance schema resolves");
36    let emitter = PythonEmitter::new();
37    let handlers = emitter.generator_handlers();
38    let resources = emitter.code_resources().expect("emitter resources hash");
39    let projection = project(
40        &resolved,
41        BindingTarget::Python,
42        &ProjectionConfig::python(),
43        &handlers,
44        &resources,
45    )
46    .expect("acceptance schema projects");
47    let available: CapabilitySet = BUILTIN_SCHEMA_CAPABILITY_IDS
48        .iter()
49        .map(|id| CapabilityId::new(*id).expect("built-in capability ID"))
50        .collect();
51    let context = ManagedDeltaContext::new(
52        ManagedScopeId::new("python-generated-acceptance").expect("acceptance scope"),
53        profile,
54        available,
55    );
56    let authority = build_schema_authority(&declared, declared.required_capabilities(), &context)
57        .expect("acceptance authority builds");
58    let package = emitter
59        .emit(&projection, &authority)
60        .expect("Python package emits");
61
62    fs::create_dir_all(&output_path).expect("output directory is created");
63    for (relative, bytes) in package.files() {
64        fs::write(output_path.join(relative), bytes).expect("generated file is written");
65    }
66}
Source

pub fn code_resources(&self) -> Result<Vec<CodeResourceDigest>, Diagnostic>

Hash its exact fixed output resources.

Examples found in repository?
examples/emit_python_acceptance.rs (line 38)
16fn main() {
17    let mut arguments = env::args_os().skip(1);
18    let schema_path = PathBuf::from(arguments.next().expect("schema path is required"));
19    let output_path = PathBuf::from(arguments.next().expect("output path is required"));
20    assert!(
21        arguments.next().is_none(),
22        "only schema and output paths are accepted"
23    );
24
25    let source = fs::read_to_string(&schema_path).expect("acceptance schema is readable");
26    let documents = SchemaDocumentSet::parse([(
27        DocumentId::new("python-acceptance.yaml").expect("document ID is valid"),
28        source,
29    )])
30    .expect("acceptance schema parses");
31    let declared = normalize_documents(&documents).expect("acceptance schema normalizes");
32    let profile_name = env::var("TYPE_BRIDGE_ACCEPTANCE_SEMANTIC_PROFILE")
33        .unwrap_or_else(|_| "typedb-3.12.1/v1".to_owned());
34    let profile = SemanticProfileId::new(&profile_name).expect("semantic profile is valid");
35    let resolved = resolve(&declared, &profile).expect("acceptance schema resolves");
36    let emitter = PythonEmitter::new();
37    let handlers = emitter.generator_handlers();
38    let resources = emitter.code_resources().expect("emitter resources hash");
39    let projection = project(
40        &resolved,
41        BindingTarget::Python,
42        &ProjectionConfig::python(),
43        &handlers,
44        &resources,
45    )
46    .expect("acceptance schema projects");
47    let available: CapabilitySet = BUILTIN_SCHEMA_CAPABILITY_IDS
48        .iter()
49        .map(|id| CapabilityId::new(*id).expect("built-in capability ID"))
50        .collect();
51    let context = ManagedDeltaContext::new(
52        ManagedScopeId::new("python-generated-acceptance").expect("acceptance scope"),
53        profile,
54        available,
55    );
56    let authority = build_schema_authority(&declared, declared.required_capabilities(), &context)
57        .expect("acceptance authority builds");
58    let package = emitter
59        .emit(&projection, &authority)
60        .expect("Python package emits");
61
62    fs::create_dir_all(&output_path).expect("output directory is created");
63    for (relative, bytes) in package.files() {
64        fs::write(output_path.join(relative), bytes).expect("generated file is written");
65    }
66}
Source

pub fn emit( &self, projection: &RuntimeProjection, authority: &VerifiedSchemaAuthority, ) -> Result<GeneratedPackage, Diagnostic>

Emit one deterministic package bound to exact verified schema authority.

Examples found in repository?
examples/emit_python_acceptance.rs (line 59)
16fn main() {
17    let mut arguments = env::args_os().skip(1);
18    let schema_path = PathBuf::from(arguments.next().expect("schema path is required"));
19    let output_path = PathBuf::from(arguments.next().expect("output path is required"));
20    assert!(
21        arguments.next().is_none(),
22        "only schema and output paths are accepted"
23    );
24
25    let source = fs::read_to_string(&schema_path).expect("acceptance schema is readable");
26    let documents = SchemaDocumentSet::parse([(
27        DocumentId::new("python-acceptance.yaml").expect("document ID is valid"),
28        source,
29    )])
30    .expect("acceptance schema parses");
31    let declared = normalize_documents(&documents).expect("acceptance schema normalizes");
32    let profile_name = env::var("TYPE_BRIDGE_ACCEPTANCE_SEMANTIC_PROFILE")
33        .unwrap_or_else(|_| "typedb-3.12.1/v1".to_owned());
34    let profile = SemanticProfileId::new(&profile_name).expect("semantic profile is valid");
35    let resolved = resolve(&declared, &profile).expect("acceptance schema resolves");
36    let emitter = PythonEmitter::new();
37    let handlers = emitter.generator_handlers();
38    let resources = emitter.code_resources().expect("emitter resources hash");
39    let projection = project(
40        &resolved,
41        BindingTarget::Python,
42        &ProjectionConfig::python(),
43        &handlers,
44        &resources,
45    )
46    .expect("acceptance schema projects");
47    let available: CapabilitySet = BUILTIN_SCHEMA_CAPABILITY_IDS
48        .iter()
49        .map(|id| CapabilityId::new(*id).expect("built-in capability ID"))
50        .collect();
51    let context = ManagedDeltaContext::new(
52        ManagedScopeId::new("python-generated-acceptance").expect("acceptance scope"),
53        profile,
54        available,
55    );
56    let authority = build_schema_authority(&declared, declared.required_capabilities(), &context)
57        .expect("acceptance authority builds");
58    let package = emitter
59        .emit(&projection, &authority)
60        .expect("Python package emits");
61
62    fs::create_dir_all(&output_path).expect("output directory is created");
63    for (relative, bytes) in package.files() {
64        fs::write(output_path.join(relative), bytes).expect("generated file is written");
65    }
66}

Trait Implementations§

Source§

impl Clone for PythonEmitter

Source§

fn clone(&self) -> PythonEmitter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for PythonEmitter

Source§

impl Debug for PythonEmitter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PythonEmitter

Source§

fn default() -> PythonEmitter

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.