prequ icon indicating copy to clipboard operation
prequ copied to clipboard

sync: Parse errors in requirements.txt files are not reported correctly

Open suutari-ai opened this issue 7 years ago • 0 comments

The sync command should report parse errors of the requirement files rather than just fail with a traceback.

E.g. when doing prequ sync -n *.txt in a directory where there is a non-requirement txt file too, the output will look like this:

$ prequ sync -n *.txt
Traceback (most recent call last):
  File "venv/bin/prequ", line 11, in <module>
    sys.exit(main())
  File "venv/lib/python3.4/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "venv/lib/python3.4/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "venv/lib/python3.4/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "venv/lib/python3.4/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "venv/lib/python3.4/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "venv/lib/python3.4/site-packages/prequ/scripts/sync.py", line 71, in cli
    to_install, to_uninstall = sync.diff(requirements, installed_dists)
  File "venv/lib/python3.4/site-packages/prequ/sync.py", line 101, in diff
    requirements_lut = {r.link if r.editable else key_from_req(r.req): r for r in compiled_requirements}
  File "venv/lib/python3.4/site-packages/prequ/sync.py", line 101, in <dictcomp>
    requirements_lut = {r.link if r.editable else key_from_req(r.req): r for r in compiled_requirements}
  File "venv/lib/python3.4/site-packages/prequ/utils.py", line 55, in key_from_req
    key = req.name
AttributeError: 'NoneType' object has no attribute 'name'

It should look like this (e.g.):

$ prequ sync -n *.txt
Cannot parse as a requirement file: README.txt

suutari-ai avatar Oct 12 '17 05:10 suutari-ai