Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allowing to import code generated from proto with strip_import_prefix #1406

Merged
merged 10 commits into from Oct 12, 2023

Conversation

linzhp
Copy link
Contributor

@linzhp linzhp commented Sep 8, 2023

When the proto_library has strip_import_prefix, the py files from proto are generated into a directory like bazel-bin/tests/py_proto_library/proto/_virtual_imports and symlinked in the runfiles as <runfilesroot>/<workspace name>/tests/py_proto_library/proto/_virtual_imports.
We need to add <workspace name>/tests/py_proto_library/proto/_virtual_imports to the imports of _PyProtoInfo, so it will be appended to PYTHONPATH.

Modified an existing example to demonstrate the scenario and verify the fix.

@linzhp linzhp changed the title fix: allowing to import code generated from proto fix: allowing to import code generated from proto with strip_import_prefix Sep 15, 2023
.bazelci/presubmit.yml Outdated Show resolved Hide resolved
examples/py_proto_library/.bazelrc Outdated Show resolved Hide resolved
python/private/proto/py_proto_library.bzl Show resolved Hide resolved
@aignas
Copy link
Collaborator

aignas commented Sep 26, 2023

Could you also please a line in the CHANGELOG.md?

Copy link
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@aignas aignas added this pull request to the merge queue Oct 12, 2023
Merged via the queue into bazelbuild:main with commit bee35ef Oct 12, 2023
2 checks passed
@linzhp linzhp deleted the proto branch October 12, 2023 18:03
linzhp added a commit to linzhp/rules_python that referenced this pull request Oct 15, 2023
…refix (bazelbuild#1406)

When the `proto_library` has `strip_import_prefix`, the py files from
proto are generated into a directory like
`bazel-bin/tests/py_proto_library/proto/_virtual_imports` and symlinked
in the runfiles as `<runfilesroot>/<workspace
name>/tests/py_proto_library/proto/_virtual_imports`.
We need to add `<workspace
name>/tests/py_proto_library/proto/_virtual_imports` to the `imports` of
`_PyProtoInfo`, so it will be appended to `PYTHONPATH`.

Modified an existing example to demonstrate the scenario and verify the
fix.

---------

Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants