浏览代码

Merge pull request #36 from Holzhaus/python-flags-passthrough

Python flags passthrough
Jan Holthuis 4 年之前
父节点
当前提交
c7089cb17c
共有 3 个文件被更改,包括 41 次插入3 次删除
  1. 1 1
      .travis.yml
  2. 3 1
      docs/changelog.rst
  3. 37 1
      sphinx_multiversion/main.py

+ 1 - 1
.travis.yml

@@ -91,6 +91,6 @@ before_script:
 script:
 - mkdir html
 - git fetch --all
-- sphinx-multiversion -W docs html
+- python -I -m sphinx_multiversion -W docs html
 - python setup.py build sdist bdist_wheel
 

+ 3 - 1
docs/changelog.rst

@@ -15,7 +15,7 @@ Version 0.2.4 (unreleased)
 * Fix bug in the sphinx extension which tried to load the `conf.py` from the source directory instead of the conf directory. This could lead to problems when the two directories differ. (`#11 <issue11_>`_, `#13 <issue13_>`_)
 * Fix wrong import in :file:`__main__.py` that prevented invocation using ``python -m sphinx_multiversion``. (`#23 <issue23_>`_)
 * Fix failure to find refs if ``sphinx-multiversion`` was not invoked from the root of the git repository. (`#24 <issue24_>`_, `#25 <issue25_>`_, `#26 <issue26_>`_)
-* Resolve issues with Sphinx extensions and Python modules not being reloaded when parsing the different :file:`conf.py` files. Now, each config file is parsed in it's own process, and the build is performed using the ``subprocess`` module instead of doing it all from the context of the main module. (`#22 <issue22_>`_, `#28 <issue28_>`_, `#30 <issue30_>`_)
+* Resolve issues with Sphinx extensions and Python modules not being reloaded when parsing the different :file:`conf.py` files. Now, each config file is parsed in it's own process, and the build is performed using the ``subprocess`` module instead of doing it all from the context of the main module. Python's `interpreter flags <pythonflags_>`_ (e.g. isolated mode) are passed through to the subprocesses. (`#22 <issue22_>`_, `#28 <issue28_>`_, `#30 <issue30_>`_, `#36 <issue36_>`_)
 * Rewrite the path handling of the Sphinx extension to handle branch names containing a forward slash properly on Windows and add unittests and Windows CI builds to make sure it doesn't break on future updates. (`#31 <issue31_>`_, `#35 <issue35_>`_)
 
 
@@ -77,3 +77,5 @@ Version 0.1.0
 .. _issue30: https://github.com/Holzhaus/sphinx-multiversion/issues/30
 .. _issue31: https://github.com/Holzhaus/sphinx-multiversion/issues/31
 .. _issue35: https://github.com/Holzhaus/sphinx-multiversion/issues/35
+.. _issue36: https://github.com/Holzhaus/sphinx-multiversion/issues/36
+.. _pythonflags: https://docs.python.org/3/using/cmdline.html#miscellaneous-options

+ 37 - 1
sphinx_multiversion/main.py

@@ -89,6 +89,36 @@ def load_sphinx_config(confpath, confoverrides, add_defaults=False):
     return result
 
 
+def get_python_flags():
+    if sys.flags.bytes_warning:
+        yield "-b"
+    if sys.flags.debug:
+        yield "-d"
+    if sys.flags.hash_randomization:
+        yield "-R"
+    if sys.flags.ignore_environment:
+        yield "-E"
+    if sys.flags.inspect:
+        yield "-i"
+    if sys.flags.isolated:
+        yield "-I"
+    if sys.flags.no_site:
+        yield "-S"
+    if sys.flags.no_user_site:
+        yield "-s"
+    if sys.flags.optimize:
+        yield "-O"
+    if sys.flags.quiet:
+        yield "-q"
+    if sys.flags.verbose:
+        yield "-v"
+    for option, value in sys._xoptions.items():
+        if value is True:
+            yield from ("-X", option)
+        else:
+            yield from ("-X", "{}={}".format(option, value))
+
+
 def main(argv=None):
     if not argv:
         argv = sys.argv[1:]
@@ -297,7 +327,13 @@ def main(argv=None):
                 ]
             )
             logger.debug("Running sphinx-build with args: %r", current_argv)
-            cmd = (sys.executable, "-m", "sphinx", *current_argv)
+            cmd = (
+                sys.executable,
+                *get_python_flags(),
+                "-m",
+                "sphinx",
+                *current_argv,
+            )
             current_cwd = os.path.join(data["basedir"], cwd_relative)
             subprocess.check_call(cmd, cwd=current_cwd)