From cb5a91a165534a1abfee319a2c0e97a7294d732a Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Sun, 8 Dec 2019 09:50:15 +0100
Subject: [PATCH] fix doc generation

- os.path.walk does not exist in Python3 anymore, use os.walk instead
  (changed interface)
- sphinx-build tried really hard to use Python 2. Import sphinx from
  current interpreter instead and directly call its __main__ function
---
 doc/make.py | 34 +++++++++++-----------------------
 1 file changed, 11 insertions(+), 23 deletions(-)

diff --git a/doc/make.py b/doc/make.py
index 1b9f43a1d..4d0ce533f 100644
--- a/doc/make.py
+++ b/doc/make.py
@@ -5,18 +5,13 @@ import shutil
 from ost import settings
 from optparse import OptionParser
 import subprocess
+import sphinx
 
 if len(sys.argv)==2:
   root_dir=sys.argv[1]
 else:
   root_dir='.'
 
-def _CheckCall(cmd, shell):
-  r = subprocess.call(cmd, shell=True)
-  if r != 0:
-    sys.stderr.write("Command '%s' returned non-zero exit status %d\n"%(cmd, r))
-    sys.exit(-1)
-
 def _OutputPath(inpath, outdir):
   parts=inpath.split(os.path.sep)
   filtered_parts=[outdir]
@@ -71,7 +66,6 @@ def _CollectRstDocs(outdir, dirname, fnames):
         img_name = os.path.join(dirname,img)
         _CreateAndCopy(img_name, outdir)
 
-
 def ParseArgs():
   parser = OptionParser("usage: ost make.py [options] ")
   parser.add_option("-l","--linkcheck", action="store_true", default=False, dest="linkcheck", help="validate all external links")
@@ -93,25 +87,19 @@ if opts.quiet:
   opt_str=' -Q '
 
 for sub_dir in ('modules',):
-  os.path.walk(sub_dir, _CollectRstDocs, 'doc/source')
-sphinx_bin=settings.Locate(['sphinx-build', 'sphinx-build-2.6','sphinx-build-2.7'])
+  print("start walking")
+  for directory, dirnames, filenames in os.walk(sub_dir):
+    _CollectRstDocs('doc/source', directory, filenames)
 
 if opts.html:
-  cmd='%s %s -b html -c %s %s %s' % (sphinx_bin, opt_str, 
-                                     'doc/conf', 'doc/source', 'doc/build/html')
-  print(cmd)
-  _CheckCall(cmd, shell=True)
+  sphinx.main([opt_str, '-b', 'html', '-c', 'doc/conf', 'doc/source', 'doc/build/html'])
 
 if opts.doctest:
-  cmd='%s %s -b doctest -c %s %s %s' % (sphinx_bin, opt_str, 
-                                        'doc/conf', 'doc/source', 
-                                        'doc/build/doctest')
-  _CheckCall(cmd, shell=True)
+  sphinx.main([opt_str, '-b', 'doctest', '-c', 'doc/conf', 'doc/source', 'doc/build/html'])
+
 if opts.build_json:
-  cmd='%s %s -b json -c %s %s %s' % (sphinx_bin, opt_str, 'doc/conf', 
-                                     'doc/source', 'doc/build/json')
-  _CheckCall(cmd, shell=True)
+  sphinx.main([opt_str, '-b', 'json', '-c', 'doc/conf', 'doc/source', 'doc/build/html'])
+
 if opts.linkcheck:
-  cmd='%s %s -b linkcheck -c %s %s %s' % (sphinx_bin, opt_str, 'doc/conf', 
-                                          'doc/source', 'doc/build/check')
-  _CheckCall(cmd, shell=True)
+  sphinx.main([opt_str, '-b', 'linkcheck', '-c', 'doc/conf', 'doc/source', 'doc/build/html'])
+
-- 
GitLab