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

[lit] Running lit with bazel fails for Python 3.11 #75963

Closed
fzakaria opened this issue Dec 19, 2023 · 3 comments · Fixed by #87022
Closed

[lit] Running lit with bazel fails for Python 3.11 #75963

fzakaria opened this issue Dec 19, 2023 · 3 comments · Fixed by #87022
Labels
bazel "Peripheral" support tier build system: utils/bazel llvm-lit

Comments

@fzakaria
Copy link
Contributor

fzakaria commented Dec 19, 2023

I noticed that running llvm's lit is failing for Python 3.11 but passes for Python 3.10 -- I am not sure why but I wanted to capture my investigation.

Here is a script of me running lit with bazel on Python 3.10 successfully and then switching to Python 3.11 and failing.

python -V
Python 3.11.5which python
/usr/local/google/home/fmzakari/code/github.com/openxla/stablehlo/venv3.11/bin/pythonbazel run @llvm-project//llvm:lit
INFO: Analyzed target @llvm-project//llvm:lit (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target @llvm-project//llvm:lit up-to-date:
  bazel-bin/external/llvm-project/llvm/lit
INFO: Elapsed time: 0.137s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/external/llvm-project/llvm/lit
Traceback (most recent call last):
  File "/usr/local/google/home/fmzakari/.cache/bazel/_bazel_fmzakari/17bce12c4b47a4a2fc75249afee05177/execroot/stablehlo/bazel-out/k8-fastbuild/bin/external/llvm-project/llvm/lit.runfiles/llvm-project/llvm/utils/lit/lit.py", line 3, in <module>
    from lit.main import main
ModuleNotFoundError: No module named 'lit'deactivatesource venv310/bin/activatewhich python
/usr/local/google/home/fmzakari/code/github.com/openxla/stablehlo/venv310/bin/pythonpython -V
Python 3.10.0bazel run @llvm-project//llvm:lit
INFO: Analyzed target @llvm-project//llvm:lit (1 packages loaded, 2 targets configured).
INFO: Found 1 target...
Target @llvm-project//llvm:lit up-to-date:
  bazel-bin/external/llvm-project/llvm/lit
INFO: Elapsed time: 0.186s, Critical Path: 0.01s
INFO: 2 processes: 2 internal.
INFO: Build completed successfully, 2 total actions
INFO: Running command line: bazel-bin/external/llvm-project/llvm/lit
usage: lit [-h] [--version] [-j N] [--config-prefix NAME] [-D NAME=VAL] [-q] [-s] [-v] [-vv] [-a]
           [-o PATH] [--no-progress-bar] [--show-excluded] [--show-skipped] [--show-unsupported]
           [--show-pass] [--show-flakypass] [--show-xfail] [--gtest-sharding]
           [--no-gtest-sharding] [--path PATH] [--vg] [--vg-leak] [--vg-arg ARG] [--time-tests]
           [--no-execute] [--xunit-xml-output XUNIT_XML_OUTPUT]
           [--resultdb-output RESULTDB_OUTPUT] [--time-trace-output TIME_TRACE_OUTPUT]
           [--timeout MAXINDIVIDUALTESTTIME] [--max-failures MAX_FAILURES] [--allow-empty-runs]
           [--per-test-coverage] [--ignore-fail] [--max-tests N] [--max-time N]
           [--order {lexical,random,smart}] [--shuffle] [-i] [--filter REGEX] [--filter-out REGEX]
           [--xfail LIST] [--xfail-not LIST] [--num-shards M] [--run-shard N] [--debug]
           [--show-suites] [--show-tests] [--show-used-features]
           TEST_PATH [TEST_PATH ...]
lit: error: the following arguments are required: TEST_PATH

We are using LLVM out of tree in https://github.com/openxla/stablehlo using llvm_configure starlark rule.
We are using a pretty recent commit as of this issue posting: b2cdf3c commit.

@EugeneZelenko EugeneZelenko added bazel "Peripheral" support tier build system: utils/bazel llvm-lit and removed new issue labels Dec 19, 2023
@fzakaria
Copy link
Contributor Author

I noticed lots of repositories seem to pin to Python3.10 which makes this issue hidden.

@sjain-stanford
Copy link
Member

sjain-stanford commented Jan 19, 2024

+1 we're hitting this after updating one of our dependencies which transitively uses a newer rules_python (with python 3.11 interpreter).

sjain-stanford added a commit to sjain-stanford/mlir-tcp that referenced this issue Feb 5, 2024
sjain-stanford added a commit to sjain-stanford/mlir-tcp that referenced this issue Feb 11, 2024
torch-mlir pip dep

buildifier

use python 3.10 llvm/llvm-project#75963

fix

fixes

--test_output=errors for showing errors on GHA

cleanup

minor

add py_test

fix

fix paths

fix

add python tests to test_suite

headers

enable python lit tests

buildifier

clean disk space

fix

bump actions versions

fix

fix

fix

update requirements
sjain-stanford added a commit to sjain-stanford/mlir-tcp that referenced this issue Feb 11, 2024
torch-mlir pip dep

buildifier

use python 3.10 llvm/llvm-project#75963

fix

fixes

--test_output=errors for showing errors on GHA

cleanup

minor

add py_test

fix

fix paths

fix

add python tests to test_suite

headers

enable python lit tests

buildifier

clean disk space

fix

bump actions versions

fix

fix

fix

update requirements

minor

try stablehlo without test_output

cleanup

specify shell

disk space cleanup

trial

fix

more fixes

fix

fix
fzakaria added a commit to openxla/stablehlo that referenced this issue Feb 13, 2024
Major change: Bump Bazel to the new LTS at 7.X

* Included a default Python toolchain 3.10

  There is a problem at the moment running lit using Python311 where it
  cannot find the module.

  Our CI system already enforces Python310 to get around it but we should
  set the toolchain in Bazel itself to avoid this problem.
  I had already filed llvm/llvm-project#75963

* I moved skylib to MODULE.bazel to test the MODULE portion of Bazel is
working. A remaining action item is to move LLVM itself to MODULE.bazel
which would preclude needing to define skylib since its a dependency of
LLVM.

* Workspace names are no longer named in Bazel 7+
  
  I had to change stablehlo to _main to fix the runfiles directory.
  Please see bazelbuild/bazel#18128

We should consider using
https://github.com/bazelbuild/rules_python/blob/main/python/runfiles/runfiles.py#L262
instead to get the runfiles directory for future proofing.

Fixes #1878

---------

Co-authored-by: mlevesquedion <mlevesquedion@google.com>
@keith
Copy link
Member

keith commented Mar 29, 2024

#87022

keith added a commit that referenced this issue Mar 29, 2024
In python3.11 there is a new environment variable PYTHONSAFEPATH which
stops python from setting the current directory as the first entry in
sys.path. Bazel started setting this to ensure that python targets
don't accidentally access things that aren't in their dependency tree.
This resulted in lit tests breaking because sys.path didn't include the
directory to the lit source files. This is fixed by adding the lit
binary to the dependency tree and propagating the import path from it.

Fixes #75963
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bazel "Peripheral" support tier build system: utils/bazel llvm-lit
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants