docs: improve include flag directive
The include flag directive now treats missing content as info logs instead of warnings. This prevents build failures when the enterprise-specific content isn't yet available. If the enterprise content is undefined, the directive automatically loads the open-source content. This ensures the end user has access to some content. address comments (cherry picked from commit 30887d096fbf7772868a160cf8bb96f77831e272) Closes scylladb/scylladb#20226
This commit is contained in:
committed by
Botond Dénes
parent
0b1dbb3a64
commit
853d2ec76f
@@ -1,6 +1,10 @@
|
||||
import os
|
||||
from sphinx.directives.other import Include
|
||||
from sphinx.util import logging
|
||||
from docutils.parsers.rst import directives
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
class IncludeFlagDirective(Include):
|
||||
option_spec = Include.option_spec.copy()
|
||||
option_spec['base_path'] = directives.unchanged
|
||||
@@ -8,11 +12,18 @@ class IncludeFlagDirective(Include):
|
||||
def run(self):
|
||||
env = self.state.document.settings.env
|
||||
base_path = self.options.get('base_path', '_common')
|
||||
file_path = self.arguments[0]
|
||||
|
||||
if env.app.tags.has('enterprise'):
|
||||
self.arguments[0] = base_path + "_enterprise/" + self.arguments[0]
|
||||
enterprise_path = os.path.join(base_path + "_enterprise", file_path)
|
||||
_, enterprise_abs_path = env.relfn2path(enterprise_path)
|
||||
if os.path.exists(enterprise_abs_path):
|
||||
self.arguments[0] = enterprise_path
|
||||
else:
|
||||
LOGGER.info(f"Enterprise content not found: Skipping inclusion of {file_path}")
|
||||
return []
|
||||
else:
|
||||
self.arguments[0] = base_path + "/" + self.arguments[0]
|
||||
self.arguments[0] = os.path.join(base_path, file_path)
|
||||
return super().run()
|
||||
|
||||
def setup(app):
|
||||
|
||||
Reference in New Issue
Block a user