Skip to content

Commit 6a772bb

Browse files
committed
docs: allow building without polyversion
1 parent e12aeef commit 6a772bb

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

docsrc/pre-build.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
import shutil
33
import sys
44
from pathlib import Path
5-
from sphinx_polyversion.git import Git
5+
6+
try:
7+
from sphinx_polyversion.git import Git
8+
9+
USE_POLYVERSION = True
10+
except ImportError:
11+
USE_POLYVERSION = False
612

713

814
def copy_files(sourcedir):
@@ -34,8 +40,13 @@ def copy_files(sourcedir):
3440

3541

3642
def patch_conf(sourcedir):
37-
root = Git.root(Path(__file__).parent)
43+
if USE_POLYVERSION:
44+
root = Git.root(Path(__file__).parent)
45+
else:
46+
root = str(Path(sourcedir).parent.parent)
3847
cursrc = os.path.join(root, "docsrc", "source")
48+
if os.path.abspath(cursrc) == os.path.abspath(sourcedir):
49+
return
3950
# copy the configuration file: shared for all versions
4051
conf_src = os.path.join(cursrc, "conf.py")
4152
conf_dst = os.path.join(sourcedir, "conf.py")

docsrc/source/conf.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
import os
1313
import sys
14-
from sphinx_polyversion import load
15-
from sphinx_polyversion.git import GitRef
14+
15+
try:
16+
from sphinx_polyversion import load
17+
from sphinx_polyversion.git import GitRef
18+
from sphinx_polyversion.api import LoadError
19+
20+
USE_POLYVERSION = True
21+
except ImportError:
22+
USE_POLYVERSION = False
23+
print("sphinx_polyversion not installed, building single version")
1624

1725
sys.path.insert(0, os.path.abspath("../.."))
1826

@@ -134,5 +142,9 @@
134142
autosummmary_generate = True
135143

136144
# versioning data for template
137-
data = load(globals())
138-
current: GitRef = data["current"]
145+
if USE_POLYVERSION:
146+
try:
147+
data = load(globals())
148+
current: GitRef = data["current"]
149+
except LoadError:
150+
print("sphinx_polyversion could not load. Building single version")

0 commit comments

Comments
 (0)