Skip to content

pylint can or not resolve imports from the same package depending on whether files are specified or directories, and whether -j 1 is set or not #135

@felixfontein

Description

@felixfontein

When pylint runs in parallel, it seems to process paths to individual files differently from when -j 1 is set. Since with change detection we pass a list of individual files, this is a problem.

For exampe running ANTSIBULL_CHANGE_DETECTION=true nox -Re codeqa -v in the checkout of ansible-collections/community.docker#1155 results in the errors shown in CI, while nox -Re codeqa -v passes. I've traced the call chain back to:

  1. pylint.lint.expand_modules() calls astroid.modutils.modpath_from_file()
  2. astroid.modutils.modpath_from_file() calls astroid.interpreter._import.util.is_namespace()
  3. astroid.interpreter._import.util.is_namespace() calls importlib.util._find_spec_from_path()
  4. The latter returns different results depending on wether pylint is called with -j 1 or not.

The problem seems to be that _frozen_importlib_external.PathFinder.find_spec() returns None (without -j 1) vs. a proper spec (with -j 1) for ansible_collections. I've tried adding print() statements to my system's importlib version, but for some reason that doesn't result in anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions