VACUMM / sphinx-fortran

Fortran domain and autodoc extensions to Sphinx
Other
45 stars 29 forks source link

Fatal error when documenting multiple types in the same file #35

Closed dvuckovic closed 3 years ago

dvuckovic commented 3 years ago

In case Fortran source has two or more types declared in the same file, like so:

module test
    implicit none

    type foo
        integer :: foo
    end type foo

    type bar
        integer :: bar
    end type bar
end module test

Python will throw a fatal error during generation of the documentation:

Exception occurred:
  File "/path/to/sphinxfortran/fortran_autodoc.py", line 1246, in format_quickaccess
    tlist = sorted(self.get_blocklist('types', module))
TypeError: '<' not supported between instances of 'dict' and 'dict'

The issue stems from trying to sort dictionaries using the sorted() function, which is apparently unsupported. This occurs in format_quickaccess method, so it's probably better to simply remove the call to sorted(), and leave this job to get_blocklist method, where sort parameter defaults to True anyway.

Fix will be provided in a PR shortly, for your consideration.

BTW, it would be very cool to be able to omit the autogenerated Quick access section from the output, possibly by introducing additional option to f:autosrcfile directive, for example :no_quick_access:. I can probably try to prepare this, but I wanted first to check if you accept these kind of enhancements via PRs and if the project is still alive?

Thanks for this great plugin, it's quite unique :)

Lebam360 commented 3 years ago

I know that this is closed, but when I tried to run sphinx-fortran, I got a crash. After tracing back to find the issue, I found out that the problem was that I had a file with multiple types. It seems like the problem was fixed, but perhaps I am mistaken? sphinx-err-0fk2jd2l.log

dvuckovic commented 3 years ago

@Lebam360 This issue was indeed fixed, but a new release is still pending, as far as I can tell. The latest release version on PyPi is 1.1.1 which does not include the fix.

However, you can try to install the plugin via Git source:

pip3 install git+https://github.com/VACUMM/sphinx-fortran.git@master

This command should checkout the latest state of the repo (master branch) and build the plugin from it.

Lebam360 commented 3 years ago

I installed the plugin through the Git source like you suggested, but sphinx-fortran is still crashing when I try to include a module with multiple types. I am still getting the same issues as before. This might just be because I need to wait until the new release or something, but it also could be something else. I just wanted to let you know. sphinx-err-i9z70kum.log

dvuckovic commented 2 years ago

@Lebam360 Sorry for the late reply, but your log file indicates that you are still using an older version of the plugin:

  File "/home/aand/.local/lib/python3.8/site-packages/sphinxfortran/fortran_autodoc.py", line 1246, in format_quickaccess
    tlist = sorted(self.get_blocklist('types', module))
TypeError: '<' not supported between instances of 'dict' and 'dict'

The line in question now looks a bit different (does not use sorted() function):

tlist = self.get_blocklist('types', module)

Please check that you are indeed installing the correct state, you can use the following command to remove any previously installed version of the plugin:

pip3 uninstall sphinx-fortran

Then, try to reinstall it from the Git state:

pip3 install git+https://github.com/VACUMM/sphinx-fortran.git@master

PIP should be quite verbose that it is indeed building from source:

Collecting git+https://github.com/VACUMM/sphinx-fortran.git@master
  Cloning https://github.com/VACUMM/sphinx-fortran.git (to revision master) to /private/var/folders/zk/bw8t57f168z5_c1_d68yk5cm0000gn/T/pip-req-build-vj7ci0il
  Running command git clone -q https://github.com/VACUMM/sphinx-fortran.git /private/var/folders/zk/bw8t57f168z5_c1_d68yk5cm0000gn/T/pip-req-build-vj7ci0il
Building wheels for collected packages: sphinx-fortran
  Building wheel for sphinx-fortran (setup.py) ... done
  Created wheel for sphinx-fortran: filename=sphinx_fortran-1.1.1-py3-none-any.whl size=36936 sha256=11199db111e657368ccfd468558883318324dbd79f0855204e0f923f8a20e92a
  Stored in directory: /private/var/folders/zk/bw8t57f168z5_c1_d68yk5cm0000gn/T/pip-ephem-wheel-cache-3cvmsf0j/wheels/9e/11/c7/9b90a9abd360d6d4ef0fed924b25ae3fb378b60198d3527f23
Successfully built sphinx-fortran
Installing collected packages: sphinx-fortran
Successfully installed sphinx-fortran-1.1.1

(Ignore the version number in the output, it's simply using the same value defined by the sources, e.g. current release.)