As mentioned by @dirn, a module requires a .py
extension to be considered as such.
An alternate solution that I think is cleaner, though it requires more work:
- Create a directory named
links
on your Sphinx root folder (that is, it will be a sibling to source
and build
)
- On that directory, create relative links to your scripts, adding
.py
to their names
- Add this new directory to the Python PATH on
conf.py
, under Path setup
: sys.path.insert(0, os.path.abspath('../links'))
- Now, you can use something like
.. automodule:: my_command
to have your script read as a module and documented.
A sample project would look like this:
proj_root/
proj_root/doc # Sphinx root
proj_root/doc/build
proj_root/doc/links # Remember to version this
proj_root/doc/links/my_command.py -> ../../bin/my_command
proj_root/doc/source
proj_root/doc/source/conf.py
proj_root/bin
proj_root/bin/my_command # Actual code
The advantage I see for this method is that you do not polute your bin
directory with .py
files that are just duplicates of the actual scripts.
One could probably also try to hack this through the imp
module to get it, but I think that would be uglier. I haven't tried that.