1load("@bazel_skylib//rules:run_binary.bzl", "run_binary") 2load("@rules_python//python:defs.bzl", "py_test") 3 4# Below are targets for testing the `py_console_script_binary` feature and are 5# not part of the example how to use the feature. 6 7# And a test that we can correctly run `pylint --version` 8py_test( 9 name = "pylint_test", 10 srcs = ["pylint_test.py"], 11 data = ["//entry_points:pylint"], 12 env = { 13 "ENTRY_POINT": "$(rlocationpath //entry_points:pylint)", 14 }, 15 deps = ["@rules_python//python/runfiles"], 16) 17 18# Next run pylint on the file to generate a report. 19run_binary( 20 name = "pylint_report", 21 srcs = [ 22 ":file_with_pylint_errors.py", 23 ], 24 outs = ["pylint_report.txt"], 25 args = [ 26 "--output-format=text:$(location pylint_report.txt)", 27 "--load-plugins=pylint_print", 28 # The `exit-zero` ensures that `run_binary` is successful even though there are lint errors. 29 # We check the generated report in the test below. 30 "--exit-zero", 31 "$(location :file_with_pylint_errors.py)", 32 ], 33 env = { 34 # otherwise it may try to create ${HOME}/.cache/pylint 35 "PYLINTHOME": "./.pylint_home", 36 }, 37 tool = "//entry_points:pylint_with_deps", 38) 39 40py_test( 41 name = "pylint_deps_test", 42 srcs = ["pylint_deps_test.py"], 43 data = [ 44 ":pylint_report", 45 "//entry_points:pylint_with_deps", 46 ], 47 env = { 48 "ENTRY_POINT": "$(rlocationpath //entry_points:pylint_with_deps)", 49 "PYLINT_REPORT": "$(rlocationpath :pylint_report)", 50 }, 51 deps = ["@rules_python//python/runfiles"], 52) 53 54# And a test to check that yamllint works 55py_test( 56 name = "yamllint_test", 57 srcs = ["yamllint_test.py"], 58 data = ["//entry_points:yamllint"], 59 env = { 60 "ENTRY_POINT": "$(rlocationpath //entry_points:yamllint)", 61 }, 62 deps = ["@rules_python//python/runfiles"], 63) 64