linkml 1.9.4rc2__py3-none-any.whl → 1.9.5rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. linkml/cli/main.py +4 -0
  2. linkml/generators/__init__.py +2 -0
  3. linkml/generators/common/build.py +5 -20
  4. linkml/generators/common/template.py +289 -3
  5. linkml/generators/docgen.py +55 -10
  6. linkml/generators/erdiagramgen.py +9 -5
  7. linkml/generators/graphqlgen.py +32 -6
  8. linkml/generators/jsonldcontextgen.py +78 -12
  9. linkml/generators/jsonschemagen.py +29 -12
  10. linkml/generators/mermaidclassdiagramgen.py +21 -3
  11. linkml/generators/owlgen.py +4 -1
  12. linkml/generators/panderagen/dataframe_class.py +13 -0
  13. linkml/generators/panderagen/dataframe_field.py +50 -0
  14. linkml/generators/panderagen/linkml_pandera_validator.py +186 -0
  15. linkml/generators/panderagen/panderagen.py +22 -5
  16. linkml/generators/panderagen/panderagen_class_based/class.jinja2 +70 -13
  17. linkml/generators/panderagen/panderagen_class_based/custom_checks.jinja2 +27 -0
  18. linkml/generators/panderagen/panderagen_class_based/enums.jinja2 +3 -3
  19. linkml/generators/panderagen/panderagen_class_based/pandera.jinja2 +12 -2
  20. linkml/generators/panderagen/panderagen_class_based/slots.jinja2 +19 -17
  21. linkml/generators/panderagen/slot_generator_mixin.py +143 -16
  22. linkml/generators/panderagen/transforms/__init__.py +19 -0
  23. linkml/generators/panderagen/transforms/collection_dict_model_transform.py +62 -0
  24. linkml/generators/panderagen/transforms/list_dict_model_transform.py +66 -0
  25. linkml/generators/panderagen/transforms/model_transform.py +8 -0
  26. linkml/generators/panderagen/transforms/nested_struct_model_transform.py +27 -0
  27. linkml/generators/panderagen/transforms/simple_dict_model_transform.py +86 -0
  28. linkml/generators/plantumlgen.py +17 -11
  29. linkml/generators/pydanticgen/pydanticgen.py +53 -2
  30. linkml/generators/pydanticgen/template.py +45 -233
  31. linkml/generators/pydanticgen/templates/attribute.py.jinja +1 -0
  32. linkml/generators/pydanticgen/templates/base_model.py.jinja +16 -2
  33. linkml/generators/pydanticgen/templates/imports.py.jinja +1 -1
  34. linkml/generators/rdfgen.py +11 -2
  35. linkml/generators/rustgen/__init__.py +3 -0
  36. linkml/generators/rustgen/build.py +94 -0
  37. linkml/generators/rustgen/cli.py +65 -0
  38. linkml/generators/rustgen/rustgen.py +1038 -0
  39. linkml/generators/rustgen/template.py +865 -0
  40. linkml/generators/rustgen/templates/Cargo.toml.jinja +42 -0
  41. linkml/generators/rustgen/templates/anything.rs.jinja +142 -0
  42. linkml/generators/rustgen/templates/as_key_value.rs.jinja +56 -0
  43. linkml/generators/rustgen/templates/class_module.rs.jinja +8 -0
  44. linkml/generators/rustgen/templates/enum.rs.jinja +54 -0
  45. linkml/generators/rustgen/templates/file.rs.jinja +62 -0
  46. linkml/generators/rustgen/templates/import.rs.jinja +4 -0
  47. linkml/generators/rustgen/templates/imports.rs.jinja +8 -0
  48. linkml/generators/rustgen/templates/poly.rs.jinja +9 -0
  49. linkml/generators/rustgen/templates/poly_containers.rs.jinja +439 -0
  50. linkml/generators/rustgen/templates/poly_trait.rs.jinja +15 -0
  51. linkml/generators/rustgen/templates/poly_trait_impl.rs.jinja +5 -0
  52. linkml/generators/rustgen/templates/poly_trait_impl_orsubtype.rs.jinja +5 -0
  53. linkml/generators/rustgen/templates/poly_trait_property.rs.jinja +8 -0
  54. linkml/generators/rustgen/templates/poly_trait_property_impl.rs.jinja +132 -0
  55. linkml/generators/rustgen/templates/poly_trait_property_match.rs.jinja +10 -0
  56. linkml/generators/rustgen/templates/property.rs.jinja +19 -0
  57. linkml/generators/rustgen/templates/pyproject.toml.jinja +10 -0
  58. linkml/generators/rustgen/templates/serde_utils.rs.jinja +310 -0
  59. linkml/generators/rustgen/templates/slot_range_as_union.rs.jinja +61 -0
  60. linkml/generators/rustgen/templates/struct.rs.jinja +75 -0
  61. linkml/generators/rustgen/templates/struct_or_subtype_enum.rs.jinja +108 -0
  62. linkml/generators/rustgen/templates/typealias.rs.jinja +13 -0
  63. linkml/generators/sqltablegen.py +18 -16
  64. linkml/generators/yarrrmlgen.py +157 -0
  65. linkml/linter/config/datamodel/config.py +160 -293
  66. linkml/linter/config/datamodel/config.yaml +34 -26
  67. linkml/linter/config/default.yaml +4 -0
  68. linkml/linter/config/recommended.yaml +4 -0
  69. linkml/linter/linter.py +1 -2
  70. linkml/linter/rules.py +37 -0
  71. linkml/utils/schemaloader.py +55 -3
  72. {linkml-1.9.4rc2.dist-info → linkml-1.9.5rc1.dist-info}/METADATA +1 -1
  73. {linkml-1.9.4rc2.dist-info → linkml-1.9.5rc1.dist-info}/RECORD +76 -38
  74. {linkml-1.9.4rc2.dist-info → linkml-1.9.5rc1.dist-info}/entry_points.txt +1 -0
  75. linkml/generators/panderagen/panderagen_class_based/mixins.jinja2 +0 -26
  76. {linkml-1.9.4rc2.dist-info → linkml-1.9.5rc1.dist-info}/WHEEL +0 -0
  77. {linkml-1.9.4rc2.dist-info → linkml-1.9.5rc1.dist-info}/licenses/LICENSE +0 -0
