Skip to content

Commit e688078

Browse files
Allow running builds sequentially (#14)
This adds a new config option `SEQUENTIAL` for building the revisions sequentially instead of calling the build steps for all revisions in parallel. This helps for repositories with a massive amount of revisions which would suffer memory overflows without this option. * sphinx_polyversion/driver.py (srun): Implement the new build mode. * sphinx_polyversion/driver.py (run): Add `sequential` parameter that controls whether `arun` or `srun` is called. * sphinx_polyversion/main.py (get_parser): Add `--sequential` cmd option. * sphinx_polyversion/api.py (apply_overrides): Implement new `--sequential` cmd option. * tests/test_api.py (test_apply_overrides): Update test * docs/poly.py : Add `SEQUENTIAL` option. * docs/sphinx/guide/getting-started.rst : Configure new option and add missing link. * README.md: Update example `poly.py` config file to include the new `SEQUENTIAL` option. --------- Co-authored-by: real-yfprojects <[email protected]>
1 parent 6b7a763 commit e688078

File tree

7 files changed

+59
-13
lines changed

7 files changed

+59
-13
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,12 @@ MOCK_DATA = {
108108
],
109109
"current": GitRef("local", "", "", GitRefType.BRANCH, datetime.fromtimestamp(6)),
110110
}
111+
#: Whether to build using only local files and mock data
111112
MOCK = False
112113

