pip: entry_point: Add support for exit codes - #550
Conversation
d818b19 to
45ce4d0
Compare
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
45ce4d0 to
cbe7c1a
Compare
|
This seems exciting! Any updates here? |
hrfuller
left a comment
There was a problem hiding this comment.
Overall seems like a reasonable change. There is some fit and finish to do before merging.
| load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
|
||
| http_archive( | ||
| local_repository( |
There was a problem hiding this comment.
Don't commit this. The integration test runner replaces the url here with a file:// url to a tar of the current version.
There was a problem hiding this comment.
Ahh, thanks, reverted.
|
|
||
| # For pip dependencies which have entry points, the `entry_point` macro can be | ||
| # used from the generated `pip_install` repository to access a runnable binary. | ||
| # used from the generated `pip_parse` repository to access a runnable binary. |
There was a problem hiding this comment.
Dont think this should change here. This is pip_install/BUILD
| ) | ||
|
|
||
| http_archive( | ||
| local_repository( |
| ) | ||
|
|
||
| # Test the use of all pip_parse utilities in a single py_test | ||
| # Test the use of all pip_install utilities in a single py_test |
There was a problem hiding this comment.
This and the other comment changing the rule name seem wrong. Am I missing something?
| load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
|
||
| http_archive( | ||
| local_repository( |
| load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
|
||
| http_archive( | ||
| local_repository( |
| if __name__ == "__main__": | ||
| from {module} import {method} | ||
| {method}() | ||
| sys.exit({method}()) |
There was a problem hiding this comment.
I wonder how often the convention of returning a numerical exit code holds for scripts in PyPI.
There was a problem hiding this comment.
@gibfahn What I mean is that we should actually check that this is an int / or at least coercible to an int before calling sys.exit.
There was a problem hiding this comment.
Sorry, missed replying to this one. Was going to say I considered scanning pypi for packages that return an int, but there didn't seem to be a straightforward way of checking that without some fancy mypy style magic 😁
What I mean is that we should actually check that this is an int / or at least coercible to an int before calling sys.exit.
Yeah okay, let me take a look.
There was a problem hiding this comment.
So looking at other similar things, existing Python tooling does not check. I am not sure we can check without a lot of code additions.
There was a problem hiding this comment.
isn't it just is_integer as a runtime check?
>>> 1.5.is_integer()
False
>>> 1.0.is_integer()
True
>>> 1.4142135623730951.is_integer()
False
it's much better to exit 0 then to throw, if some module has a non-int main return value. And someone surely does
There was a problem hiding this comment.
Okay, added that check, please take a look.
Pip doesn't seem to do this, so I'd say chances are probably low that it's in use, but better safe than sorry.
cbe7c1a to
7284876
Compare
|
|
||
| alias( | ||
| name = "yamllint", | ||
| # If `pkg` and `script` are the same, passing a single string to |
There was a problem hiding this comment.
this is confusing, there's only one thing below.
do you mean "since pkg and script are the same"?
There was a problem hiding this comment.
Yep, this is wrong, fixed.
|
|
||
| alias( | ||
| name = "yamllint", | ||
| # If `pkg` and `script` are the same, passing a single string to |
There was a problem hiding this comment.
again, comment doesn't align with code
| if __name__ == "__main__": | ||
| from {module} import {method} | ||
| {method}() | ||
| sys.exit({method}()) |
There was a problem hiding this comment.
isn't it just is_integer as a runtime check?
>>> 1.5.is_integer()
False
>>> 1.0.is_integer()
True
>>> 1.4142135623730951.is_integer()
False
it's much better to exit 0 then to throw, if some module has a non-int main return value. And someone surely does
7284876 to
ed55f1e
Compare
hrfuller
left a comment
There was a problem hiding this comment.
Thanks for the changes. LGTM.
PR Checklist
Please check if your PR fulfills the following requirements:
.parfiles. See CONTRIBUTING.md for infoPR Type
What kind of change does this PR introduce?
What is the current behavior?
Entry point used via the
entry_pointhelper, if a function returning a int, the return int does not become the program return code.What is the new behavior?
Entry points are expected to return an int and this int is the status code.
Does this PR introduce a breaking change?
Other information
I tried looking for the code in setuptool that generates the shim but did not find it proper. The closest I found was setuptools/command/easy_install.py.
My use case is the
sphinx-buildentry point that maps to the following code:Using
pipenv installthe following shim gets generated:This does forward the error to
sys.exit. In the case of rules_python, I am not sure we need the regex bit, but I do know.Commits (oldest to newest)
bc30a71 pip: entry_point: Add support for exit codes
4a044b5 Add test for entrypoint exit codes
cbe7c1a Update tests for entrypoint exit codes