Skip to content
This repository was archived by the owner on Dec 14, 2021. It is now read-only.
This repository was archived by the owner on Dec 14, 2021. It is now read-only.

symbol not found if package ambiguous #73

@mbway

Description

@mbway

the codebase I'm working with is structured similarly to this. I've tried to simplify the situation as much as possible:

.
├── environment
├── src
│   ├── __init__.py
│   ├── mypackage
│   │   ├── __init__.py
│   │   └── mymodule.py
│   └── otherpackage
│       ├── helper.py
│       └── __init__.py
├── test
│   ├── __init__.py
│   └── mypackage
│       ├── __init__.py
│       └── test_mypackage.py

where environment sets PYTHONPATH like so:

THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export PYTHONPATH="${THIS_DIR}/src:${THIS_DIR}/test"

this is so that packages under src can import from other packages like from otherpackage.helper import .... By experimenting I found that Sourcetrail uses the current PYTHONPATH during scanning, so if only src is in the path then everything is OK, except that references to functions made in the test code are not discovered.
However if test is included as well then any imports like

from mypackage.mymodule import do_thing

anywhere in the codebase fail with

Imported symbol named "mymodule" has not been found.

I think this is because it's ambiguous whether the import refers to src/mypackage or test/mypackage. However the python interpreter itself does not get confused because of the ordering in PYTHONPATH. It would be nice if Sourcetrail could support situations like this as well.
I appreciate that fully qualifying imports or renaming the test packages would work but this would require large changes and may break in the future depending on the behaviour of IDE auto-importing etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions