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

//src/test/py/bazel:py_test is broken with Python 3.11 #20660

Closed
meteorcloudy opened this issue Dec 22, 2023 · 4 comments
Closed

//src/test/py/bazel:py_test is broken with Python 3.11 #20660

meteorcloudy opened this issue Dec 22, 2023 · 4 comments
Assignees
Labels
team-Rules-Python Native rules for Python type: bug

Comments

@meteorcloudy
Copy link
Member

https://buildkite.com/bazel/bazel-bazel/builds/26029#018c915e-33cc-4272-9169-2722a7a94f6d

We recently update our mac machines on CI and python was upgraded to 3.11. This test started to fail with

File "/private/var/tmp/_bazel_buildkite/42e36ea1c1dcd25f4ab5af8d98bf3465/sandbox/darwin-sandbox/8220/execroot/_main/_tmp/9d5b13726e352fe4fa73b514c6621472/_bazel_buildkite/da87a3ce985221b3cb431edb4e3cae38/execroot/_main/bazel-out/darwin_x86_64-fastbuild/bin/a/a.runfiles/_main/a/a.py", line 1, in <module>
import b
ModuleNotFoundError: No module named 'b'

To reproduce on macOS

brew install python3
bazel test //src/test/py/bazel:py_test --test_filter=PyTest.testSmoke
@meteorcloudy meteorcloudy changed the title //src/test/py/bazel:py_test //src/test/py/bazel:py_test is broken with Python 3.11 Dec 22, 2023
@meteorcloudy
Copy link
Member Author

meteorcloudy commented Dec 22, 2023

I debugged a bit with the sys.path printed

with python 3.9 as default python on PATH

ci@bk-imacpro-11 tmpdp3x5ecv % ./bazel-bin/a/a
['/private/var/tmp/_bazel_ci/ba891f1787a15980e5a85b9711097c39/sandbox/darwin-sandbox/3558/execroot/_main/_tmp/9d5b13726e352fe4fa73b514c6621472/tests_root/tmpdp3x5ecv/a', '/private/var/tmp/_bazel_ci/ba891f1787a15980e5a85b9711097c39/sandbox/darwin-sandbox/3558/execroot/_main/_tmp/9d5b13726e352fe4fa73b514c6621472/tests_root/tmpdp3x5ecv/bazel-bin/a/a.runfiles', '/private/var/tmp/_bazel_ci/ba891f1787a15980e5a85b9711097c39/sandbox/darwin-sandbox/3558/execroot/_main/_tmp/9d5b13726e352fe4fa73b514c6621472/tests_root/tmpdp3x5ecv/bazel-bin/a/a.runfiles/_main', '/private/var/tmp/_bazel_ci/ba891f1787a15980e5a85b9711097c39/sandbox/darwin-sandbox/3558/execroot/_main/_tmp/9d5b13726e352fe4fa73b514c6621472/tests_root/tmpdp3x5ecv/bazel-bin/a/a.runfiles/bazel_tools', '/Applications/Xcode14.2.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python39.zip', '/Applications/Xcode14.2.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9', '/Applications/Xcode14.2.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/lib-dynload', '/Applications/Xcode14.2.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages']
Hello, World

with python 3.11 as default python on PATH

ci@bk-imacpro-11 tmpdp3x5ecv % ./bazel-bin/a/a
['/private/var/tmp/_bazel_ci/ba891f1787a15980e5a85b9711097c39/sandbox/darwin-sandbox/3558/execroot/_main/_tmp/9d5b13726e352fe4fa73b514c6621472/tests_root/tmpdp3x5ecv/bazel-bin/a/a.runfiles', '/private/var/tmp/_bazel_ci/ba891f1787a15980e5a85b9711097c39/sandbox/darwin-sandbox/3558/execroot/_main/_tmp/9d5b13726e352fe4fa73b514c6621472/tests_root/tmpdp3x5ecv/bazel-bin/a/a.runfiles/_main', '/private/var/tmp/_bazel_ci/ba891f1787a15980e5a85b9711097c39/sandbox/darwin-sandbox/3558/execroot/_main/_tmp/9d5b13726e352fe4fa73b514c6621472/tests_root/tmpdp3x5ecv/bazel-bin/a/a.runfiles/bazel_tools', '/usr/local/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python311.zip', '/usr/local/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11', '/usr/local/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload', '/usr/local/lib/python3.11/site-packages']
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_ci/ba891f1787a15980e5a85b9711097c39/sandbox/darwin-sandbox/3558/execroot/_main/_tmp/9d5b13726e352fe4fa73b514c6621472/tests_root/tmpdp3x5ecv/./bazel-bin/a/a.runfiles/_main/a/a.py", line 3, in <module>
    import b
