Unable to find qualified name for module: main.py — what does in mean?

175 Views Asked by At

I'm using the wemake-python-styleguide for linting my code, and one of the checks outputs this message for every Python file.

So, my questions are: what does it mean, and what does the linter want to see?

Ive searched google, stack overflow, linters git, and chatGPT, but havent found an answer!

1

There are 1 best solutions below

0
On

You didn't share much detail, so I'm just guessing. I imagine this is the code that's being run: Bandit. And here's the bit that logs the message you're seeing:

    # in some cases we can't determine a qualified name
    try:
        self.namespace = b_utils.get_module_qualname_from_path(fname)
    except b_utils.InvalidModulePath:
        LOG.warning(
            "Unable to find qualified name for module: %s", self.fname
        )
        self.namespace = ""
    LOG.debug("Module qualified name: %s", self.namespace)

b_utils.get_module_qualname_from_path(fname) is in your case returning an InvalidModulePath exception. If you check what raises that exception, it is when the path cannot be split into two parts.

def get_module_qualname_from_path(path):
    """Get the module's qualified name by analysis of the path.

    Resolve the absolute pathname and eliminate symlinks. This could result in
    an incorrect name if symlinks are used to restructure the python lib
    directory.

    Starting from the right-most directory component look for __init__.py in
    the directory component. If it exists then the directory name is part of
    the module name. Move left to the subsequent directory components until a
    directory is found without __init__.py.

    :param: Path to module file. Relative paths will be resolved relative to
            current working directory.
    :return: fully qualified module name
    """

    (head, tail) = os.path.split(path)
    if head == "" or tail == "":
        raise InvalidModulePath(
            'Invalid python file path: "%s"'
            " Missing path or file name" % (path)
        )

    [code continues]

So I think you're running whatever you're running from the same directory where the .py files are, meaning the head of os.path.split(path) will be empty. Try placing the .py files in a subdirectory, and see if the message disappears.