pip-check-reqs
pip-check-reqs copied to clipboard
unhandled exception when requirements.txt is missing
when running pip-missing-reqs
command on my project, if no requirements.txt
is found the execution stops as expected. The output is an unhandled exception tho, which could be catched and returned with a cleaner version
output sample:
> pip-missing-reqs project
Traceback (most recent call last):
File "/Users/user/.local/share/virtualenvs/project/lib/python3.6/site-packages/pip/_internal/req/req_file.py", line 573, in get_file_content
with open(url, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/.local/share/virtualenvs/project/bin/pip-missing-reqs", line 8, in <module>
sys.exit(main())
File "/Users/user/.local/share/virtualenvs/project/lib/python3.6/site-packages/pip_check_reqs/find_missing_reqs.py", line 144, in main
requirements_filename=requirements_filename,
File "/Users/user/.local/share/virtualenvs/project/lib/python3.6/site-packages/pip_check_reqs/find_missing_reqs.py", line 63, in find_missing_reqs
session=PipSession(),
File "/Users/user/.local/share/virtualenvs/project/lib/python3.6/site-packages/pip/_internal/req/req_file.py", line 151, in parse_requirements
for parsed_line in parser.parse(filename, constraint):
File "/Users/user/.local/share/virtualenvs/project/lib/python3.6/site-packages/pip/_internal/req/req_file.py", line 330, in parse
for line in self._parse_and_recurse(filename, constraint):
File "/Users/user/.local/share/virtualenvs/project/lib/python3.6/site-packages/pip/_internal/req/req_file.py", line 335, in _parse_and_recurse
for line in self._parse_file(filename, constraint):
File "/Users/user/.local/share/virtualenvs/project/lib/python3.6/site-packages/pip/_internal/req/req_file.py", line 369, in _parse_file
filename, self._session, comes_from=self._comes_from
File "/Users/user/.local/share/virtualenvs/project/lib/python3.6/site-packages/pip/_internal/req/req_file.py", line 577, in get_file_content
'Could not open requirements file: {}'.format(exc)
pip._internal.exceptions.InstallationError: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
the output can be cleaned in something like
> pip-missing-reqs project
FileNotFoundError: Cannot find 'requirements.txt' file, please add it in order to detect missing requirements
If deemed useful I can try and make a PR when I have the time
Yes, this would be useful, but the traceback will still need to be shown if --debug
is present.
All of this is also the case when the target path is wrong.