cool-easter-32542
06/29/2023, 10:12 AMpants run ... a python_requirement target, effectively running python -m ... (AIUI). Node could do something similar, via npm exec ... (aka npx).
cd $(mktemp -d)
cat > pants.toml <<EOF
[GLOBAL]
pants_version = "2.18.0.dev1"
backend_packages = [
"pants.backend.experimental.javascript",
"pants.backend.python",
]
[python]
interpreter_constraints = ["==3.10.*"]
EOF
cat > package.json <<EOF
{
"name": "test",
"version": "1.0.0",
"private": true,
"scripts": {
"run-cowsay": "cowsay"
},
"dependencies": {
"cowsay": "^1"
}
}
EOF
npm install # generate a package-lock.json
cat > BUILD <<EOF
package_json(
name="js",
scripts=[node_build_script(entry_point="run-cowsay")]
)
python_requirement(name="py-cowsay", requirements=["cowsay"])
EOF
# various forms of directly executing a third party package:
npm exec cowsay blah
pants run '//:py-cowsay' -- blah
# running a build script works well, yay
pants run '//:js#run-cowsay' -- blah
# this doesn't work:
pants run '//:js#cowsay' -- blah
#> NoApplicableTargetsException: No applicable files or targets matched. The `run` goal works with these target types:
Describe the solution you'd like
pants run path/to:some_node_third_party_package (and thus adhoc_tool target) should have close to the same behaviour as npm exec, running the package if there's an unambiguous binary to choose, or giving an error if not, with all the pants magic of cached installation etc.
See https://docs.npmjs.com/cli/v9/commands/npx?v=true:
If no --package options are provided, then npm will attempt to determine the executable name from the package specifier provided as the first positional argument according to the following heuristic:
• If the package has a single entry in its bin field in package.json, or if all entries are aliases of the same command, then that command will be used.
• If the package has multiple bin entries, and one of them matches the unscoped portion of the name field, then that command will be used.
• If this does not result in exactly one option (either because there are no bin entries, or none of them match the name of the package), then npm exec exits with an error.Describe alternatives you've considered N/A Additional context Add any other context or screenshots about the feature request here. pantsbuild/pants