Skip to content

requirements_test always pass if pip-compile fails to resolve dependency #478

@reiyw

Description

@reiyw

🐞 bug report

Affected Rule

The issue is caused by the rule: compile_pip_requirements

Is this a regression?

No.

Description

compile_pip_requirements produces a test target for checking pip-compile. This test generates a lock file from given requirements_in, and fails if the content is different from the original requirements_txt. However, if pip-compile fails to resolve the dependency, the test passes regardless of the contents of requirements_txt.

The cause of this issue is in: https://github.com/bazelbuild/rules_python/blob/c6970fc44877dbbbce84d17845d9bc797aefe299/python/pip_install/pip_compile.py#L70-L89
pip-compile exits with code 2 when it fails to resolve the dependency. However, the error code is not checked, and here the contents of requirements_txt and requirements_out are identical (copied immediately before and not updated by pip-compile), so the test passes.

I'm ready to send a PR to fix this issue, if relevant.

🔬 Minimal Reproduction

Example Project

WORKSPACE

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# HEAD commit as of 2021-06-01.
RULES_PYTHON_COMMIT = "c6970fc44877dbbbce84d17845d9bc797aefe299"
RULES_PYTHON_DIGEST = "c43edeb59c6cb009f23f8e5603ce8fa1ca25a9084aae54513c82acfff06c3aaa"

http_archive(
    name = "rules_python",
    urls = [
        "https://github.com/bazelbuild/rules_python/archive/" + RULES_PYTHON_COMMIT + ".tar.gz",
    ],
    sha256 = RULES_PYTHON_DIGEST,
    strip_prefix = "rules_python-" + RULES_PYTHON_COMMIT,
)

load("@rules_python//python:pip.bzl", "pip_parse")
pip_parse(
    name = "my_deps",
    requirements_lock = "//:requirements.txt",
)

load("@my_deps//:requirements.bzl", "install_deps")
install_deps()

BUILD

load("@rules_python//python/pip_install:requirements.bzl", "compile_pip_requirements")

compile_pip_requirements(
    name = "requirements",
    extra_args = [
        "--quiet",
    ],
)

requirements.in

grpcio==1.38.0
# tensorflow 2.5.0 requires grpcio~=1.34.0, which is incompatible
tensorflow==2.5.0

requirements.txt

foo

Command

$ bazel test //:requirements_test

🔥 Exception or Error

INFO: Analyzed target //:requirements_test (9 packages loaded, 228 targets configured).
INFO: Found 1 test target...
Target //:requirements_test up-to-date:
  bazel-bin/requirements_test
INFO: Elapsed time: 5.532s, Critical Path: 4.88s
INFO: 2 processes: 2 processwrapper-sandbox.
INFO: Build completed successfully, 2 total actions
//:requirements_test                                                     PASSED in 4.8s

INFO: Build completed successfully, 2 total actions

🌍 Your Environment

Operating System:

  
Debian GNU/Linux 10 (buster)
  

Output of bazel version:

  
4.1.0
  

Rules_python version:

  
c6970fc44877dbbbce84d17845d9bc797aefe299
  

Anything else relevant?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions