Skip to content

Commit 21486ac

Browse files
committed
move file transfers from Makefile to py
1 parent be29bc8 commit 21486ac

File tree

4 files changed

+47
-53
lines changed

4 files changed

+47
-53
lines changed

docsrc/Makefile

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# You can set these variables from the command line, and also
55
# from the environment for the first two.
66
SPHINXOPTS ?=
7-
SPHINXBUILD ?= sphinx-multiversion
7+
SPHINXBUILD ?= sphinx-build
88
SOURCEDIR = source
99
BUILDDIR = _build
1010

@@ -18,26 +18,22 @@ help:
1818
# copy rendered docs and .nojekyll (for github.io) to docs folder
1919
# remove example notebooks from source folder
2020
github:
21-
# @cp ../INSTALL.rst source/installation.rst # INSTALL.rst does not exist
22-
@cp ../CONTRIBUTING.md source/contributing.md
21+
@cp ../INSTALL.rst source/installation.rst
22+
@cp ../CONTRIBUTING source/contributing.md
2323
@cp -a ../examples/. source/_examples
24-
@rm -rf source/_examples/in_progress # ignore if in_progress does not exist
25-
@$(SPHINXBUILD) "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS)
26-
@echo 'Copying output from _build/html to ../docs.'
24+
@rm -r source/_examples/in_progress
25+
@make html
2726
@cp -a _build/html/. ../docs
2827
@cp .nojekyll ../docs/.nojekyll
28+
@rm -r _build/html/
29+
@rm -r source/_examples
30+
@rm source/installation.rst
31+
@rm source/contributing.md
2932

3033
clean:
3134
@rm -rf ../docs/*
3235
@rm -rf _build
3336

34-
clean-all:
35-
@rm -rf ../docs/*
36-
@rm -rf _build
37-
@rm -rf source/_examples
38-
# remove all files from source/api except for bayesflow.rst
39-
@find source/api -type f ! -name 'bayesflow.rst' -exec rm -f {} +
40-
4137
.PHONY: help Makefile
4238

4339
# Catch-all target: route all unknown targets to Sphinx using the new

docsrc/poly.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sphinx_polyversion.driver import DefaultDriver
66
from sphinx_polyversion.git import Git, GitRef, GitRefType, file_predicate, refs_by_type
77
from sphinx_polyversion.pyvenv import Pip
8-
from sphinx_polyversion.sphinx import CommandBuilder
8+
from sphinx_polyversion.sphinx import SphinxBuilder, Placeholder
99

1010
#: Regex matching the branches to build docs for
1111
BRANCH_REGEX = r"master-doctest"
@@ -73,7 +73,9 @@ def root_data(driver):
7373
buffer_size=1 * 10**9, # 1 GB
7474
predicate=file_predicate([src]), # exclude refs without source dir
7575
),
76-
builder=CommandBuilder(source=src / "source", cmd=["make", "github"]),
76+
builder=SphinxBuilder(
77+
src / "source", args=SPHINX_ARGS.split(), pre_cmd=["python", "pre-build.py", Placeholder.SOURCE_DIR]
78+
),
7779
env=Pip.factory(args=POETRY_ARGS.split(), venv="buildvenv"),
7880
template_dir=root / src / "polyversion/templates",
7981
static_dir=root / src / "polyversion/static",

docsrc/pre-build.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
import shutil
3+
import sys
4+
from pathlib import Path
5+
6+
7+
def copy_files(sourcedir):
8+
basedir = Path(sourcedir).parent.parent
9+
print(basedir, sourcedir)
10+
11+
examples_src = os.path.join(basedir, "examples")
12+
examples_dst = os.path.join(sourcedir, "_examples")
13+
if os.path.exists(examples_src):
14+
print("Copying examples")
15+
shutil.copytree(examples_src, examples_dst, dirs_exist_ok=True)
16+
examples_in_progress = os.path.join(examples_dst, "in_progress")
17+
if os.path.exists(examples_in_progress):
18+
shutil.rmtree(examples_in_progress)
19+
contributing_src = os.path.join(basedir, "CONTRIBUTING.md")
20+
contributing_dst = os.path.join(sourcedir, "contributing.md")
21+
if os.path.exists(contributing_src):
22+
shutil.copy2(contributing_src, contributing_dst)
23+
installation_src = os.path.join(basedir, "INSTALL.rst")
24+
installation_dst = os.path.join(sourcedir, "installation.rst")
25+
if os.path.exists(installation_src):
26+
shutil.copy2(installation_src, installation_dst)
27+
print(os.listdir(sourcedir))
28+
print(os.listdir(examples_dst))
29+
30+
31+
if __name__ == "__main__":
32+
print("Running pre-build script") # move files around if necessary
33+
sourcedir = sys.argv[1]
34+
copy_files(sourcedir)

docsrc/source/conf.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
import os
1313
import sys
14-
import shutil
1514
from sphinx_polyversion import load
1615
from sphinx_polyversion.git import GitRef
1716

@@ -134,49 +133,12 @@
134133

135134
autosummmary_generate = True
136135

137-
# sphinx-multiversion: select tags, branches and remotes
138-
smv_tag_whitelist = r"^(v1.1.6)$"
139-
# smv_branch_whitelist = r"^(|doc-autosummary|master|dev)$"
140-
smv_branch_whitelist = r"^(master)$"
141-
smv_remote_whitelist = None
142-
143-
144-
# move files around if necessary
145-
def copy_files_handler(app, config):
146-
print("TODO")
147-
return
148-
current_version = config["smv_current_version"]
149-
current_metadata = config["smv_metadata"][current_version]
150-
basedir = current_metadata["basedir"]
151-
sourcedir = current_metadata["sourcedir"]
152-
153-
print("Current version:", current_version)
154-
print("Basedir:", basedir)
155-
print("Metadata:", current_metadata)
156-
157-
examples_src = os.path.join(basedir, "examples")
158-
examples_dst = os.path.join(sourcedir, "_examples")
159-
if os.path.exists(examples_src):
160-
shutil.copytree(examples_src, examples_dst, dirs_exist_ok=True)
161-
examples_in_progress = os.path.join(examples_dst, "in_progress")
162-
if os.path.exists(examples_in_progress):
163-
shutil.rmtree(examples_in_progress)
164-
contributing_src = os.path.join(basedir, "CONTRIBUTING.md")
165-
contributing_dst = os.path.join(sourcedir, "contributing.md")
166-
if os.path.exists(contributing_src):
167-
shutil.copy2(contributing_src, contributing_dst)
168-
installation_src = os.path.join(basedir, "INSTALL.rst")
169-
installation_dst = os.path.join(sourcedir, "installation.rst")
170-
if os.path.exists(installation_src):
171-
shutil.copy2(installation_src, installation_dst)
172-
173136

174137
def cleanup_handler(app, exception):
175138
print("Done, what now?")
176139

177140

178141
def setup(app):
179-
app.connect("config-inited", copy_files_handler)
180142
app.connect("build-finished", cleanup_handler)
181143

182144

0 commit comments

Comments
 (0)