22
33import base64
44import json
5- import os
6- import posixpath
5+ from pathlib import Path
76
87from docutils import nodes
98from docutils .parsers .rst import Directive , directives
@@ -249,8 +248,8 @@ def run(self):
249248
250249
251250class _FindTabsDirectiveVisitor (nodes .NodeVisitor ):
252- """ Visitor pattern than looks for a sphinx tabs
253- directive in a document """
251+ """Visitor pattern than looks for a sphinx tabs
252+ directive in a document"""
254253
255254 def __init__ (self , document ):
256255 nodes .NodeVisitor .__init__ (self , document )
@@ -279,17 +278,17 @@ def update_context(app, pagename, templatename, context, doctree):
279278 visitor = _FindTabsDirectiveVisitor (doctree )
280279 doctree .walk (visitor )
281280 if not visitor .found_tabs_directive :
282- paths = [posixpath . join ("_static" , "sphinx_tabs/" + f ) for f in FILES ]
281+ paths = [Path ("_static" ) / "sphinx_tabs" / f for f in FILES ]
283282 if "css_files" in context :
284283 context ["css_files" ] = context ["css_files" ][:]
285284 for path in paths :
286- if path .endswith ( ".css" ) and path in context ["css_files" ]:
287- context ["css_files" ].remove (path )
285+ if path .suffix == ".css" and path in context ["css_files" ]:
286+ context ["css_files" ].remove (path . as_posix () )
288287 if "script_files" in context :
289288 context ["script_files" ] = context ["script_files" ][:]
290289 for path in paths :
291- if path .endswith ( ".js" ) and path in context ["script_files" ]:
292- context ["script_files" ].remove (path )
290+ if path .suffix == ".js" and path . as_posix () in context ["script_files" ]:
291+ context ["script_files" ].remove (path . as_posix () )
293292
294293
295294# pylint: enable=unused-argument
@@ -316,15 +315,15 @@ def copy_assets(app, exception):
316315
317316 log ("Copying tabs assets" )
318317
319- installdir = os . path . join (app .builder .outdir , "_static" , "sphinx_tabs" )
318+ installdir = Path (app .builder .outdir ) / "_static" / "sphinx_tabs"
320319
321320 for path in FILES :
322321 source = resource_filename ("sphinx_tabs" , path )
323- dest = os . path . join ( installdir , path )
322+ dest = installdir / path
324323
325- destdir = os . path . dirname ( dest )
326- if not os . path . exists (destdir ):
327- os . makedirs ( destdir )
324+ destdir = dest . parent
325+ if not destdir . exists ():
326+ destdir . mkdir ( parents = True )
328327
329328 copyfile (source , dest )
330329
@@ -337,17 +336,17 @@ def setup(app):
337336 app .add_directive ("tab" , TabDirective )
338337 app .add_directive ("group-tab" , GroupTabDirective )
339338 app .add_directive ("code-tab" , CodeTabDirective )
340- for path in ["sphinx_tabs/" + f for f in FILES ]:
341- if path .endswith ( ".css" ) :
339+ for path in [Path ( "sphinx_tabs" ) / f for f in FILES ]:
340+ if path .suffix == ".css" :
342341 if "add_css_file" in dir (app ):
343- app .add_css_file (path )
342+ app .add_css_file (path . as_posix () )
344343 else :
345- app .add_stylesheet (path )
346- if path .endswith ( ".js" ) :
344+ app .add_stylesheet (path . as_posix () )
345+ if path .suffix == ".js" :
347346 if "add_script_file" in dir (app ):
348- app .add_script_file (path )
347+ app .add_script_file (path . as_posix () )
349348 else :
350- app .add_js_file (path )
349+ app .add_js_file (path . as_posix () )
351350 app .connect ("html-page-context" , update_context )
352351 app .connect ("build-finished" , copy_assets )
353352
0 commit comments