tardyp / sphinx-jinja

MIT License
28 stars 22 forks source link

Use `app.srcdir` as jinja_base #25

Closed mathiasertl closed 2 years ago

mathiasertl commented 2 years ago

Use app.srcdir as jinja_base. Without this, sphinx-jinja behaves inconsistently when selecting "separate source and build directories" (-> Makefile is one level above index.rst/conf.py!) on startup like this:

$ sphinx-quickstart docs
Welcome to the Sphinx 4.3.2 quickstart utility.
...
You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
"source" and "build" directories within the root path.
> Separate source and build directories (y/n) [n]: y
...

If you then enable sphinx-jinja (obviously), create docs/source/test.rst and try to use it with both include and jinja directives:

$ ls docs/
build  make.bat  Makefile  source
$ ls docs/source/
conf.py  index.rst  _static  _templates  test.rst
$ echo test > docs/source/test.rst
$ vim docs/source/index.rst  # ... see output below

With index.rst being (what you would expect, I would say):

...

.. include:: test.rst

.. jinja:: 
   :file: test.rst

... and finally generate documentation the usual way:

$ make -C docs html

Without the patch, you'll get a "jinja2.exceptions.TemplateNotFound: test.rst", because jinja_base is (falsly, I would argue) docs/ and not docs/source/. As a workaround without the patch, you can specify :file: source/test.rst, which then works (or manually compute the undocumented jinja_base option.

tardyp commented 2 years ago

Hum, I agree that your proposal is a saner default. probably at the time I wrote this, src_dir was not available..

However merging this means probably breaking everyone else's doc.

I would prefer a solution one would have to configure in conf.py. So a maybe documentation patch as you suggests

mathiasertl commented 2 years ago

Hmm.

However merging this means probably breaking everyone else's doc.

This only changes behavior if you have a separate source dir (it works as before if you do not, which is the default and by far the most common variant, AFAICT). In this case the documentation for :file: doesn't cover you anyway as the source/ dir is never included in any other directive and this projects doesn't use it all.

I only found out how to use the templates really debugging the code. I would guess that most users with split dirs just couldn't get it to work and tried something else. So IMHO this would only cover few users that probably already recognized this as a bug already.

mathiasertl commented 2 years ago

Also, configuring jinja_base manually to a dir that Sphinx already knows about is quite redundant.

Naturally it's up to you the maintainer to decide what you think is best. Just let me know, I'd also update the docs for you if you prefer.

tardyp commented 2 years ago

So I just verified this indeed does not brake buildbot's doc, so for what that test is worth I'll merge it..