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 3
3
import os
4
4
import subprocess
5
5
import sys
6
+ from linkml .generators .shaclgen import ShaclGenerator
7
+ import linkml ._version as linkml_version
6
8
7
9
8
10
def 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 ()
17
13
18
14
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 "
20
17
f"# Source file: { input_file } \n "
21
- f"# Command: { ' ' . join ( command ) } \n \n "
18
+ " \n "
22
19
)
23
20
24
21
# Run the command and redirect output to the output file
25
22
with open (output_file , "w" ) as outfile :
26
23
outfile .write (comment )
27
- outfile .write (str ( result . stdout . decode ( "utf-8" )) )
24
+ outfile .write (shacl_shapes )
28
25
29
26
30
27
def 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"
51
51
max-line-length = 120
52
52
53
53
[build-system ]
54
- requires = [" poetry-core" ]
54
+ requires = [" poetry-core" , " linkml " ]
55
55
build-backend = " poetry.core.masonry.api"
56
56
57
57
[tool .poetry .build ]
You can’t perform that action at this time.
0 commit comments