File tree Expand file tree Collapse file tree 2 files changed +9
-12
lines changed Expand file tree Collapse file tree 2 files changed +9
-12
lines changed Original file line number Diff line number Diff line change 33import os
44import subprocess
55import sys
6+ from linkml .generators .shaclgen import ShaclGenerator
7+ import linkml ._version as linkml_version
68
79
810def convert_to_shacl (input_file : str , output_file : str ):
9- # Construct the command
10- command = [
11- "linkml" , "generate" , "shacl" ,
12- "--include-annotations" , "--non-closed" ,
13- input_file
14- ]
15-
16- result = subprocess .run (command , capture_output = True , check = True )
11+ # Generate shacl
12+ shacl_shapes = ShaclGenerator (input_file ).serialize ()
1713
1814 comment = (
19- f"# This SHACL file was generated using the LinkML\n "
15+ f"# This SHACL file was auto-generated with LinkML { linkml_version .__version__ } .\n "
16+ f"#Changes will be overwritten on install.\n "
2017 f"# Source file: { input_file } \n "
21- f"# Command: { ' ' . join ( command ) } \n \n "
18+ " \n "
2219 )
2320
2421 # Run the command and redirect output to the output file
2522 with open (output_file , "w" ) as outfile :
2623 outfile .write (comment )
27- outfile .write (str ( result . stdout . decode ( "utf-8" )) )
24+ outfile .write (shacl_shapes )
2825
2926
3027def convert_folder_recursively (path : str , force : bool = False ):
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ pytest-xdist = "^3.6.1"
5151max-line-length = 120
5252
5353[build-system ]
54- requires = [" poetry-core" ]
54+ requires = [" poetry-core" , " linkml " ]
5555build-backend = " poetry.core.masonry.api"
5656
5757[tool .poetry .build ]
You can’t perform that action at this time.
0 commit comments