Skip to content

Cannot import a module scattered in multiple directories #330

@plule-ansys

Description

@plule-ansys

Hello,

When the files of a module are not all in the same directory, then one seem to shadow the others even with correct "imports" arguments.

For example, in this structure, sub1 and sub2 are meant to be abstracted by the import, and the full my_module module is expected to have both a.py and b.py. However, only one of those can be used at the same time.

  • sub1: BUILD.bazel (py_library with "imports = ["sub1"])
  • sub1/my_module: a.py
  • sub2: BUILD.bazel (py_library with "imports = ["sub2"])
  • sub2/my_module: b.py

Basic reproduction here.

  • bazel run //:main fails with missing module
  • However, if I set the PYTHONPATH to "sub1;sub2" (or "sub1:sub2" on Linux), python main.py succeeds.
  • If I remove the dependency and import to //sub1:a then it works
  • If I remove the dependency and import to //sub2:b then it works

Bazel version: 3.0.0 and 3.3.0
OS: Seen on Windows 10 and Linux
Rules version: 0.0.2
Python version:  Python 3.7.6 and 3.6.3
Actual use case: Mixing generated and non generated files, or generated rules putting the files in a subfolder like with this code generation: rules_proto_grpc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions