1515try :
1616 import requests
1717except :
18- os .system (' pip install requests' )
18+ os .system (" pip install requests" )
1919 import requests
2020
2121
@@ -24,50 +24,50 @@ def parse_version_tag():
2424
2525
2626def get_libs_dir () -> str :
27- return abspath (join (dirname (__file__ ), '..' , ' libs' ))
27+ return abspath (join (dirname (__file__ ), ".." , " libs" ))
2828
2929
3030def get_os_arch_path (windows_path ):
31- copy_from = ''
31+ copy_from = ""
3232 libs_dir = get_libs_dir ()
3333 os_name = platform .system ().lower ()
3434 processor_name = platform .machine ().lower ()
35- if os_name == ' windows' :
35+ if os_name == " windows" :
3636 copy_from = join (libs_dir , windows_path )
37- elif os_name == ' linux' :
38- if processor_name == ' x86_64' :
39- copy_from = join (libs_dir , ' linux' )
40- elif processor_name == ' armv7l' :
41- copy_from = join (libs_dir , ' linux-armv7' )
42- elif processor_name == ' aarch64' :
43- copy_from = join (libs_dir , ' linux-aarch64' )
44- elif os_name == ' darwin' :
45- copy_from = join (libs_dir , ' macos' )
37+ elif os_name == " linux" :
38+ if processor_name == " x86_64" :
39+ copy_from = join (libs_dir , " linux" )
40+ elif processor_name == " armv7l" :
41+ copy_from = join (libs_dir , " linux-armv7" )
42+ elif processor_name == " aarch64" :
43+ copy_from = join (libs_dir , " linux-aarch64" )
44+ elif os_name == " darwin" :
45+ copy_from = join (libs_dir , " macos" )
4646 return copy_from
4747
4848
4949def set_env_var (name , value ):
50- env_file = os .getenv (' GITHUB_ENV' )
50+ env_file = os .getenv (" GITHUB_ENV" )
5151 if env_file is None :
5252 return
5353 with open (env_file , "a" ) as file :
5454 file .write (f"{ name } ={ value } " )
5555
5656
57- def copy_okapi_libs (copy_to : str , windows_path = ' windows' ):
57+ def copy_okapi_libs (copy_to : str , windows_path = " windows" ):
5858 copy_from = get_os_arch_path (windows_path )
5959 logging .info (f"Copying okapi libs from: { copy_from } \n to: { copy_to } " )
6060
61- for copy_file in glob .glob (join (copy_from , ' *.*' )):
61+ for copy_file in glob .glob (join (copy_from , " *.*" )):
6262 shutil .copy2 (copy_file , copy_to )
6363 try :
64- shutil .copy2 (join (get_libs_dir (), ' C_header' , ' okapi.h' ), copy_to )
64+ shutil .copy2 (join (get_libs_dir (), " C_header" , " okapi.h" ), copy_to )
6565 except FileNotFoundError :
6666 pass
6767
6868
6969def deep_copy_okapi_libs (copy_to : str ):
70- copy_from = abspath (join (dirname (__file__ ), '..' , ' libs' ))
70+ copy_from = abspath (join (dirname (__file__ ), ".." , " libs" ))
7171 logging .info (f"Copying okapi libs from: { copy_from } \n to: { copy_to } " )
7272 shutil .rmtree (copy_to , ignore_errors = True )
7373 shutil .copytree (copy_from , copy_to )
@@ -91,19 +91,21 @@ def clean_dir(language_dir: str) -> None:
9191
9292
9393def update_line (file_name : str , replace_lines : Dict [str , str ]) -> None :
94- with open (file_name , 'r' ) as fid :
94+ with open (file_name , "r" ) as fid :
9595 file_lines = fid .readlines ()
9696
97- file_lines = list (map (lambda x : replace_line_if_needed (x , replace_lines ), file_lines ))
97+ file_lines = list (
98+ map (lambda x : replace_line_if_needed (x , replace_lines ), file_lines )
99+ )
98100
99- with open (file_name , 'w' ) as fid2 :
101+ with open (file_name , "w" ) as fid2 :
100102 fid2 .writelines (file_lines )
101103
102104
103105def replace_line_if_needed (line : str , replace_lines : Dict [str , str ]) -> str :
104106 for find , replace in replace_lines .items ():
105107 if line .strip ().startswith (find .strip ()):
106- line = replace + ' \n '
108+ line = replace + " \n "
107109 return line
108110
109111
@@ -113,124 +115,174 @@ def get_language_dir(language_name: str) -> str:
113115 :param language_name: The language directory
114116 :return: Absolute path to the given language SDK
115117 """
116- return abspath (join (dirname (abspath (__file__ )), '..' , language_name ))
118+ return abspath (join (dirname (abspath (__file__ )), ".." , language_name ))
117119
118120
119121def get_sdk_dir () -> str :
120122 """Get the full path of the root of the sdk repository"""
121- return abspath (join (dirname (abspath (__file__ )), '..' ))
123+ return abspath (join (dirname (abspath (__file__ )), ".." ))
122124
123125
124126def build_python (args ) -> None :
125127 # Update version in setup.cfg
126- python_dir = get_language_dir ('python' )
127- update_line (join (python_dir , 'setup.cfg' ), {'version = ' : f'version = { get_package_versions (args )} ' })
128+ python_dir = get_language_dir ("python" )
129+ update_line (
130+ join (python_dir , "setup.cfg" ),
131+ {"version = " : f"version = { get_package_versions (args )} " },
132+ )
128133 # TODO - Support ARM
129- copy_okapi_file (abspath (join (dirname (__file__ ), '..' , 'libs' , 'windows' , 'okapi.dll' )),
130- abspath (join (python_dir , 'libs' , 'windows' )))
131- copy_okapi_file (abspath (join (dirname (__file__ ), '..' , 'libs' , 'macos' , 'libokapi.dylib' )),
132- abspath (join (python_dir , 'libs' , 'macos' )))
133- copy_okapi_file (abspath (join (dirname (__file__ ), '..' , 'libs' , 'linux' , 'libokapi.so' )),
134- abspath (join (python_dir , 'libs' , 'linux' )))
134+ copy_okapi_file (
135+ abspath (join (dirname (__file__ ), ".." , "libs" , "windows" , "okapi.dll" )),
136+ abspath (join (python_dir , "libs" , "windows" )),
137+ )
138+ copy_okapi_file (
139+ abspath (join (dirname (__file__ ), ".." , "libs" , "macos" , "libokapi.dylib" )),
140+ abspath (join (python_dir , "libs" , "macos" )),
141+ )
142+ copy_okapi_file (
143+ abspath (join (dirname (__file__ ), ".." , "libs" , "linux" , "libokapi.so" )),
144+ abspath (join (python_dir , "libs" , "linux" )),
145+ )
135146
136147
137148def build_java (args ) -> None :
138149 # Update version in setup.cfg
139- java_dir = get_language_dir ('java' )
140- update_line (join (java_dir , 'build.gradle' ), {'def jarVersion' : f'def jarVersion = "{ get_package_versions (args )} "' })
141- copy_okapi_libs (abspath (join (java_dir , '..' , 'libs' )))
150+ java_dir = get_language_dir ("java" )
151+ update_line (
152+ join (java_dir , "build.gradle" ),
153+ {"def jarVersion" : f'def jarVersion = "{ get_package_versions (args )} "' },
154+ )
155+ copy_okapi_libs (abspath (join (java_dir , ".." , "libs" )))
142156
143157
144158def build_ruby (args ) -> None :
145159 # Update version in setup.cfg
146- ruby_dir = get_language_dir ('ruby' )
147- update_line (join (ruby_dir , 'lib' , 'version.rb' ), {' VERSION =' : f" VERSION = '{ get_package_versions (args )} '" })
160+ ruby_dir = get_language_dir ("ruby" )
161+ update_line (
162+ join (ruby_dir , "lib" , "version.rb" ),
163+ {" VERSION =" : f" VERSION = '{ get_package_versions (args )} '" },
164+ )
148165 # TODO - Support Ruby on ARM
149- copy_okapi_file (abspath (join (dirname (__file__ ), '..' , 'libs' , 'windows' , 'okapi.dll' )),
150- abspath (join (ruby_dir , 'libs' , 'windows' )))
151- copy_okapi_file (abspath (join (dirname (__file__ ), '..' , 'libs' , 'macos' , 'libokapi.dylib' )),
152- abspath (join (ruby_dir , 'libs' , 'macos' )))
153- copy_okapi_file (abspath (join (dirname (__file__ ), '..' , 'libs' , 'linux' , 'libokapi.so' )),
154- abspath (join (ruby_dir , 'libs' , 'linux' )))
166+ copy_okapi_file (
167+ abspath (join (dirname (__file__ ), ".." , "libs" , "windows" , "okapi.dll" )),
168+ abspath (join (ruby_dir , "libs" , "windows" )),
169+ )
170+ copy_okapi_file (
171+ abspath (join (dirname (__file__ ), ".." , "libs" , "macos" , "libokapi.dylib" )),
172+ abspath (join (ruby_dir , "libs" , "macos" )),
173+ )
174+ copy_okapi_file (
175+ abspath (join (dirname (__file__ ), ".." , "libs" , "linux" , "libokapi.so" )),
176+ abspath (join (ruby_dir , "libs" , "linux" )),
177+ )
155178
156179
157180def build_golang (args ) -> None :
158181 # Copy in Okapi libraries to the $GOLANG_LD_PATH directory
159- golang_dir = abspath (join (get_language_dir ('go' ), ' okapi' ))
182+ golang_dir = abspath (join (get_language_dir ("go" ), " okapi" ))
160183 set_env_var ("GOLANG_LD_PATH" , golang_dir )
161184
162185 # Copy in the binaries
163- copy_okapi_libs (golang_dir , ' windows-gnu' )
186+ copy_okapi_libs (golang_dir , " windows-gnu" )
164187
165188
166189def get_package_versions (args ) -> str :
167- return (args .package_version or get_github_version ()).lstrip ('v' )
190+ return (args .package_version or get_github_version ()).lstrip ("v" )
168191
169192
170193def get_github_version (github_token : str = None ) -> str :
171194 if not github_token :
172- github_token = os .getenv ('API_GITHUB_TOKEN' )
173- github_release_request = requests .get ('https://api.github.com/repos/trinsic-id/okapi/releases/latest' ,
174- headers = {'Authorization' : github_token })
195+ github_token = os .getenv ("API_GITHUB_TOKEN" )
196+ github_release_request = requests .get (
197+ "https://api.github.com/repos/trinsic-id/okapi/releases/latest" ,
198+ headers = {"Authorization" : github_token },
199+ )
175200 github_json = github_release_request .json ()
176- version = github_json [' tag_name' ]
201+ version = github_json [" tag_name" ]
177202 return version
178203
179204
180205def build_java_docs (args ):
181206 # https://github.com/fchastanet/groovydoc-to-markdown
182207 # npm install in the root of sdk
183208 subprocess .Popen (
184- ['node' , './node_modules/groovydoc-to-markdown/src/doc2md.js' , './java' , 'java' , './docs/reference/java' ],
185- cwd = get_sdk_dir ()).wait ()
209+ [
210+ "node" ,
211+ "./node_modules/groovydoc-to-markdown/src/doc2md.js" ,
212+ "./java" ,
213+ "java" ,
214+ "./docs/reference/java" ,
215+ ],
216+ cwd = get_sdk_dir (),
217+ ).wait ()
186218
187219
188220def build_dotnet_docs (args ) -> None :
189221 # https://github.com/Doraku/DefaultDocumentation
190222 # dotnet tool install DefaultDocumentation.Console -g
191- assembly_file = ' ./dotnet/Library/Okapi/bin/Debug/net6.0/okapi.dll'
192- output_doc_folder = ' ./docs/reference/dotnet'
223+ assembly_file = " ./dotnet/Library/Okapi/bin/Debug/net6.0/okapi.dll"
224+ output_doc_folder = " ./docs/reference/dotnet"
193225 clean_dir (abspath (join (get_sdk_dir (), output_doc_folder )))
194226 subprocess .Popen (
195- ["defaultdocumentation" , "--AssemblyFilePath" , assembly_file , "--OutputDirectoryPath" , output_doc_folder ,
196- "--FileNameMode" , "Name" , "--GeneratedPages" , "Namespaces" , ], cwd = get_sdk_dir ()).wait ()
227+ [
228+ "defaultdocumentation" ,
229+ "--AssemblyFilePath" ,
230+ assembly_file ,
231+ "--OutputDirectoryPath" ,
232+ output_doc_folder ,
233+ "--FileNameMode" ,
234+ "Name" ,
235+ "--GeneratedPages" ,
236+ "Namespaces" ,
237+ ],
238+ cwd = get_sdk_dir (),
239+ ).wait ()
197240
198241
199242def build_go_docs (args ):
200243 # https://github.com/posener/goreadme
201244 # go get github.com/posener/goreadme/cmd/goreadme
202- goreadme_args = ['-recursive' , '-functions' , '-methods' , '-types' ,
203- '-variabless' ] # Yes, that's a duplicated s, it's on purpose.
204- doc_path = abspath (join (get_language_dir ('docs' ), 'reference' , 'go' ))
245+ goreadme_args = [
246+ "-recursive" ,
247+ "-functions" ,
248+ "-methods" ,
249+ "-types" ,
250+ "-variabless" ,
251+ ] # Yes, that's a duplicated s, it's on purpose.
252+ doc_path = abspath (join (get_language_dir ("docs" ), "reference" , "go" ))
205253
206254 def write_doc_file (input_path : str , output_file : str ):
207255 logging .info (f"goreadme(input={ input_path } , output={ output_file } )" )
208256 print (f"goreadme(input={ input_path } , output={ output_file } )" )
209- with open (join (doc_path , f'{ output_file } .md' ), 'w' ) as output :
210- subprocess .Popen (['goreadme' , * goreadme_args ], cwd = input_path , stdout = output ).wait ()
257+ with open (join (doc_path , f"{ output_file } .md" ), "w" ) as output :
258+ subprocess .Popen (
259+ ["goreadme" , * goreadme_args ], cwd = input_path , stdout = output
260+ ).wait ()
211261 # Handle the subdirectories
212- for sub_folder in glob .glob (join (input_path , '**' )):
262+ for sub_folder in glob .glob (join (input_path , "**" )):
213263 if isdir (sub_folder ):
214264 _ , folder_name = split (sub_folder )
215265 write_doc_file (sub_folder , folder_name )
216266
217- write_doc_file (get_language_dir ('go' ), ' index' )
267+ write_doc_file (get_language_dir ("go" ), " index" )
218268
219269
220270def parse_arguments ():
221- parser = argparse .ArgumentParser (description = 'Process SDK building' )
222- parser .add_argument ('--package-version' , help = 'Manual override package version' )
223- parser .add_argument ('--language' , help = 'Comma-separated languages to build' , default = 'all' )
271+ parser = argparse .ArgumentParser (description = "Process SDK building" )
272+ parser .add_argument ("--package-version" , help = "Manual override package version" )
273+ parser .add_argument (
274+ "--language" , help = "Comma-separated languages to build" , default = "all"
275+ )
224276 return parser .parse_args ()
225277
226278
227279def extract_libs_zip ():
228280 # Look for a libs.zip file to extract
229- libs_zip = abspath (join (dirname (__file__ ), '..' , ' libs.zip' ))
281+ libs_zip = abspath (join (dirname (__file__ ), ".." , " libs.zip" ))
230282 if exists (libs_zip ):
231- print (f' Found released zip binary, extracting...' )
283+ print (f" Found released zip binary, extracting..." )
232284 with ZipFile (libs_zip ) as zip_ref :
233- zip_ref .extractall (abspath (join (dirname (__file__ ), '..' )))
285+ zip_ref .extractall (abspath (join (dirname (__file__ ), ".." )))
234286
235287
236288def continue_on_error (fcn , args ) -> None :
@@ -243,21 +295,21 @@ def continue_on_error(fcn, args) -> None:
243295def main ():
244296 # Get command line arguments
245297 args = parse_arguments ()
246- langs_to_build = [lang .lower () for lang in (args .language + ',' ).split (',' )]
247- build_all = ' all' in langs_to_build
298+ langs_to_build = [lang .lower () for lang in (args .language + "," ).split ("," )]
299+ build_all = " all" in langs_to_build
248300
249301 extract_libs_zip ()
250302
251303 # Update version information
252- if build_all or ' python' in langs_to_build :
304+ if build_all or " python" in langs_to_build :
253305 continue_on_error (build_python , args )
254- if build_all or ' java' in langs_to_build :
306+ if build_all or " java" in langs_to_build :
255307 continue_on_error (build_java , args )
256- if build_all or ' ruby' in langs_to_build :
308+ if build_all or " ruby" in langs_to_build :
257309 continue_on_error (build_ruby , args )
258- if build_all or ' golang' in langs_to_build :
310+ if build_all or " golang" in langs_to_build :
259311 continue_on_error (build_golang , args )
260- if build_all or ' docs' in langs_to_build :
312+ if build_all or " docs" in langs_to_build :
261313 continue_on_error (build_java_docs , args )
262314 continue_on_error (build_go_docs , args )
263315 continue_on_error (build_dotnet_docs , args )
0 commit comments