Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unhandled exception when requirements.txt is missing #48

Open
HitLuca opened this issue Jul 13, 2020 · 1 comment
Open

unhandled exception when requirements.txt is missing #48

HitLuca opened this issue Jul 13, 2020 · 1 comment

Comments

@HitLuca
Copy link

HitLuca commented Jul 13, 2020

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

@MrMino
Copy link
Collaborator

MrMino commented Mar 19, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants