pycco-docs / pycco

Literate-style documentation generator.
https://pycco-docs.github.io/pycco/
Other
842 stars 144 forks source link

Option --skip-bad-files now skips all kind of bad files #101

Closed vrde closed 6 years ago

vrde commented 6 years ago

I had some problems running pycco in a directory containing some cached Pytest files (.pytest_cache/). I noticed that even if the --skip-bad-files option was used, Pycco would still fail to generate the documentation. Removing the cached files is an option of course, but in my opinion Pycco should treat those files as bad files.

Given a .pytest_cache dire.tory (AFAIK it should be generate by Pytest when running the tests), the new behavior is the following,

With the --skip-bad-files option

 ~/r/pycco git:(master) ✗ ➜ pycco --skip-bad-files  .pytest_cache/
pycco [FAILURE]: .pytest_cache/v/cache/lastfailed, Can't figure out the language!
pycco [FAILURE]: .pytest_cache/v/cache/nodeids, Can't figure out the language!

Without the --skip-bad-files option

 ~/r/pycco git:(master) ✗ ➜ pycco .pytest_cache/
Traceback (most recent call last):
  File "/home/vrde/repos/pycco/pycco/main.py", line 392, in get_language
    lang = lexers.guess_lexer(code).name.lower()
  File "/home/vrde/.local/share/virtualenvs/1e40936ec5d4128/lib/python3.6/site-packages/pygments/lexers/__init__.py", line 252, in guess_lexer
    raise ClassNotFound('no lexer matching the text found')
pygments.util.ClassNotFound: no lexer matching the text found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/vrde/.local/share/virtualenvs/1e40936ec5d4128/bin/pycco", line 11, in <module>
    load_entry_point('Pycco', 'console_scripts', 'pycco')()
  File "/home/vrde/repos/pycco/pycco/main.py", line 620, in main
    skip=opts.skip_bad_files)
  File "/home/vrde/repos/pycco/pycco/main.py", line 532, in process
    next_file()
  File "/home/vrde/repos/pycco/pycco/main.py", line 520, in next_file
    encoding=encoding))
  File "/home/vrde/repos/pycco/pycco/main.py", line 65, in generate_documentation
    return _generate_documentation(source, code, outdir, preserve_paths, language)
  File "/home/vrde/repos/pycco/pycco/main.py", line 72, in _generate_documentation
    language = get_language(file_path, code, language=language)
  File "/home/vrde/repos/pycco/pycco/main.py", line 402, in get_language
    raise ValueError("Can't figure out the language!")
ValueError: Can't figure out the language!
coveralls commented 6 years ago

Coverage Status

Coverage increased (+1.7%) to 83.333% when pulling c7b01d3aeef3dd0786190d4c5330fcd800b7066e on vrde:master into fce7f146a3c70e637af86e9fa9856515d3165b8f on pycco-docs:master.

vrde commented 6 years ago

@subsetpark any suggestion on how to backport the test to Python 2.7? One idea is to use mock, I can add it to requirements.tests.txt.

subsetpark commented 6 years ago

@vrde Yeah, I think it's totally kosher to add a requirement on mock. Let me know if you need any other feedback.

subsetpark commented 6 years ago

@vrde while you're at it, I think skip_bad_files is not a great name. What would you think about aliasing to something like skip_failures or continue_on_failure or what have you?

vrde commented 6 years ago

@subsetpark thanks for your comments.

@vrde while you're at it, I think skip_bad_files is not a great name. What would you think about aliasing to something like skip_failures or continue_on_failure or what have you?

What about -x, --ignore-errors?

For my taste, the default behavior should be to ignore errors, and have a --strict flag (or something similar) that makes the program exit on the first error.

subsetpark commented 6 years ago

@subsetpark thanks for your comments. ...

@vrde I like the first suggestion... I think the second is a step too far for now.

vrde commented 6 years ago

I like the first suggestion... I think the second is a step too far for now.

Sure, check my last commit. I changed the shortcut from -x to -e because the full flag is called --ignore-errors (i is already taken by --index). I can change it back to -x if you prefer, up to you :)

vrde commented 6 years ago

All green. To be honest the CI failed on my last commit, something with hypothesis, tell me if you think it's crucial. I committed exactly the same change again to trigger another build, and this passes now.

subsetpark commented 6 years ago

Thanks @vrde - but I'd rather have both command flags point to the same argument, rather than break the command-line API.

vrde commented 6 years ago

Thanks @vrde - but I'd rather have both command flags point to the same argument, rather than break the command-line API.

Sure thing. I just noticed you said "aliasing" in one of your comments.

subsetpark commented 6 years ago

@vrde , thanks for your work! I’ve got a minor refactor to merge after this one then I’ll cut a new version.