Skip to content

Commit 0d69ce5

Browse files
committed
main: Pass Python interpreter flags and -X options to child processes
1 parent 7109646 commit 0d69ce5

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

sphinx_multiversion/main.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,36 @@ def load_sphinx_config(confpath, confoverrides, add_defaults=False):
8989
return result
9090

9191

92+
def get_python_flags():
93+
if sys.flags.bytes_warning:
94+
yield "-b"
95+
if sys.flags.debug:
96+
yield "-d"
97+
if sys.flags.hash_randomization:
98+
yield "-R"
99+
if sys.flags.ignore_environment:
100+
yield "-E"
101+
if sys.flags.inspect:
102+
yield "-i"
103+
if sys.flags.isolated:
104+
yield "-I"
105+
if sys.flags.no_site:
106+
yield "-S"
107+
if sys.flags.no_user_site:
108+
yield "-s"
109+
if sys.flags.optimize:
110+
yield "-O"
111+
if sys.flags.quiet:
112+
yield "-q"
113+
if sys.flags.verbose:
114+
yield "-v"
115+
for option, value in sys._xoptions.items():
116+
if value is True:
117+
yield from ("-X", option)
118+
else:
119+
yield from ("-X", "{}={}".format(option, value))
120+
121+
92122
def main(argv=None):
93123
if not argv:
94124
argv = sys.argv[1:]
@@ -297,7 +327,13 @@ def main(argv=None):
297327
]
298328
)
299329
logger.debug("Running sphinx-build with args: %r", current_argv)
300-
cmd = (sys.executable, "-m", "sphinx", *current_argv)
330+
cmd = (
331+
sys.executable,
332+
*get_python_flags(),
333+
"-m",
334+
"sphinx",
335+
*current_argv,
336+
)
301337
current_cwd = os.path.join(data["basedir"], cwd_relative)
302338
subprocess.check_call(cmd, cwd=current_cwd)
303339

0 commit comments

Comments
 (0)