114+
#: Whether to run the builds in sequence or in parallel
115+
SEQUENTIAL = False
116+
113117
# Load overrides read from commandline to global scope
114118
apply_overrides(globals())
115119
# Determine repository root directory
@@ -131,7 +135,7 @@ DefaultDriver(
131135
template_dir=root / src / "templates",
132136
static_dir=root / src / "static",
133137
mock=MOCK_DATA,
134-
).run(MOCK)
138+
).run(MOCK, SEQUENTIAL)
135139
```
136140

137141
Build your docs by running
@@ -143,7 +147,7 @@ $ sphinx-polyversion docs/poly.py
143147
### Commandline Options
144148

145149
```
146-
usage: sphinx-polyversion [-h] [-o [OVERRIDE [OVERRIDE ...]]] [-v] [-l] conf [out]
150+
usage: sphinx-polyversion [-h] [-o [OVERRIDE [OVERRIDE...]]] [-v] [-l] [--sequential] conf [out]
147151
148152
Build multiple versions of your sphinx docs and merge them into one site.
149153
@@ -157,6 +161,7 @@ optional arguments:
157161
Override config options. Pass them as `key=value` pairs.
158162
-v, --verbosity Increase output verbosity (decreases minimum log level). The default log level is ERROR.
159163
-l, --local, --mock Build the local version of your docs.
164+
--sequential Build the revisions sequentially.
160165
```
161166

162167
### How To Build Versions Differently

docs/poly.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@
3737
],
3838
"current": GitRef("local", "", "", GitRefType.TAG, datetime.fromtimestamp(6)),
3939
}
40+
41+
#: Whether to build using only local files and mock data
4042
MOCK = False
4143

44+
#: Whether to run the builds in sequence or in parallel
45+
SEQUENTIAL = False
46+
4247

4348
#: Data passed to templates
4449
def data(driver, rev, env):
@@ -84,4 +89,4 @@ def root_data(driver):
8489
data_factory=data,
8590
root_data_factory=root_data,
8691
mock=MOCK_DATA,
87-
).run(MOCK)
92+
).run(MOCK, SEQUENTIAL)

docs/sphinx/guide/getting-started.rst

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ you define and how you name them.
4545

4646
.. warning::
4747

48-
There are to naming specifications for config variables:
48+
To be able to override configuration options using the `sphix-polyversion`
49+
command, you have to use the following naming specifications for config
50+
variables:
4951
The output directory must always be called :code:`OUTPUT_DIR`.
50-
And you have to pass :code:`MOCK` to :code:`DefaultDriver.run`.
52+
The flag to use the local version and mock data must be called :code:`MOCK`.
53+
The flag to use sequential builds must be called :code:`SEQUENTIAL`.
54+
Finally, you have to pass :code:`MOCK` and :code:`SEQUENTIAL` to :code:`DefaultDriver.run`.
5155

5256
.. TODO link reference
5357
@@ -68,10 +72,8 @@ you define and how you name them.
6872
Defining the options as variables at the beginning not only makes
6973
the configuration file easier to understand but also allows those variables to
7074
be overridden from the commandline before being used to build the documentation.
71-
This is a major feature of `sphinx-polyversion` which will be explained
72-
further down this guide.
73-
74-
.. TODO: link overrides section
75+
This is a major feature of `sphinx-polyversion` which will be explained in this
76+
section and :ref:`further down this guide<Overriding config options>`.
7577

7678
.. code-block:: py
7779
:caption: `docs/poly.py` - imports and config variables
@@ -116,6 +118,11 @@ further down this guide.
116118
"current": GitRef("local", "", "", GitRefType.BRANCH, datetime.fromtimestamp(6)),
117119
}
118120
121+
#: Whether to build using only local files and mock data
122+
MOCK = False
123+
124+
#: Whether to run the builds in sequence or in parallel
125+
SEQUENTIAL = False
119126
120127
Next you add the code handling the overrides read from the commandline.
121128
This is straightforward since `sphinx-polyversion` provides the function :code:`apply_overrides` that
@@ -177,7 +184,7 @@ in its revision.
177184
template_dir=root / src / "templates",
178185
static_dir=root / src / "static",
179186
mock=MOCK_DATA,
180-
).run(MOCK)
187+
).run(MOCK, SEQUENTIAL)
181188
182189
Using versioning data in :code:`conf.py`
183190
----------------------------------------
@@ -314,13 +321,15 @@ this flag all other versions are not build.
314321
:prog: sphinx_polyversion
315322
:nodescription:
316323

324+
.. _Overriding config options:
317325

318326
Overriding config options
319327
-------------------------
320328

321329
You can override the defaults set in `poly.py` by specifying values on the
322330
commandline. Specifying an output location will override :code:`OUTPUT_DIR` while
323331
specifying :code:`--local` will set :code:`MOCK` to :code:`True`.
332+
Specifying :code:`--sequential` will set :code:`SEQUENTIAL` to :code:`True`.
324333
All other variables can be overidden through the :code:`-o` flag. You can
325334
override the arguments passed to `sphinx-build` by entering the following:
326335

sphinx_polyversion/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def apply_overrides(namespace: dict[str, Any]) -> dict[str, Any]:
8282
overrides.setdefault("MOCK", False)
8383
if args.local:
8484
overrides["MOCK"] = True
85+
overrides.setdefault("SEQUENTIAL", False)
86+
if args.sequential:
87+
overrides["SEQUENTIAL"] = True
8588
namespace.update(overrides)
8689
return overrides
8790

sphinx_polyversion/driver.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,29 @@ async def arun(self) -> None:
361361
await asyncio.gather(*(self.build_revision(rev) for rev in self.targets))
362362
await self.build_root()
363363

364-
def run(self, mock: bool = False) -> None:
365-
"""Build all revisions or build from local files."""
364+
async def srun(self) -> None:
365+
"""Build all revisions (sequential)."""
366+
await self.init()
367+
for rev in self.targets:
368+
await self.build_revision(rev)
369+
await self.build_root()
370+
371+
def run(self, mock: bool = False, sequential: bool = False) -> None:
372+
"""
373+
Build all revisions or build from local files.
374+
375+
Parameters
376+
----------
377+
mock : bool, optional, default: False
378+
Whether to build all revisions (False) or from local files (True)
379+
sequential : bool, optional, default: False
380+
Whether to build revisions in parallel (False) or sequential (True)
381+
382+
"""
366383
if mock:
367384
asyncio.run(self.build_local())
385+
elif sequential:
386+
asyncio.run(self.srun())
368387
else:
369388
asyncio.run(self.arun())
370389

sphinx_polyversion/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ def get_parser(expect_config: bool = True) -> argparse.ArgumentParser:
8080
action="store_true",
8181
help="Build the local version of your docs.",
8282
)
83+
parser.add_argument(
84+
"--sequential",
85+
action="store_true",
86+
help="Build the revisions sequentially.",
87+
)
8388
return parser
8489

8590

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ def test_apply_overrides():
3131
namespace = {}
3232
apply_overrides(namespace)
3333

34-
assert namespace == {"a": "1", "b": "2", "MOCK": False}
34+
assert namespace == {"a": "1", "b": "2", "MOCK": False, "SEQUENTIAL": False}

0 commit comments

Comments
 (0)