ModuleNotFoundError: No module named 'b'

/private/var/tmp/_bazel_ci/ba891f1787a15980e5a85b9711097c39/sandbox/darwin-sandbox/3558/execroot/_main/_tmp/9d5b13726e352fe4fa73b514c6621472/tests_root/tmpdp3x5ecv/a is missing with python 3.11.

@meteorcloudy
Copy link
Member Author

I'm disabling this test case on macOS to make presubmit green

copybara-service bot pushed a commit that referenced this issue Dec 22, 2023
Due to #20660

RELNOTES: None
PiperOrigin-RevId: 593115090
Change-Id: Ifc2a282dbd6dd8a3abfec987398388e5844af91c
@rickeylev
Copy link
Contributor

This is probably due to PYTHONSAFEPATH being respected in python 3.11 (it isn't in earlier python versions). This is a good thing and is just exposing a non-hermetic behavior that was being relied upon.

Should be a fairly simple fix. Either the import line needs to change ("from something import x") or an imports = something setting needs to be added a py_* target somewhere

bazel-io pushed a commit to bazel-io/bazel that referenced this issue Jan 3, 2024
Due to bazelbuild#20660

RELNOTES: None
PiperOrigin-RevId: 593115090
Change-Id: Ifc2a282dbd6dd8a3abfec987398388e5844af91c
bazel-io pushed a commit to bazel-io/bazel that referenced this issue Jan 3, 2024
Due to bazelbuild#20660

RELNOTES: None
PiperOrigin-RevId: 593115090
Change-Id: Ifc2a282dbd6dd8a3abfec987398388e5844af91c
bazel-io pushed a commit to bazel-io/bazel that referenced this issue Jan 3, 2024
Due to bazelbuild#20660

RELNOTES: None
PiperOrigin-RevId: 593115090
Change-Id: Ifc2a282dbd6dd8a3abfec987398388e5844af91c
Wyverald pushed a commit that referenced this issue Jan 3, 2024
Due to #20660

RELNOTES: None
PiperOrigin-RevId: 593115090
Change-Id: Ifc2a282dbd6dd8a3abfec987398388e5844af91c
rickeylev added a commit to rickeylev/bazel that referenced this issue Jan 3, 2024
The test was failing because the `b.py` file couldn't be imported
because, starting with Python 3.11, the `PYTHONSAFEPATH` environment
variable (set by the bootstrap startup) is respected. This setting
inhibits the default Python behavior of adding the main script's
directory to sys.path.

To fix, use `py_library.imports` to explicitly add the necessary
directory to `sys.path`.

Fixes bazelbuild#20660
@rickeylev
Copy link
Contributor

Looks like a simple fix. I have #20738 going through CI.

copybara-service bot pushed a commit that referenced this issue Jan 5, 2024
*** Reason for rollback ***

Rollforward after fixing the underlying problem in 9b027c8

*** Original change description ***

Disable PyTest.testSmoke on macOS

Due to #20660

RELNOTES: None
PiperOrigin-RevId: 595998556
Change-Id: Idddf6149a918de4408a3fda016d605380a4ab6af
github-merge-queue bot pushed a commit that referenced this issue Jan 8, 2024
Due to #20660

RELNOTES: None
Commit
d9dc4fd

PiperOrigin-RevId: 593115090
Change-Id: Ifc2a282dbd6dd8a3abfec987398388e5844af91c

---------

Co-authored-by: Googler <pcloudy@google.com>
Co-authored-by: Ian (Hee) Cha <heec@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-Python Native rules for Python type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants