pythontoxliterate-programming

How can I pass *.py to pycco via tox?


The following command works:

$ pycco *.py
# generates literate-style documentation
# for all .py files in the current folder

And the following snippet in my tox.ini file works as expected:

[testenv:pycco]
deps =
    pycco
commands =
    pycco manage.py
# generates literate-style documentation
# for manage.py

But if I try to use a glob:

[testenv:pycco]
deps =
    pycco
commands =
    pycco *.py

...I get the following error:

  File "/home/user/Documents/project/.tox/pycco/lib/python3.7/site-packages/pycco/main.py", line 79, in generate_documentation
    code = open(source, "rb").read().decode(encoding)
FileNotFoundError: [Errno 2] No such file or directory: '*.py'

How can I pass *.py to pycco via tox?


Solution

  • You cannot do this directly because pycco does not (currently) support glob expansions. Instead you can create a shell script execute_pycco.sh as follows:

    #!/bin/sh
    
    pycco *.py
    

    Update tox.ini as follows:

    [testenv:pycco]
    deps =
        pycco
    commands =
        ./execute_pycco.sh
    

    You will now execute your shell script in the "pycco" environment created by tox. This method also allows you to define more elaborate scripts:

    #!/bin/sh
    
    filelist=$( find . -name '*.py' | grep -v ".tox" )
    # make a list of all .py files in all subfolders,
    # except the .tox/ subfolder
    
    pycco -ip $filelist
    # generate literate-style documentation for all
    # files in the list