SyntaxError during `pipreqs` execution due to legacy Python syntax in source file
- Dominant language
- Python
- Stars
- 7.5k
- Forks
- 424
- PR merge metrics
- No merged PRs in 30d
Description
**Description:**
While running `pipreqs`, I encountered a `SyntaxError` related to old Python 2-style `print` statements in one of the scanned files. The error suggests that `ast.parse()` fails when it encounters a line like:
**Environment:**
* OS: Windows 11
* Python version: 3.10
* `pipreqs` version: (latest from pip as of now)
* Installed via: `pip3 install pipreqs`
**Error traceback:**
```
Traceback (most recent call last):
File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Python310\Scripts\pipreqs.exe_main.py", line 7, in
File "C:\Python310\lib\site-packages\pipreqs\pipreqs.py", line 609, in main
init(args)
File "C:\Python310\lib\site-packages\pipreqs\pipreqs.py", line 533, in init
candidates = get_all_imports(
File "C:\Python310\lib\site-packages\pipreqs\pipreqs.py", line 153, in get_all_imports
raise exc
File "C:\Python310\lib\site-packages\pipreqs\pipreqs.py", line 139, in get_all_imports
tree = ast.parse(contents)
File "C:\Python310\lib\ast.py", line 50, in parse
return compile(source, filename, mode, flags,
File "", line 24
print "warning: %s" % msg
^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
```
**What I tried:**
* Reinstalled `pipreqs` using `pip3 install --upgrade --force-reinstall pipreqs` — **same error persists**
Contributor guide
Research direction
Start at pipreqs.py lines 139-153, where get_all_imports calls ast.parse(contents), and reproduce the failure with a scanned file containing the traceback's Python 2-style print statement. The issue does not define whether such files should be skipped, transformed, or reported differently, so confirm the expected behavior before changing it. Done means the chosen behavior has regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100