Skip to content

ImportError for implicit namespace (pyproject, setuptools) #7875

@b-kamphorst

Description

@b-kamphorst

Bug description

Hi all,

I try to run pylint on an implicit namespace that is build from a pyproject.toml with setuptools as backend. However, pylint is not able to deduce the namespace and throws an ImportError.

Project lay-out:

|-- pyproject.toml |-- src |-- foo |-- bar |-- __init__.py |-- fun.py 

pyproject.toml

[build-system] requires = ["setuptools", "setuptools-scm"] build-backend = "setuptools.build_meta" [project] name = "foo.bar" version = "0.0.1"

fun.py

def foo() -> None: pass

Configuration

No response

Command used

pip install . pylint foo.bar

Pylint output

Traceback (most recent call last): File "/home/bart/git/pylint-tester/.venv/bin/pylint", line 8, in <module> sys.exit(run_pylint()) File "/home/bart/git/pylint-tester/.venv/lib/python3.10/site-packages/pylint/__init__.py", line 35, in run_pylint PylintRun(argv or sys.argv[1:]) File "/home/bart/git/pylint-tester/.venv/lib/python3.10/site-packages/pylint/lint/run.py", line 207, in __init__ linter.check(args) File "/home/bart/git/pylint-tester/.venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 696, in check ast_per_fileitem = self._get_asts(fileitems, data) File "/home/bart/git/pylint-tester/.venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 707, in _get_asts for fileitem in fileitems: File "/home/bart/git/pylint-tester/.venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 874, in _iterate_file_descrs for descr in self._expand_files(files_or_modules).values(): File "/home/bart/git/pylint-tester/.venv/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 881, in _expand_files result, errors = expand_modules( File "/home/bart/git/pylint-tester/.venv/lib/python3.10/site-packages/pylint/lint/expand_modules.py", line 149, in expand_modules modpath = _modpath_from_file( File "/home/bart/git/pylint-tester/.venv/lib/python3.10/site-packages/pylint/lint/expand_modules.py", line 21, in _modpath_from_file return modutils.modpath_from_file_with_callback( File "/home/bart/git/pylint-tester/.venv/lib/python3.10/site-packages/astroid/modutils.py", line 303, in modpath_from_file_with_callback raise ImportError( ImportError: Unable to find module for /home/bart/git/pylint-tester/.venv/lib/python3.10/site-packages/foo/bar/fun.py in /home/bart/git/pylint-tester, /home/bart/git/pylint-tester/.venv/bin, /home/bart/.pyenv/versions/3.10.8/lib/python310.zip, /home/bart/.pyenv/versions/3.10.8/lib/python3.10, /home/bart/.pyenv/versions/3.10.8/lib/python3.10/lib-dynload, /home/bart/git/pylint-tester/.venv/lib/python3.10/site-packages

Expected behavior

pylint analysis of the module, similar to the following output (obtained by putting fun.py in foo and updating the package name):

************* Module foo .venv/lib/python3.10/site-packages/foo/__init__.py:1:0: C0104: Disallowed name "foo" (disallowed-name) ************* Module foo.fun .venv/lib/python3.10/site-packages/foo/fun.py:1:0: C0114: Missing module docstring (missing-module-docstring) .venv/lib/python3.10/site-packages/foo/fun.py:1:0: C0116: Missing function or method docstring (missing-function-docstring) .venv/lib/python3.10/site-packages/foo/fun.py:1:0: C0104: Disallowed name "foo" (disallowed-name) ------------------------------------------------------------------ Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Pylint version

pylint 2.15.7 astroid 2.12.13 Python 3.10.8 (main, Nov 30 2022, 11:20:47) [GCC 9.4.0]

OS / Environment

Ubuntu 20.04.5 LTS (in WSL 2 on Windows 10)

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions