Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sphinx and autodoc #757

Open
mathPi opened this issue Oct 17, 2020 · 10 comments
Open

Sphinx and autodoc #757

mathPi opened this issue Oct 17, 2020 · 10 comments

Comments

@mathPi
Copy link

mathPi commented Oct 17, 2020

Hi,
I'm trying to make the transition from pybuilder 0.11.X to 0.12.X.
I have an issue with the documentation generation and especially the autodoc.
In my project I have dependencies to external libraries, like pandas. When generating the documentation, I have an issue : "No module named 'pandas'"

I looked at the sphinx plugin source code, and it looks like it uses the pybuilder virtual env. To be able to generate the autodoc, it would need an environment with the project dependencies.

Steps to reproduce:

  • add a dependency to pandas in build.py : project.depends_on("pandas")
  • add an import somewhere in the code
  • call the audodoc in the sphinx configuration conf.py:
import os
import sys
sys.path.insert(0, os.path.abspath('../main/python')) # maybe you would need to change this path

extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.napoleon']
  • run pyb -v sphinx_generate_documentation

Does someone have the same issue ? Did someone succeed to solve it ?

Thanks for you help.

@mathPi mathPi changed the title Sphinx and autodo Sphinx and autodoc Oct 17, 2020
@arcivanov
Copy link
Member

arcivanov commented Oct 18, 2020

Hello and thanks for the report.
Please try using project.plugin_depends_on("pandas") and let me know if it works for you.

@mathPi
Copy link
Author

mathPi commented Oct 19, 2020

It works with plugin_depends_on. As I understood the behavior of the 0.12 venv build architecture, this is normal because in this case, pandas is in the .pybuilder venv.
But the problem is that it is not in the test nor the build environment anymore.
I could put pandas both in plugin_depends_on and depends_on. It would work, but I would need to do it with my full dependency list.
Do you have an idea to do it in a better way ?

@arcivanov
Copy link
Member

It works with plugin_depends_on. As I understood the behavior of the 0.12 venv build architecture, this is normal because in this case, pandas is in the .pybuilder venv.

Correct

But the problem is that it is not in the test nor the build environment anymore

project.build_depends_on("pandas") would put your dependency in the build venv as well. It would not be available for the integration tests though.

@mathPi
Copy link
Author

mathPi commented Oct 21, 2020

Yes but in my case, I want my dependency to be a runtime dependency (installed when my package is installed) and I want it to be accessible while building my documentation.
So I would like to have the same behavior as setting it with both a depends_on and a plugin_depends_on. But I don't think that's a good thing to do. The 0.12 pybuilder introduced the distinction between the 3 venv but here I would break this distinction (by putting the content of the test venv in the pybuilder venv) and also by build will install three time the same libraries.
So I am a little lost, I don't know how to do it properly.

@arcivanov
Copy link
Member

arcivanov commented Oct 21, 2020

You can add depends_on and plugin_depends_on both.
The distinction is as follows:

  • .pybuilder - PyB tooling
  • test - project runtime dependencies
  • build - project build dependencies (runtime and build combined)

In this case you need that dependency in your tooling and at runtime. These are different considerations and adding both dependencies is totally valid.

@arcivanov
Copy link
Member

@mathPi how's it going?

@mathPi
Copy link
Author

mathPi commented Oct 29, 2020

Hi, I didn't have time to continue on this subject.
I don't really want to duplicate all my dependencies because I've a lot of them in a lot of projects.
I'm thinking about 2 possible solutions :

  • making (I don't know how I'll do it right now) the sphinx plugin to use the build environment instead of the pybuilder
  • forcing the no-venvs in the build.py. I'll loose the idea of separated venvs which would be too bad.
    So I'm still thinking about it, if you have any thoughts to help me.

@arcivanov
Copy link
Member

You can't make sphinx plugin use build because then it won't find self. But sphinx may need to have access to build environment against which it is running so I may add a layer for sphinx python path.

@mathPi
Copy link
Author

mathPi commented Oct 29, 2020

How do you think it can be ?
I tried to add the build environment in the sphinx conf.py file. It worked.
Do you think about something like that but in the sphinx plugin ?

@arcivanov
Copy link
Member

I mean I would have to make a code change in a sphinx plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants