bug: imports attr misdocumented and misinterpretered when venv mode activated

There are two bugs with the imports attribute:

First, the docs say it is a "repo root relative" path -- this is incorrect. It is a target-relative path. i.e. //foo:bar setting . means add $repo/foo to sys.path. This is evident from reading the code, it essentially does:

join(main_repo, runfiles_short_path(ctx.label), imports_attr_value), e.g. join("_main", "../+somerepo/foo", ".")

Second, when the experimental_venvs_site_packages setting is enabled, py_library treats the value as a repo-relative path, not a target-relative path.

This makes using the same imports value unnecessarily difficult.

To fix:

  • Fix docs
  • Change py_library to treat it as target-relative