Mathieu Bridon pushed to branch bochecha/build-docs at BuildStream / buildstream
Commits:
-
df7553b5
by Mathieu Bridon at 2018-08-04T19:15:13Z
3 changed files:
Changes:
| ... | ... | @@ -143,7 +143,6 @@ docs: |
| 143 | 143 |
- pip3 install sphinx-click
|
| 144 | 144 |
- pip3 install sphinx_rtd_theme
|
| 145 | 145 |
- cd dist && ./unpack.sh && cd buildstream
|
| 146 |
- - pip3 install .
|
|
| 147 | 146 |
- make BST_FORCE_SESSION_REBUILD=1 -C doc
|
| 148 | 147 |
- cd ../..
|
| 149 | 148 |
- mv dist/buildstream/doc/build/html public
|
| ... | ... | @@ -31,6 +31,9 @@ ifneq ($(strip $(BST_FORCE_SESSION_REBUILD)),) |
| 31 | 31 |
BST2HTMLOPTS = --force
|
| 32 | 32 |
endif
|
| 33 | 33 |
|
| 34 |
+# Help Python find buildstream and its plugins
|
|
| 35 |
+PYTHONPATH=$(CURDIR)/..:$(CURDIR)/../buildstream/plugins
|
|
| 36 |
+ |
|
| 34 | 37 |
|
| 35 | 38 |
.PHONY: all clean templates templates-clean sessions sessions-prep sessions-clean html devhelp
|
| 36 | 39 |
|
| ... | ... | @@ -65,7 +68,6 @@ define plugin-doc-skeleton |
| 65 | 68 |
endef
|
| 66 | 69 |
|
| 67 | 70 |
|
| 68 |
-# We set PYTHONPATH here because source/conf.py sys.modules hacks dont seem to help sphinx-build import the plugins
|
|
| 69 | 71 |
all: html devhelp
|
| 70 | 72 |
|
| 71 | 73 |
clean: templates-clean sessions-clean
|
| ... | ... | @@ -103,7 +105,7 @@ sessions-prep: |
| 103 | 105 |
#
|
| 104 | 106 |
sessions: sessions-prep
|
| 105 | 107 |
for file in $(wildcard sessions/*.run); do \
|
| 106 |
- $(BST2HTML) $(BST2HTMLOPTS) --description $$file; \
|
|
| 108 |
+ PYTHONPATH=$(PYTHONPATH) $(BST2HTML) $(BST2HTMLOPTS) --description $$file; \
|
|
| 107 | 109 |
done
|
| 108 | 110 |
|
| 109 | 111 |
sessions-clean:
|
| ... | ... | @@ -114,7 +116,7 @@ sessions-clean: |
| 114 | 116 |
#
|
| 115 | 117 |
html devhelp: templates sessions
|
| 116 | 118 |
@echo "Building $@..."
|
| 117 |
- PYTHONPATH=$(CURDIR)/../buildstream/plugins \
|
|
| 119 |
+ PYTHONPATH=$(PYTHONPATH) \
|
|
| 118 | 120 |
$(SPHINXBUILD) -b $@ $(ALLSPHINXOPTS) "$(BUILDDIR)/$@" \
|
| 119 | 121 |
$(wildcard source/*.rst) \
|
| 120 | 122 |
$(wildcard source/tutorial/*.rst) \
|
| ... | ... | @@ -37,6 +37,7 @@ import click |
| 37 | 37 |
|
| 38 | 38 |
from buildstream import _yaml
|
| 39 | 39 |
from buildstream import utils
|
| 40 |
+from buildstream._frontend import cli as bst_cli
|
|
| 40 | 41 |
from buildstream._exceptions import BstError
|
| 41 | 42 |
|
| 42 | 43 |
|
| ... | ... | @@ -175,6 +176,19 @@ def ansi2html(text, palette='solarized'): |
| 175 | 176 |
return sub
|
| 176 | 177 |
|
| 177 | 178 |
|
| 179 |
+@contextmanager
|
|
| 180 |
+def capture_stdout_stderr():
|
|
| 181 |
+ from io import StringIO
|
|
| 182 |
+ |
|
| 183 |
+ oldstdout, sys.stdout = sys.stdout, StringIO()
|
|
| 184 |
+ oldstderr, sys.stderr = sys.stderr, StringIO()
|
|
| 185 |
+ |
|
| 186 |
+ yield sys.stdout, sys.stderr
|
|
| 187 |
+ |
|
| 188 |
+ sys.stdout = oldstdout
|
|
| 189 |
+ sys.stderr = oldstderr
|
|
| 190 |
+ |
|
| 191 |
+ |
|
| 178 | 192 |
# workdir()
|
| 179 | 193 |
#
|
| 180 | 194 |
# Sets up a new temp directory with a config file
|
| ... | ... | @@ -219,9 +233,11 @@ def workdir(source_cache=None): |
| 219 | 233 |
def run_command(config_file, directory, command):
|
| 220 | 234 |
click.echo("Running command in directory '{}': bst {}".format(directory, command), err=True)
|
| 221 | 235 |
|
| 222 |
- argv = ['bst', '--colors', '--config', config_file] + shlex.split(command)
|
|
| 223 |
- p = subprocess.Popen(argv, cwd=directory, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
| 224 |
- out, _ = p.communicate()
|
|
| 236 |
+ args = ['--colors', '--config', config_file, '--directory', directory] + shlex.split(command)
|
|
| 237 |
+ |
|
| 238 |
+ with capture_stdout_stderr() as (out, _):
|
|
| 239 |
+ bst_cli.main(args=args, prog_name=bst_cli.name)
|
|
| 240 |
+ |
|
| 225 | 241 |
return out.decode('utf-8').strip()
|
| 226 | 242 |
|
| 227 | 243 |
|
