-
Notifications
You must be signed in to change notification settings - Fork 1
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
Run shell functions #46
Open
j4mie
wants to merge
5
commits into
master
Choose a base branch
from
run-shell-functions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9c0c076
Detect and run shell functions
j4mie a94a5c0
Bail from main function early on execvpe calls
j4mie b96b0b3
Make router tests pass if crab processes are running on the machine
j4mie 1a4a8ff
Check return code is not zero rather than a specific error code
j4mie 4852b16
Change order of checks so functions override binaries
j4mie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
from crab import router, __version__ | ||
import shlex | ||
import socket | ||
import subprocess | ||
import sys | ||
from dotenv import dotenv_values | ||
import shutil | ||
|
@@ -78,12 +79,20 @@ def main(command=None): | |
port = env.setdefault("PORT", get_free_port()) | ||
command = [item.replace("$PORT", port) for item in command] | ||
|
||
if shutil.which(command[0], path=env["PATH"]) is None: | ||
print('Could not find "{}" in your procfile or $PATH.'.format(command[0])) | ||
exit(1) | ||
# Is it a shell function? | ||
if ( | ||
subprocess.run( | ||
["declare", "-f", command[0]], shell=True, stdout=subprocess.DEVNULL | ||
).returncode | ||
== 0 | ||
): | ||
return os.execvpe(env["SHELL"], [env["SHELL"], "-ci"] + command, env) | ||
|
||
if shutil.which(command[0], path=env["PATH"]) is not None: | ||
return os.execvpe(command[0], command, env) | ||
|
||
# off we go | ||
os.execvpe(command[0], command, env) | ||
print('Could not find "{}" in your procfile or $PATH.'.format(command[0])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth mentioning here about it also not being a shell function? Although that would be quite a long message. Shells just do "command not found". |
||
exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think we should follow the semantics of shell functions in that they override items in the
$PATH
, rather than only being called if they don't exist.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.
Ah right, so swap the two checks?
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.
Indeed