Skip to content

Commit

Permalink
defer requirement() failure until build time (ali5h#51)
Browse files Browse the repository at this point in the history
I'd like to use select() to conditionally include dependencies depending
on platform, eg a py_binary with

deps = select({
        "@bazel_tools//src/conditions:host_windows": [
            requirement("psutil"),
            requirement("pywin32"),
        ],
        "//conditions:default": [],
    })

Currently this doesn't work, as requirement() is executed on all
platforms. This patch changes requirement() to return an invalid key
instead of using fail(), which will allow such usages of select().
If the user specifies a requirement that was not listed in the
requirements file, they should still get an error at build time
which identifies the missing package.
  • Loading branch information
dae authored Nov 1, 2020
1 parent 4873874 commit 492d891
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/piptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def pip_install(pip_args=[]):
def requirement(name, target=None):
name_key = name.lower()
if name_key not in _requirements:
fail("Could not find pip-provided dependency: '%s'" % name)
return name_key + "_not_found_in_requirements"
req = _requirements[name_key]
if target != None:
pkg, _, _ = req.partition("//")
Expand Down

0 comments on commit 492d891

Please sign in to comment.