@@ -67,12 +67,21 @@ class RDFGenerator(Generator):
67
67
  base=str(self.namespaces._base),
68
68
  prefix=True,
69
69
  )
70
- out = self._data(graph)
71
70
  if output:
71
+ # Binary-safe when -o/--output is used:
72
+ # delegate to RDFLib (Graph.serialize(destination=..., format=...)).
73
+ # Serializers that produce bytes write directly to the file; stdout stays empty.
74
+ fmt = "turtle" if self.format == "ttl" else self.format
75
+ try:
76
+ out = graph.serialize(format=fmt)
77
+ except UnicodeDecodeError:
78
+ graph.serialize(destination=output, format=fmt)
79
+ return ""
72
80
  with open(output, "w", encoding="UTF-8") as outf:
73
81
  outf.write(out)
82
+ return out
74
83
 
75
- return out
84
+ return self._data(graph)
76
85
 
77
86
 
78
87
  @shared_arguments(RDFGenerator)
@@ -0,0 +1,3 @@
1
+ from linkml.generators.rustgen.rustgen import RUST_MODES, RustGenerator
2
+
3
+ __all__ = ["RUST_MODES", "RustGenerator"]
@@ -0,0 +1,94 @@
1
+ from linkml.generators.common.build import (
2
+ BuildResult,
3
+ SchemaResult,
4
+ )
5
+ from linkml.generators.common.build import (
6
+ ClassResult as ClassResult_,
7
+ )
8
+ from linkml.generators.common.build import EnumResult as EnumResult_
9
+ from linkml.generators.common.build import (
10
+ SlotResult as SlotResult_,
11
+ )
12
+ from linkml.generators.common.build import TypeResult as TypeResult_
13
+ from linkml.generators.rustgen.template import (
14
+ Imports,
15
+ RustCargo,
16
+ RustEnum,
17
+ RustFile,
18
+ RustProperty,
19
+ RustPyProject,
20
+ RustStruct,
21
+ RustTemplateModel,
22
+ RustTypeAlias,
23
+ )
24
+
25
+
26
+ class RustBuildResult(BuildResult):
27
+ """
28
+ BuildResult parent class for rustgen
29
+ """
30
+
31
+ imports: Imports = Imports()
32
+
33
+ def merge(self, other: "RustBuildResult") -> "RustBuildResult":
34
+ self.imports += other.imports
35
+ return self
36
+
37
+
38
+ class TypeResult(RustBuildResult, TypeResult_):
39
+ """
40
+ A linkml type as a type alias
41
+ """
42
+
43
+ type_: RustTypeAlias
44
+
45
+
46
+ class ClassResult(RustBuildResult, ClassResult_):
47
+ """
48
+ A single built rust struct
49
+ """
50
+
51
+ cls: RustStruct
52
+
53
+
54
+ class SlotResult(RustBuildResult, SlotResult_):
55
+ """
56
+ A type alias
57
+ """
58
+
59
+ slot: RustTypeAlias
60
+
61
+
62
+ class AttributeResult(RustBuildResult, SlotResult_):
63
+ """
64
+ A field within a rust struct
65
+ """
66
+
67
+ attribute: RustProperty
68
+
69
+
70
+ class EnumResult(RustBuildResult, EnumResult_):
71
+ """
72
+ A rust enum!
73
+ """
74
+
75
+ enum: RustEnum
76
+
77
+
78
+ class CrateResult(RustBuildResult, SchemaResult):
79
+ """
80
+ A schema built into a rust crate
81
+ """
82
+
83
+ cargo: RustCargo
84
+ file: RustFile
85
+ extra_files: dict[str, RustTemplateModel]
86
+ pyproject: RustPyProject
87
+
88
+
89
+ class FileResult(RustBuildResult, SchemaResult):
90
+ """
91
+ A schema built into a single rust file
92
+ """
93
+
94
+ file: RustFile
@@ -0,0 +1,65 @@
1
+ from pathlib import Path
2
+ from typing import Optional, get_args
3
+
4
+ import click
5
+
6
+ from linkml._version import __version__
7
+ from linkml.generators.rustgen import RUST_MODES, RustGenerator
8
+ from linkml.utils.generator import shared_arguments
9
+
10
+
11
+ @shared_arguments(RustGenerator)
12
+ @click.option(
13
+ "-m",
14
+ "--mode",
15
+ type=click.Choice([a for a in get_args(RUST_MODES)]),
16
+ default="crate",
17
+ help="Generation mode: 'crate' (Cargo package) or 'file' (single .rs)",
18
+ )
19
+ @click.option(
20
+ "-f",
21
+ "--force",
22
+ is_flag=True,
23
+ help="Overwrite output if it already exists",
24
+ )
25
+ @click.option(
26
+ "-p",
27
+ "--pyo3",
28
+ is_flag=True,
29
+ help=(
30
+ "Add 'pyo3' to Cargo.toml default features and emit Python module glue (cdylib + #[pymodule]). "
31
+ 'Source always includes #[cfg(feature="pyo3")] gates; this flag only enables the crate feature by default.'
32
+ ),
33
+ )
34
+ @click.option(
35
+ "-s",
36
+ "--serde",
37
+ is_flag=True,
38
+ help=(
39
+ "Add 'serde' to Cargo.toml default features. Source always includes #[cfg(feature=\"serde\")] derives/attrs; "
40
+ "this flag only enables the crate feature by default."
41
+ ),
42
+ )
43
+ @click.option("-n", "--crate-name", type=str, default=None, help="Name of the generated crate/module")
44
+ @click.option(
45
+ "-o",
46
+ "--output",
47
+ type=click.Path(dir_okay=True),
48
+ help="Output directory (crate mode) or .rs file (file mode)",
49
+ )
50
+ @click.version_option(__version__, "-V", "--version")
51
+ @click.command(name="rust")
52
+ def cli(
53
+ yamlfile: Path,
54
+ mode: RUST_MODES = "crate",
55
+ force: bool = False,
56
+ pyo3: bool = False,
57
+ serde: bool = False,
58
+ crate_name: Optional[str] = None,
59
+ output: Optional[Path] = None,
60
+ **kwargs,
61
+ ):
62
+ gen = RustGenerator(yamlfile, mode=mode, pyo3=pyo3, serde=serde, output=output, crate_name=crate_name, **kwargs)
63
+ serialized = gen.serialize(force=force)
64
+ if output is None:
65
+ print(serialized)