Reputation: 17032
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?
Upvotes: 0
Views: 194
Reputation: 17032
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
Upvotes: 3
Reputation: 881
The problem here is that pycco does not support glob expansions. What makes pycco *.py
work is that before the execution happens the shell actually transforms *.py
to actual files; and then passes that to the OS to run it.
When tox runs your command there's no shell involved, so whatever you write is as is passed on to the OS, so now pycco actually gets as argument *.py
hence the error.
You can work around this by either explicitly listing the file paths or using the python interpreter to do the expansion:
python -c 'from glob import glob; import subprocess; subprocess.check_call(["pycco"] + glob("*.py"))'
Put the above command inside your tox commands and things will work now as python is now the shell doing the expansion of "*.py" to actual files list.
Upvotes: 4