Skip to content

Commit 13da5d7

Browse files
committed
Inline makecmd in make mode
1 parent 3d0110a commit 13da5d7

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

sphinx/cmd/make_mode.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def __init__(self, srcdir: str, builddir: str, opts: Sequence[str]) -> None:
6767
self.srcdir = srcdir
6868
self.builddir = builddir
6969
self.opts = [*opts]
70-
self.makecmd = os.environ.get('MAKE', 'make') # refer $MAKE to determine make command
7170

7271
def builddir_join(self, *comps: str) -> str:
7372
return path.join(self.builddir, *comps)
@@ -105,10 +104,11 @@ def build_latexpdf(self) -> int:
105104
if self.run_generic_build('latex') > 0:
106105
return 1
107106

108-
if sys.platform == 'win32':
109-
makecmd = os.environ.get('MAKE', 'make.bat')
110-
else:
111-
makecmd = self.makecmd
107+
# Use $MAKE to determine the make command
108+
make_fallback = 'make.bat' if sys.platform == 'win32' else 'make'
109+
makecmd = os.environ.get('MAKE', make_fallback)
110+
if not makecmd.lower().startswith('make'):
111+
raise RuntimeError('Invalid $MAKE command: %r' % makecmd)
112112
try:
113113
with chdir(self.builddir_join('latex')):
114114
return subprocess.call([makecmd, 'all-pdf'])
@@ -120,10 +120,11 @@ def build_latexpdfja(self) -> int:
120120
if self.run_generic_build('latex') > 0:
121121
return 1
122122

123-
if sys.platform == 'win32':
124-
makecmd = os.environ.get('MAKE', 'make.bat')
125-
else:
126-
makecmd = self.makecmd
123+
# Use $MAKE to determine the make command
124+
make_fallback = 'make.bat' if sys.platform == 'win32' else 'make'
125+
makecmd = os.environ.get('MAKE', make_fallback)
126+
if not makecmd.lower().startswith('make'):
127+
raise RuntimeError('Invalid $MAKE command: %r' % makecmd)
127128
try:
128129
with chdir(self.builddir_join('latex')):
129130
return subprocess.call([makecmd, 'all-pdf'])
@@ -134,11 +135,16 @@ def build_latexpdfja(self) -> int:
134135
def build_info(self) -> int:
135136
if self.run_generic_build('texinfo') > 0:
136137
return 1
138+
139+
# Use $MAKE to determine the make command
140+
makecmd = os.environ.get('MAKE', 'make')
141+
if not makecmd.lower().startswith('make'):
142+
raise RuntimeError('Invalid $MAKE command: %r' % makecmd)
137143
try:
138144
with chdir(self.builddir_join('texinfo')):
139-
return subprocess.call([self.makecmd, 'info'])
145+
return subprocess.call([makecmd, 'info'])
140146
except OSError:
141-
print('Error: Failed to run: %s' % self.makecmd)
147+
print('Error: Failed to run: %s' % makecmd)
142148
return 1
143149

144150
def build_gettext(self) -> int:

0 commit comments

Comments
 (0)