Author kebab-mai-haddi
Recipients kebab-mai-haddi
Date 2021-02-18.03:16:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I want to get all the functions and classes in module: `__main__` of the source code directory: `/tmp/rebound/rebound`. 
When I use the `pyclbr.readmodule_ex` API:
source_code_data = pyclbr.readmodule_ex(source_code_module, path=source_code_path)
I specify it the module and it's path:
DEBUG:root:Source code module: __main__, Source code path: ['/tmp/rebound/rebound/rebound']
I then get this error:
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/", line 69, in _find_spec_from_path
    raise ValueError('{}.__spec__ is None'.format(name))
ValueError: __main__.__spec__ is None
I then tried to use the function that is not supposed to be used by the public: `_readmodule`:
source_code_data = pyclbr._readmodule(source_code_module, source_code_path, )
But I could not decide what should be the value of the parameter: `inpackage`.

Upon tracing the code via debugger, I spotted a mistake:
def _find_spec_from_path(name, path=None):
    """Return the spec for the specified module.

    First, sys.modules is checked to see if the module was already imported. If
    so, then sys.modules[name].__spec__ is returned. If that happens to be
    set to None, then ValueError is raised. If the module is not in
    sys.modules, then sys.meta_path is searched for a suitable spec with the
    value of 'path' given to the finders. None is returned if no spec could
    be found.

    Dotted names do not have their parent packages implicitly imported. You will
    most likely need to explicitly import all parent packages in the proper
    order for a submodule to get the correct spec.

    if name not in sys.modules:
        return _find_spec(name, path)
        module = sys.modules[name]
        if module is None:
            return None
            spec = module.__spec__
        except AttributeError:
            raise ValueError('{}.__spec__ is not set'.format(name)) from None
            if spec is None:
                raise ValueError('{}.__spec__ is None'.format(name))
            return spec
This is the function in the module: `python3.8/importlib/` and it evaluates `__main__` as a built-in module as it falls in the `else` block.

How do I differentiate `__main__` of my target source code to read from the built-in `__main__`? In other words, how do I read the module `__main__` of the codebase: rebound?
Date User Action Args
2021-02-18 03:16:48kebab-mai-haddisetrecipients: + kebab-mai-haddi
2021-02-18 03:16:48kebab-mai-haddisetmessageid: <>
2021-02-18 03:16:48kebab-mai-haddilinkissue43247 messages
2021-02-18 03:16:47kebab-mai-haddicreate