David Mould
David Mould

Reputation: 11

PyDoc - Write multiple files at the same time

I am trying to use pydoc to output a series of .html files for our project's documentation, however I don't want to have to sit and do this manually so I'm trying to automate it so that pydoc will create documentation for all the files within a folder.

def pydoc_test():
    if __name__ == "__main__":
            subprocess.run(["python3","-m","pydoc","-w",".\src"],text=True)
            sourcepath=os.getcwd()
            sourcefiles = os.listdir(sourcepath)
            destinationpath = 'documentation'
            for file in sourcefiles:
                if file.endswith('.html'):
                    shutil.move(os.path.join(sourcepath,file), os.path.join(destinationpath,file))
            os.chdir(".\src")
            for file in glob.glob("*.py"):
                print(file)

pydoc_test()

When I run the above, the terminal gives me the below output.

No Python documentation found for 'main'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.
No Python documentation found for 'main_test'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.
main.py
main_test.py

Now clearly glob is able to find all the files listed with .py extension, but I know pydoc isn't a fan of this so I've simply used .\src which finds the files but states there's no documentation for them. This is not correct as if I do the below I get the documentation.

PS ..\football> python3 -m pydoc .\src\main.py
Help on module main:

NAME
    main - nested modules - Testing PyDoc

FILE
    ..\football\src\main.py

(I edited the above to remove my directory showing) The above (python3 -m pydoc .\src\main.py) will locate and display the documentation however this only works when I specify the file name. Any ideas why pydoc can't find the documentation when I'm trying to run it for all files simultaneously or is this not even an option within pydoc?

I have tried to adjust the directory and python I am using with the terminal without any luck. My only consideration is creating a list of all .py files within the directory and loop through them.

Upvotes: 1

Views: 160

Answers (0)

Related Questions