Closed hengyunabc closed 4 years ago
Sorry for a late reply, @hengyunabc. To be honest, I do not have any experience with building PDF with Sphinx. What do you think about sending a pull request?
Hi trustin, thx for this fine project.
It is only a matter of making the -M option available. The -M option is somewhat like the -b option. To create a PDF using the latexpdf builder, you call sphinx-build -M latexpdef ...
. Unlike the -b option, the -M option must be first!
Right now you are calling build_main. Instead you need to call main, which processes the -M option like this:
def main(argv: List[str] = sys.argv[1:]) -> int:
sphinx.locale.setlocale(locale.LC_ALL, '')
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
if argv[:1] == ['-M']:
return make_main(argv)
else:
return build_main(argv)
I am not sure whether it's a good idea to include the first two lines of main. Perhaps that interacts badly with your packaging. I don't know. Perhaps it would be even an improvement to set the Python locale from LC_ALL
. Anyway, you are setting LC_ALL
in your code...
Of course, you could just change the call of build_main
to:
if argv[:1] == ['-M']:
return make_main(argv)
else:
return build_main(argv)
and leave out the other lines of main
.
If you create a Windows binary, I'd happily test it.
BTW: -M enables the "make mode", which - apart from offering latexpdf and info as additional builders - speeds up rebuild significantly by just writing the outputs for changed input files. So it is a good thing for all builders including html. Gradle and Maven incremental build doesn't make much sense, if sphinx processes everything....
Thanks for the detailed report. I've just pushed a few commits and -M
option indeed seems to work as expected. However, it has a known issue: https://github.com/sphinx-doc/sphinx/issues/4900 so I guess I can't enable it by default in my Maven/Gradle plugins.
Fixed in 0.8.1
Great news! I tried it immediately and it works great!
Actually, I tried your Gradle plugin first, but resorted to using sphinx-binary directly (great modular design, BTW), because I am using
the -c option to share a common configuration directory for multiple pairs of input/output directories (one per language) and
the -D option (two) to specify the release number and the language, which are not in conf.py for obvious reasons
which are both not supported by the Gradle plugin. I didn't like to bother you with multiple feature requests...
Regarding the -c option bug: as they say in the last comment, the workaround is to put the -c option after the directories like this:
sphinx-build -M html inputDir outputDir -c configDir (-D options following now in my case)
So if you'd actually add support for multiple -D options and the -c option (after inputDir and outputDir), I'd become a happy Gradle plugin user everafter.
Kind regards, Matthias
sphinx command: