sphinx-needs icon indicating copy to clipboard operation
sphinx-needs copied to clipboard

sphinx-needs generates a need-pie image in source folder

Open arwedus opened this issue 4 years ago • 7 comments

We have an out-of tree build, i.e.

sphinx-build -b html src/ build/html -c src/doc/conf.py

and Sphinx(-needs?) still creates a file named _images/need_pie_401bf.png below the src/ folder.

We have added src/_images to .gitignore now, but how can I configure sphinx or sphinx-needs to make sure that no generated files are created in the source folder?

arwedus avatar Nov 25 '21 15:11 arwedus

Would be nice to get this fixed :)

twodrops avatar Feb 17 '22 17:02 twodrops

PR-413 has not workded. This is an answer to the discussion in #413. Mainly to the last comment by arwedus: https://github.com/useblocks/sphinxcontrib-needs/pull/497#issuecomment-1047506164


You are right, _images needs to be cleaned to show this error. Thanks for the hint.

With PR #500 I undo the changes of this PR.

The solution looks valid on the first check, but it has some problems:

  1. Adding images directly to the build-folder bypasses the Sphinx image handling
  2. The solution works only for HTML, not for PDF or other builders
  3. The generated img-tags must have a relative path to the image, which normally gets calculated by sphinx.

So the important line is this one env.images[rel_file_path] = ["_images", os.path.split(rel_file_path)[-1]]. This registers the image-source and lets Sphinx do all the voodoo (scale, copy, reference) for us. We should not bypass this, as in this case, our code must be builder-specific, which I try to avoid.

In the end, we will need a location under "src", which takes our images during build time. But there is no need to have them in _images.

So another solution would be to create a folder called _temp_needs when the build starts. Store all our generated images there and register them the normal way inside Sphinx. And the end of the build (event: build-finished) we could also delete this folder so that the user normally should not see it (except Sphinx crashes). But _temp_needs could be also put easily on .gitignore.

danwos avatar Feb 23 '22 07:02 danwos

Could it be that the call env.images[rel_file_path] = ["_images", os.path.split(rel_file_path)[-1]] in itself is just wrong?

All other elements in env.images have other structure ... 'common/images/xyz/abc.png': ({'overview'}, 'abc.png'), 'common/images/xyz/def.png': ({'page1'},'def.png'), '_images\need_pie_2566d.png': ['_images', 'need_pie_2566d.png'], '_images\need_pie_e4071.png': ['_images', 'need_pie_e4071.png'],

StephanKuempel avatar Feb 23 '22 09:02 StephanKuempel

changing to env.images.add_file(fromdocname, rel_file_path) should fix this ->

'_images\need_pie_47374.png': ({'docs/reports'}, 'need_pie_47374.png')}

StephanKuempel avatar Feb 23 '22 10:02 StephanKuempel

Hi @danwos I have implemented your suggestion in PR-501 and tested it locally with no issue so far. Can you take a look please.

Youcef-DZ avatar Feb 24 '22 09:02 Youcef-DZ

@danwos Do you see a chance of integrating @Youcef-DZ @StephanKuempel 's solutions to fix this problem?

twodrops avatar Jun 21 '22 08:06 twodrops

Not really sure, my questions got not answered in #501. For @StephanKuempel solution I need to get it in a PR. Looks like this will change the location and so the code for calculating the references also need to be updated. I will check it....

danwos avatar Jun 21 '22 10:06 danwos