sphinx autodoc and autosummary with pyproject.ml - python-sphinx

In the docs
https://www.sphinx-doc.org/en/master/tutorial/describing-code.html?highlight=pyproject.toml#including-doctests-in-your-documentation
says
Note
An alternative to changing the sys.path variable is to create a pyproject.toml file and make the code installable, so it behaves like any other Python library. However, the sys.path approach is simpler.
and nothing more.
I can't make that work and I devoted at least 6 hours to this. Could you point to (or provide) a working (toy) example using autodoc, autosummary and pyproject.toml that I can reproduce?

Related

Readthedocs / Sphinx not rendering bullet list from rst file

I have a set of rst files that I am building in readthedocs with sphinx. The files have multiple bullet lists, but they are not being rendered correctly.
The text appears, but there are no bullet symbols or nesting / indentation.
To make sure it was not my files, I did a direct copy-paste from the sphinx_rtd_theme page (https://github.com/readthedocs/sphinx_rtd_theme/blob/b07560bf97dad3a4266f6145bd4b662ac708ab00/docs/demo/lists_tables.rst)
This is what the rst is supposed to render as (with ::marker for each list item in the html file)
This is what I am getting when I build the same rst using my local sphinx / rtd setup
Is there something I need to fix in my conf.py or other files?
We had the same issue (bullet points disappearing in lists) after refreshing the conda environment we use for releasing one of our packages. The other solutions listed here (thus far) didn't work for me, but downgrading docutils <0.17 did.
We are using nbsphinx (some of our docs illustrate operations with notebooks), and had recently some issues due to related package versions (jinja2, sphinx, docutils). Based on issues/comments (such as this one and that one), we used various older versions of these packages.
But as of this writing and thanks to the hard work of all the maintainers, we were able to remove all pins except for docutils. FWIW, for our current needs, the relevant subset of packages we use is:
docutils 0.16 py38_1
jinja2 3.0.0 pyhd3eb1b0_0
nbsphinx 0.8.6 pyhd8ed1ab_1 conda-forge
sphinx 4.0.1 pyhd3eb1b0_0
sphinx_rtd_theme 0.4.3 py_0
I had the same issue when using Read-The-Docs as a theme along with Sphinx-AutoAPI. Based on the answer of "Pierre D" I downgraded the docutils using:
conda install docutils=0.16
The solution worked for me. Both, missing bullets and the elongated line spacings were resolved. I guess the problem is caused by a bug in the docutils package and hope it will be fixed soon.
Other answers here point to docutils as the having the bug. But, the bug is actually in sphinx-rtd-theme. So, even though downgrading docutils seems to work, the solution that worked for us, that I think is better, is to
upgrade sphinx and sphinx-rtd-theme past the bugfix. For us, that looked like requiring sphinx>=4.3.0 and sphinx-rtd-theme>=0.5.1 (see our PR)
Seems to be a issue with sphinx_rtd_theme and new HTML5 tags in docutils. See https://github.com/readthedocs/sphinx_rtd_theme/issues/1115 for more info. As mentioned, current resolution is downgrade to docutils=0.16.
I just discovered that an RtD documentation set I maintain was experiencing this exact problem, where bullets would show on my local builds (accompanied by the ::marker in the page source) but would be absent in RtD builds (no ::marker in the page source).
I tried a couple of things that didn't work before finding this thread. Nick Crews's answer worked perfectly: I added the >=0.5.1 lower-bound constraint to the requirements-rtd.txt file that I've configured RtD to use (I already had a Sphinx==5.3.0 pin, for reasons), and poof! I had my bullets back.
UPDATE 31 Jan 2023: Based on the comments in this sphinx_rtd_theme GitHub issue, it's also important to be sure that the version of docutils that gets installed is not too high. The thread recommends a constraint of docutils<0.17, though in recent builds my bullets have rendered fine with docutils==0.17.1.
This got me curious as to why it was necessary for me to add this constraint, when I'd already had sphinx-rtd-theme declared in requirements-rtd.txt.
On taking a closer look at my RtD build logs, I discovered that RtD has its own default-requirements install step, prior to installing anything I specify in my config. In this default install step, it was installing sphinx-rtd-theme<5.0:
Collecting sphinx-rtd-theme<0.5
Downloading sphinx_rtd_theme-0.4.3-py2.py3-none-any.whl (6.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.4/6.4 MB 117.0 MB/s eta 0:00:00
Thus, when pip hit the sphinx-rtd-theme line in requirements-rtd.txt, it just ignored it, because a version of it was already installed:
Successfully installed attrs-22.1.0 importlib-metadata-5.0.0 sphinx-5.3.0
sphinx-issues-3.0.1 sphinx-removed-in-0.2.1 sphinxcontrib-applehelp-1.0.2
sphinxcontrib-devhelp-1.0.2 sphinxcontrib-htmlhelp-2.0.0 sphinxcontrib-jsmath-1.0.1
sphinxcontrib-programoutput-0.17 sphinxcontrib-qthelp-1.0.3 zipp-3.10.0
Adding the >=0.5.1 constraint thus forces an upgrade/reinstall of sphinx-rtd-theme to the latest version, fixing the problem.
So... where did this sphinx-rtd-theme<0.5 pin come from?
After digging into the RtD source for a while, I found out that there's a toggle for, essentially, "are we using the latest Sphinx version or not?":
# If defaulting to Sphinx 2+, we need to push the latest theme
# release as well. `<0.5.0` is not compatible with Sphinx 2+
self.project.get_feature_value(
Feature.USE_SPHINX_LATEST,
positive='sphinx-rtd-theme',
negative='sphinx-rtd-theme<0.5',
),
So, okaaay... I do want to use a recent version of Sphinx... why am I apparently set up to not USE_SPHINX_LATEST?
Looks like it's a compatibility decision made at some point. Any RtD docset created before a certain date (20 Oct 2020, for a personal project like mine; or, 21 Jan 2021 for RtD for Business projects) is set as not USE_SPHINX_LATEST. I assume these dates were picked for some strategic reason, likely having to do with in-the-wild usage of Sphinx < 2.0 dropping below some threshold.
Anyways! If you see a sphinx-rtd-theme<0.5 and/or sphinx<2 constraint in your RtD build logs, that's why. And, again, follow Nick Crews's advice to fix it.
I had the same problem, when listing using *, in the .rst file like:
* first item
* second item
I found out that the problem, in my case, was that I was using the theme sphinx_rtd_theme, but I didn't add it in extensions in the conf.py file. So adding the following worked for me:
extensions = [sphinx_rtd_theme,
# other extensions
]
Creating a new sphinx project solved the problem
Had the same problem:
Creating new sphinx-quickstart didn't work.
Reducing docutils to 0.16 and adding 'sphinx_rtd_theme' to the extensions list in conf.py worked:
extensions = ['sphinx_rtd_theme']

How to create distribution of Python GTK3 app?

I made an application using GTK3 on Windows (Mingw_x64 installation of GTK) and I cannot really figure out how to make a distribution out of this. According to official documentation of PyGObject, it is possible in some way.
I already tried to make a package using setuptools, but PyGObject documentation is not saying much about this process and I was not able to configure setup correctly to make it work. PyGObject has a lot of dependecies and weird imports, that I do not know how to include.
I also tried Pyinstaller, which claims it has GTK support, and it really can pack it into executable, however it is not working. I tried these two options:
make only one file (.exe), but in this situations, it throws an error, that some file is not found (libpixbufloader-ani.dll)
create a directory with all needed files (libpixbufloader-ani.dll and other libs are included this time), but when running exe, another exeption occurs, this time Struct and 2 other libraries are missing (strangely, there is a folder that contains Struct)
Becouse of the missing files, I tried adding as many paths containing needed libraries as possible to Pyinstaller, but without success.
Does anyone have any experience with packaging GTK appliciations in Python? There is definitely a way to do this, but I am not very experienced with packaging. If needed, I can provide more information.
This is an issue that has been brought up on PyInstaller's GitHub page, as others (including myself) have experienced the same issue that you've mentioned.
The last time I tried the dev version of PyInstaller, the issue still wasn't fixed, but I managed to get a working executable by using PyInstaller to find the dependencies that my Python3/GTK3 app needed, and then I used cx_Freeze to generate the final executable.

Tensorflow object detection: ImportError: No module named nets

I am currently attempting to install the tensorflow object detection app on Windows 7 (employer requirement) and I am failing at a few steps from the end.
Basically I get the following error when I run the installation test command:
ImportError: No module named nets.
I have read some solutions on the subject:
https://github.com/tensorflow/models/issues/729
https://github.com/tensorflow/models/issues/1842
which looks like this:
export PYTHONPATH="$PYTHONPATH:"somepath"/tensorflow/models/slim"
basically meaning that I must set the right path in the PYTHONPATH environmental variable.
Working with Windows, I tried calling this:
SET PYTHONPATH="$PYTHONPATH:C:tensorflow/models/slim
And when it didn't work, I created a PYTHONPATH variable in system-> environmental variables.
I'm still getting the error so I suppose that I am still missing something but due to my lack of knowledge I still can't figure out what.
Would someone familiar with Windows be able to point out what's missing?
Thanks
in linux:
add export export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim to ~/.bashrc
attention:you should keep single quote mark
if you work with windows, i guess it should like this:PYTHONPATH=$PYTHONPATH:'C:/tensorflow/models':'C:/tensorflow/models'/slim
just my guess, you can take a try.
good luck!
If you run the setup.py it will install all the relevant modules for object detection. The other option is download the git directory. cd to the folder and try to run the module from there. You might face protubuf issue. Try to install it before running the code. It's bit complicated to install protobuf in windows. But if you are not using ".pb" file, then you don't need to.
I figured out a way to make it work. I am not writing this as a final answer as it is mostly a workaround and due to lack of understanding from my part I cannot guarantee it will work (and also it might not be best good practice).
Anyway here it is:
As Beta previously suggested, you have to run setup.py, however running it from models folder did not do it for me, I also had to run it from object detection folder.
However there was a problem there, it generated an error saying the BUILD already existed (which was correct) so I had to delete the BUILD file from inside of model.
After that it worked, turns out the path I had set was working fine.
Now if some experts would look into this and explain how and why this workaround worked it might make this a valid solution.

How to check reST wellformedness with Sphinx?

When uploading README in reStructuredText to PyPI they should be valid reST documents. We already have Sphinx as a requirement to build docs. Is it also possible to check one file with Sphinx?
It appears that distutils implements setup.py check -r command since Python 2.7 that does just that.
I am leaving the question open in case somebody discovers an easy way check arbitrary reST files with Sphinx without complicated configuration and setup. Perhaps Sphinx can provide more features like checking linked documents and external links.

How to Design/Figure out the Required Path in Ruby Programming?

Is there a well-designed method that can run my ruby program from anywhere? I already searched a couple of ways to import my ruby program from the different directories by using the relative path.
i.e.
File.expand_path(“my_path”)
It worked and let me run it anywhere, but somehow, it is a little unreadable and I think it is pretty messy. So I think there may be a solution or convention to deal with this kind of problem when there are many file paths that have to be imported.
I suggest you have a look how to package a gem and build your own and install it. Or you could place your binary in $PATH, but that's a bit more messy.

Resources