-
-
Notifications
You must be signed in to change notification settings - Fork 615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for the pex --executable
argument
#20497
Conversation
@@ -213,6 +213,52 @@ def test_local_dist() -> None: | |||
assert result.stdout == "LOCAL DIST\n" | |||
|
|||
|
|||
def test_local_dist_with_executable_main() -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a copy of test_local_dist
, but using an executable main instead of an entry point.
--executable
argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG! Just a few nits...
@@ -67,7 +69,7 @@ async def _create_python_source_run_request( | |||
include_source_files=False, | |||
include_local_dists=True, | |||
# `PEX_EXTRA_SYS_PATH` should contain this entry_point's module. | |||
main=console_script or entry_point.val, | |||
main=executable or console_script or entry_point.val, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the different precedence here than above? Only one should be set, so it may not matter in practice, but it's good to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function always gets an entry_point, whereas the others can be None. So we check the Nones first.
Oddly enough, nothing in pants actually passes a ConsoleScript to this function. This PR adds a heuristic that might pass an Executable.
So, would you prefer:
main=executable or console_script or entry_point.val, | |
main=console_script or executable or entry_point.val, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's fine the way it is, it just scans oddly.
@@ -141,7 +143,7 @@ async def package_pex_binary( | |||
request = PexFromTargetsRequest( | |||
addresses=[field_set.address], | |||
internal_only=False, | |||
main=resolved_entry_point.val or field_set.script.value, | |||
main=resolved_entry_point.val or field_set.script.value or field_set.executable.value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re my question on precedence, does this always get an entry point? Can its .val
be None? How is this case different than the one below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, yes, as this is the general purpose case and can be anything.
In the other file, it is a utility function only used for the run goal, so it always has an entry point.
Co-authored-by: Benjy Weinberger <benjyw@gmail.com>
if not all(part.isidentifier() for part in source_name.split(".")): | ||
# If the python source is not importable (python modules can't be named with '-'), | ||
# then it must be an executable script. | ||
executable = Executable(self.source.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. self.source.value
is relative to the BUILD file, but Executable needs to be relative to the workspace root, similar to the logic in PexExecutableField
.
executable = Executable(os.path.join(self.address.spec_path, self.source.value).lstrip(os.path.sep))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The integration tests are only testing running a pex_binary
, not python_source
.
So, we need to add another parameter to this test to use app.py
or my-app.py
so it uses the Executable main:
https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/python/goals/run_python_source_integration_test.py#L114-L137
This fixes the feature added in #20497 as it broke using `pants run` on a python_source if the file name has `-` or other invalid characters. Bug reported here: https://pantsbuild.slack.com/archives/C046T6T9U/p1717624913138789?thread_ts=1717624913.138789&cid=C046T6T9U The other integration test for the pex --executable feature only tested running pex_binary, not python_source. So, I missed applying some of the path logic to both cases.
This fixes the feature added in #20497 as it broke using `pants run` on a python_source if the file name has `-` or other invalid characters. Bug reported here: https://pantsbuild.slack.com/archives/C046T6T9U/p1717624913138789?thread_ts=1717624913.138789&cid=C046T6T9U The other integration test for the pex --executable feature only tested running pex_binary, not python_source. So, I missed applying some of the path logic to both cases.
This fixes the feature added in #20497 as it broke using `pants run` on a python_source if the file name has `-` or other invalid characters. Bug reported here: https://pantsbuild.slack.com/archives/C046T6T9U/p1717624913138789?thread_ts=1717624913.138789&cid=C046T6T9U The other integration test for the pex --executable feature only tested running pex_binary, not python_source. So, I missed applying some of the path logic to both cases.
This fixes the feature added in #20497 as it broke using `pants run` on a python_source if the file name has `-` or other invalid characters. Bug reported here: https://pantsbuild.slack.com/archives/C046T6T9U/p1717624913138789?thread_ts=1717624913.138789&cid=C046T6T9U The other integration test for the pex --executable feature only tested running pex_binary, not python_source. So, I missed applying some of the path logic to both cases.
This fixes the feature added in #20497 as it broke using `pants run` on a python_source if the file name has `-` or other invalid characters. Bug reported here: https://pantsbuild.slack.com/archives/C046T6T9U/p1717624913138789?thread_ts=1717624913.138789&cid=C046T6T9U The other integration test for the pex --executable feature only tested running pex_binary, not python_source. So, I missed applying some of the path logic to both cases.
…) (#21084) This fixes the feature added in #20497 as it broke using `pants run` on a python_source if the file name has `-` or other invalid characters. Bug reported here: https://pantsbuild.slack.com/archives/C046T6T9U/p1717624913138789?thread_ts=1717624913.138789&cid=C046T6T9U The other integration test for the pex --executable feature only tested running pex_binary, not python_source. So, I missed applying some of the path logic to both cases.
…) (#21085) This fixes the feature added in #20497 as it broke using `pants run` on a python_source if the file name has `-` or other invalid characters. Bug reported here: https://pantsbuild.slack.com/archives/C046T6T9U/p1717624913138789?thread_ts=1717624913.138789&cid=C046T6T9U The other integration test for the pex --executable feature only tested running pex_binary, not python_source. So, I missed applying some of the path logic to both cases.
…) (#21086) This fixes the feature added in #20497 as it broke using `pants run` on a python_source if the file name has `-` or other invalid characters. Bug reported here: https://pantsbuild.slack.com/archives/C046T6T9U/p1717624913138789?thread_ts=1717624913.138789&cid=C046T6T9U The other integration test for the pex --executable feature only tested running pex_binary, not python_source. So, I missed applying some of the path logic to both cases.
This PR adds support for
pex --executable <path to script>
added in pex 2.1.93:pex-tool/pex#1807
With this change, users should be able to do
pants run bin/my-python-script.py
.Closes #18290