16
16
here = os .path .dirname (__file__ )
17
17
settings_file = os .path .join (here , 'inventree_settings.json' )
18
18
19
- with open (settings_file , 'r ' ) as sf :
19
+ with open (settings_file , encoding = 'utf-8 ' ) as sf :
20
20
settings = json .load (sf )
21
21
22
22
GLOBAL_SETTINGS = settings ['global' ]
@@ -27,7 +27,7 @@ def get_repo_url(raw=False):
27
27
"""Return the repository URL for the current project."""
28
28
mkdocs_yml = os .path .join (os .path .dirname (__file__ ), 'mkdocs.yml' )
29
29
30
- with open (mkdocs_yml , 'r ' ) as f :
30
+ with open (mkdocs_yml , encoding = 'utf-8 ' ) as f :
31
31
mkdocs_config = yaml .safe_load (f )
32
32
repo_name = mkdocs_config ['repo_name' ]
33
33
@@ -47,7 +47,7 @@ def check_link(url) -> bool:
47
47
48
48
# Keep a local cache file of URLs we have already checked
49
49
if os .path .exists (CACHE_FILE ):
50
- with open (CACHE_FILE , 'r ' ) as f :
50
+ with open (CACHE_FILE , encoding = 'utf-8 ' ) as f :
51
51
cache = f .read ().splitlines ()
52
52
53
53
if url in cache :
@@ -59,7 +59,7 @@ def check_link(url) -> bool:
59
59
response = requests .head (url , timeout = 5000 )
60
60
if response .status_code == 200 :
61
61
# Update the cache file
62
- with open (CACHE_FILE , 'a' ) as f :
62
+ with open (CACHE_FILE , 'a' , encoding = 'utf-8' ) as f :
63
63
f .write (f'{ url } \n ' )
64
64
65
65
return True
@@ -177,7 +177,7 @@ def invoke_commands():
177
177
178
178
assert subprocess .call (command , shell = True ) == 0
179
179
180
- with open (output , 'r ' ) as f :
180
+ with open (output , encoding = 'utf-8 ' ) as f :
181
181
content = f .read ()
182
182
183
183
return content
@@ -200,12 +200,13 @@ def listimages(subdir):
200
200
return assets
201
201
202
202
@env .macro
203
- def includefile (filename : str , title : str , format : str = '' ):
203
+ def includefile (filename : str , title : str , fmt : str = '' ):
204
204
"""Include a file in the documentation, in a 'collapse' block.
205
205
206
206
Arguments:
207
207
- filename: The name of the file to include (relative to the top-level directory)
208
208
- title:
209
+ - fmt:
209
210
"""
210
211
here = os .path .dirname (__file__ )
211
212
path = os .path .join (here , '..' , filename )
@@ -214,11 +215,11 @@ def includefile(filename: str, title: str, format: str = ''):
214
215
if not os .path .exists (path ):
215
216
raise FileNotFoundError (f'Required file { path } does not exist.' )
216
217
217
- with open (path , 'r ' ) as f :
218
+ with open (path , encoding = 'utf-8 ' ) as f :
218
219
content = f .read ()
219
220
220
221
data = f'??? abstract "{ title } "\n \n '
221
- data += f' ```{ format } \n '
222
+ data += f' ```{ fmt } \n '
222
223
data += textwrap .indent (content , ' ' )
223
224
data += '\n \n '
224
225
data += ' ```\n \n '
@@ -233,15 +234,15 @@ def templatefile(filename):
233
234
'src' , 'backend' , 'InvenTree' , 'report' , 'templates' , filename
234
235
)
235
236
236
- return includefile (fn , f'Template: { base } ' , format = 'html' )
237
+ return includefile (fn , f'Template: { base } ' , fmt = 'html' )
237
238
238
239
@env .macro
239
240
def rendersetting (setting : dict ):
240
241
"""Render a provided setting object into a table row."""
241
242
name = setting ['name' ]
242
243
description = setting ['description' ]
243
- default = setting .get ('default' , None )
244
- units = setting .get ('units' , None )
244
+ default = setting .get ('default' )
245
+ units = setting .get ('units' )
245
246
246
247
return f'| { name } | { description } | { default if default is not None else "" } | { units if units is not None else "" } |'
247
248
0 commit comments