pub struct PythonEmitter;Expand description
Version-one Python package emitter.
Implementations§
Source§impl PythonEmitter
impl PythonEmitter
Sourcepub const fn new() -> Self
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}Sourcepub fn generator_handlers(&self) -> Vec<ProjectionHandler>
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}Sourcepub fn code_resources(&self) -> Result<Vec<CodeResourceDigest>, Diagnostic>
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}Sourcepub fn emit(
&self,
projection: &RuntimeProjection,
authority: &VerifiedSchemaAuthority,
) -> Result<GeneratedPackage, Diagnostic>
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
impl Clone for PythonEmitter
Source§fn clone(&self) -> PythonEmitter
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for PythonEmitter
Source§impl Debug for PythonEmitter
impl Debug for PythonEmitter
Source§impl Default for PythonEmitter
impl Default for PythonEmitter
Source§fn default() -> PythonEmitter
fn default() -> PythonEmitter
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for PythonEmitter
impl RefUnwindSafe for PythonEmitter
impl Send for PythonEmitter
impl Sync for PythonEmitter
impl Unpin for PythonEmitter
impl UnsafeUnpin for PythonEmitter
impl UnwindSafe for PythonEmitter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more