Skip to content

Commit 1ae1ecc

Browse files
Added --ignore-conf argument to ignore configuration file arguments for sphinx-versioned-docs in conf.py.
1 parent 316839c commit 1ae1ecc

File tree

3 files changed

+51
-24
lines changed

3 files changed

+51
-24
lines changed

docs/settings.rst

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ Configuration File Arguments
2020

2121
Setting this variable will make sure that the ``Project home`` is listed on the versions selector badge/menu.
2222

23-
.. option:: sv_prebuild
24-
25-
Pre-build all versions to make sure ``sphinx-build`` has no issues and pass-on the successful builds to ``sphinx-versioned-docs``. Default is `True`.
26-
2723
.. option:: sv_select_branch
2824

2925
Select any particular branches/tags to build.
@@ -60,6 +56,18 @@ Configuration File Arguments
6056

6157
Force branch selection. Use this option to build detached head/commits. Default is `False`.
6258

59+
.. option:: sv_floating_badge
60+
61+
Turns the version selector menu into a floating badge. Default is `False`.
62+
63+
.. option:: sv_reset_intersphinx
64+
65+
Resets intersphinx mapping; acts as a patch for issue `#17 <https://github.com/devanshshukla99/sphinx-versioned-docs/issues/17>`__. Default is `False`.
66+
67+
.. option:: sv_sphinx_compability
68+
69+
Adds compatibility for older sphinx versions by monkey patching certain functions. Default is `False`.
70+
6371

6472
Command Line Arguments
6573
======================
@@ -109,6 +117,13 @@ These command line options must be specified when executing the ``sphinx-version
109117

110118
Turns the version selector menu into a floating badge. Default is `False`.
111119

120+
.. option:: --ignore-conf
121+
122+
Ignores conf.py configuration file arguments for sphinx-versioned-docs.
123+
124+
.. warning::
125+
conf.py will still be used in sphinx!
126+
112127
.. option:: --quite, --no-quite
113128

114129
Silents the output from `sphinx`. Use `--no-quite` to get complete-output from `sphinx`. Default is `True`.

sphinx_versioned/__main__.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def main(
5959
floating_badge: bool = typer.Option(
6060
False, "--floating-badge", "--badge", help="Turns the version selector menu into a floating badge."
6161
),
62+
ignore_conf: bool = typer.Option(
63+
False, "--ignore-conf", help="Ignores conf.py configuration file arguments for sphinx-versioned-docs. Warning: conf.py will still be used in sphinx!"
64+
),
6265
quite: bool = typer.Option(
6366
True, help="Silent `sphinx`. Use `--no-quite` to get build output from `sphinx`."
6467
),
@@ -102,6 +105,8 @@ def main(
102105
Main branch to which the top-level `index.html` redirects to. [Default = 'main']
103106
floating_badge : :class:`bool`
104107
Turns the version selector menu into a floating badge. [Default = `False`]
108+
ignore_conf : :class:`bool`
109+
Ignores conf.py configuration file arguments for sphinx-versioned-docs. Warning: conf.py will still be used in sphinx!
105110
quite : :class:`bool`
106111
Quite output from `sphinx`. Use `--no-quite` to get output from `sphinx`. [Default = `True`]
107112
verbose : :class:`bool`
@@ -121,24 +126,28 @@ def main(
121126
log.add(sys.stderr, format=logger_format, level=loglevel.upper())
122127

123128
select_branch, exclude_branch = parse_branch_selection(branches)
129+
config = {
130+
"reset_intersphinx_mapping": reset_intersphinx_mapping,
131+
"sphinx_compatibility": sphinx_compatibility,
132+
"force_branches": force_branches,
133+
"exclude_branch": exclude_branch,
134+
"floating_badge": floating_badge,
135+
"select_branch": select_branch,
136+
"prebuild": prebuild,
137+
"main_branch": main_branch,
138+
"verbose": verbose,
139+
"quite": quite,
140+
}
141+
142+
filtered_config = {x: y for x, y in config.items() if y}
124143

125144
DocsBuilder = VersionedDocs(
126145
chdir=chdir,
127146
local_conf=local_conf,
128147
output_dir=output_dir,
129148
git_root=git_root,
130-
config={
131-
"reset_intersphinx_mapping": reset_intersphinx_mapping,
132-
"sphinx_compatibility": sphinx_compatibility,
133-
"force_branches": force_branches,
134-
"exclude_branch": exclude_branch,
135-
"floating_badge": floating_badge,
136-
"select_branch": select_branch,
137-
"prebuild": prebuild,
138-
"main_branch": main_branch,
139-
"verbose": verbose,
140-
"quite": quite,
141-
},
149+
ignore_conf=ignore_conf,
150+
config=filtered_config
142151
)
143152

144153
return DocsBuilder.run()

sphinx_versioned/build.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class VersionedDocs:
3636
CLI configuration arguments.
3737
"""
3838

39-
def __init__(self, chdir: str, local_conf: str, output_dir: str, git_root: str, config: dict) -> None:
39+
def __init__(self, chdir: str, local_conf: str, output_dir: str, git_root: str, ignore_conf:bool, config: dict) -> None:
4040
# chdir if required
4141
if chdir:
4242
self.chdir = pathlib.Path(chdir)
@@ -50,8 +50,12 @@ def __init__(self, chdir: str, local_conf: str, output_dir: str, git_root: str,
5050
self.output_dir = pathlib.Path(output_dir)
5151
self.git_root = pathlib.Path(git_root) if git_root else None
5252

53+
# Ignore conf.py for configuration-file-arguments or not
54+
self.ignore_conf = ignore_conf
55+
5356
# CLI config variables
5457
self._raw_cli_config = config
58+
log.debug(f"command line arugments: {self._raw_cli_config}")
5559

5660
# Read sphinx-conf.py variables
5761
self.read_conf()
@@ -87,6 +91,10 @@ def read_conf(self) -> bool:
8791

8892
log.success(f"located conf.py")
8993

94+
if self.ignore_conf:
95+
self.config = self._raw_cli_config
96+
return
97+
9098
# Parse sphinx config file i.e. conf.py
9199
self._sphinx_conf = Config.read(self.local_conf.parent.absolute())
92100
sv_conf_values = {
@@ -95,12 +103,7 @@ def read_conf(self) -> bool:
95103
log.debug(f"Configuration file arugments: {sv_conf_values}")
96104

97105
# Make a master config variable
98-
self.config = self._raw_cli_config.copy()
99-
for x, y in self.config.items():
100-
if y or x not in sv_conf_values:
101-
continue
102-
self.config[x] = sv_conf_values.get(x)
103-
106+
self.config = sv_conf_values | self._raw_cli_config
104107
log.debug(f"master config: {self.config}")
105108
return
106109

@@ -113,7 +116,7 @@ def configure_conf(self) -> None:
113116

114117
if self.config.get("reset_intersphinx_mapping"):
115118
EventHandlers.RESET_INTERSPHINX_MAPPING = True
116-
log.warning("Forcing --no-prebuild")
119+
log.warning("forcing --no-prebuild")
117120
self.config["prebuild"] = False
118121

119122
if self.config.get("sphinx_compatibility"):

0 commit comments

Comments
 (0)