Deptry crashes when scanning numpy because of a special character in a function name
ariffjeff opened this issue · 2 comments
Describe the bug
With pandas added as a dependency (poetry) in a cookiecutter-poetry based project, doing poetry run deptry .
will lead to the following crash because one of numpy's functions has an accented letter character in its name:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\ariff\Desktop\dev\scripts\hpm-test\.venv\Scripts\deptry.exe\__main__.py", line 7, in <module>
File "C:\Users\ariff\Desktop\dev\scripts\hpm-test\.venv\Lib\site-packages\click\core.py", line 1130, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ariff\Desktop\dev\scripts\hpm-test\.venv\Lib\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "C:\Users\ariff\Desktop\dev\scripts\hpm-test\.venv\Lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ariff\Desktop\dev\scripts\hpm-test\.venv\Lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ariff\Desktop\dev\scripts\hpm-test\.venv\Lib\site-packages\deptry\cli.py", line 230, in deptry
).run()
^^^^^
File "C:\Users\ariff\Desktop\dev\scripts\hpm-test\.venv\Lib\site-packages\deptry\core.py", line 60, in run
for mod in get_imported_modules_for_list_of_files(all_python_files)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ariff\Desktop\dev\scripts\hpm-test\.venv\Lib\site-packages\deptry\imports\extract.py", line 15, in get_imported_modules_for_list_of_files
unique_modules = set(itertools.chain.from_iterable(get_imported_modules_from_file(file) for file in list_of_files))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ariff\Desktop\dev\scripts\hpm-test\.venv\Lib\site-packages\deptry\imports\extract.py", line 15, in <genexpr>
unique_modules = set(itertools.chain.from_iterable(get_imported_modules_from_file(file) for file in list_of_files))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ariff\Desktop\dev\scripts\hpm-test\.venv\Lib\site-packages\deptry\imports\extract.py", line 29, in get_imported_modules_from_file
modules = PythonImportExtractor(path_to_file).extract_imports()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ariff\Desktop\dev\scripts\hpm-test\.venv\Lib\site-packages\deptry\imports\extractors\python_import_extractor.py", line 17, in extract_imports
tree = ast.parse(python_file.read(), str(self.file))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ariff\AppData\Local\Programs\Python\Python311\Lib\ast.py", line 50, in parse
return compile(source, filename, mode, flags,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".tox\py311\Lib\site-packages\numpy\core\tests\test_regression.py", line 2521
def cassé(x):
^
SyntaxError: invalid character '©' (U+00A9)
System
- OS: Windows 10
- Language Version: Python 3.11
- Poetry version: Poetry 1.3.2
Additional context
This issue usually occurs when including too many files to be scanned. hpm-test\.venv
Should probably not be scanned, since it does not contain your source code. Are you using the extend-exclude
argument instead of exclude
? deptry
also prints the number of files it is scanning. Does the count there match the number of files you expect to be scanned?
@fpgmaas Somehow I must have changed something that's getting deptry to scan over 4000 files like you said. It's strange since I haven't specified exlude
or extend-exclude
anywhere. I've compared the project to a fresh cookiecutter-poetry
ccp
project and I can't seem to find any differences in any of the config files that would be causing deptry to scan everything in .venv
.
I'll just chalk this up to not worth looking into since it's probably user error. Thank you for your patience as I stumble around!