-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Provide configuration options and saner defaults for shell kind to be used #15
Comments
I don't know much about windows dev environments, so I made a best guess about how to get POSIX shell scripts to work seamlessly on windows with a bit of trial and error, but not very exhaustive testing, and I may have missed something obvious. The intention of the shell task type is POSIX shell scripts, so the canonical implementation is to pipe the content into a bash process. Therefore the strategy is to try find a bash executable to use by looking on the PATH, looking for git bash, or finally looking for WSL. It's all in this file: https://github.com/nat-n/poethepoet/blob/master/poethepoet/task/shell.py#L47 @JosXa What would you suggest doing differently? |
Ah yes, that sounds perfect and actually looks like you've given it a lot of thought. I can also confirm that it works out of the box when WSL is installed. So then I'd argue we need an additional way to specify which shell we'd like to run on? The |
So one workaround I found was the following: testps = {shell = "pwsh.exe -ExecutionPolicy Bypass -Command \"cd .. && ls\""} And works a little better with multiline strings: update = { shell = """
pwsh.exe -ExecutionPolicy Bypass -Command "
cd ../tgtypes && poetry update
cd ../autogram-commons && poetry update
cd ../botkit && poetry update
poetry update
"
"""}
envinfo = { shell = """
pwsh.exe -ExecutionPolicy Bypass -Command "
cd ../tgtypes && poetry env info -p &&
cd ../autogram-commons && poetry env info -p &&
cd ../botkit && poetry env info -p &&
poetry env info -p
"
""" }
No idea who's now running that or how it does it, but it works 😆 Would still be nice to have high-level control and some more insight into what exactly is running my command here. |
I've considered making it possible to specify the default shell as an option, either globally or per task, but I'm not sure if this is better or potentially worse for the goal of tasks being universal/portable by default. Of course this goal is only sort of achievable in the first place, but adding support for users to choose a shell that might be less universal than bash is possibly a step backwards. On that note, it may be relevant to your use case that if the
My windows knowledge is weak, so I'm not sure what to make of this. The I'm glad you found a workaround, would explicitly calling pwsh.exe like that work from a cmd task instead of shell? It might be more performant. If what you want is to write powershell specific tasks (i.e. that will never run on linux) then it would be trivial to create a new task type for this, which I hope to make well supported at some point #13
What would you suggest for this? I've thought a bit about describing more about the task/execution when the global |
Hmm, wouldn't the safest, most reproducible way be to specify a custom shell command that actually points into a docker container?
I do not necessarily, mainly I appreciate having the freedom to choose. And I may have to correct you on that statement, the versions 7.+ of Powershell Core are named that way because they are based on the .NET Core runtime (which is superbly linux friendly), meaning that more and more linux devs are starting to pick it up aswell. I do like the Windows "cmd.exe" is the old, built-in default terminal that's mainly used as a task runner by people, but rarely for scripting. Afaik A zsh or fish user might wanna run in the WSL, or some people may even try to play around with open ssh connections or whatever... Point is: The different types are cool, but there just needs to be some config for that, or the ability to run from current shell, IMO :) |
Oh, and they added aliases to pwsh so basically I'm typing bash commands all the time and it just works the same |
Would it be clearer if the It doesn't help that a |
That brings up an interesting idea, perhaps, to detect whether the containing process is I.e. if you want The following snippet detects the grandfather process (parent is python.exe): import psutil
print(psutil.Process().parent().parent().exe()) Returns either of:
It solves the problem of figuring out where the shell is located, and ensures that the shell actually exists / works, because poe is being run from it. Also, Windows users who also use bash, will probably run |
For detecting the shell, Poetry itself, and pipenv, use That said, I'm not fond of this idea, as it's very unlikely |
@JosXa @boukeversteegh @TBBle Thanks for the input.
As an aside: since unlike I would need some help from a windows native developer to implement the appropriate windows shell support. |
Yes, you are right, just blindly running the commands in whatever shell is active is not a good idea. But combined with your idea of a compatibility list (with global default) could perhaps make it work smoothly. Suppose:
User then tries to run in the wrong shell, and then corrects it. C:\project> poe run foo
[poe] error: you cannot run task [foo] in [command.exe]. Please execute this script from: bash / zsh / sh.
C:\project> wsl.exe
Welcome to Ubuntu!
/c/project $ echo $SHELL
/bin/bash # proving that we are running bash now
/c/project $ poe run foo
[poe] task foo completed This approach could make the following challenges easier to deal with:
|
I'm not sure it's a delightful workflow to make the I'd suggest that apart from So perhaps separately from anything else, blacklisting As another example of a shell task, to motivate my current thinking that the [tool.poe.tasks."print-python-ver"]
shells={'python'}
shell="""
import sys
print(sys.version)
""" |
I'm inclined to agree with this. Though maybe using the user's current shell as a hint when it's time to go hunting is a good idea.
Could expand upon your thinking here? Do you mean to say that the current fallback to invoking wsl bash makes no sense unless the user is already in wsl bash? I've so far resisted the temptation to support inline python scripts because writing python programs inside toml doesn't seem like a good practice to encourage. Though the way you put it there as equivalent to a shebang is interesting. |
Yeah, I think if the user is in WSL bash already, they're in a POSIX isolated environment, and will have real bash in their PATH, and it'll all work fine. They're not really working in Windows, so all this becomes academic. If they're not in WSL, it seems improbable to me that executing WSL Bash would actually come up with the same functional environment, in terms of "Things available in the path", that other Windows-based Bash environments provide. For example, despite using the So the only way WSL bash makes sense is if Both Git Bash and MSYS2 Bash seem to remain functional when launched from a So if the users seeing this have a mix of Git/MSYS2 Bash available and not-available, some are going to be in the expected state, and some are going to be effectively working from within a unitialised environment, so non-trivial bash scripts are going to be surprisingly broken, I expect. |
It only took a year to get around to picking this up again (that's side projects for you), but I've implemented something that I hope works for everyone. With the change in PR you can configure a single shell (by name) or an ordered list of shells to try, either per task by specifying the Note that there are a couple of significant limitations with the powershell integration that I don't know how to solve. Firstly when powershell starts it always prints some copyright boilerplate which is not really desirable for this use case, and secondly it doesn't propagate environment variables from the parent process which is quite a limitation (e.g. named args won't work). Suggestions are welcome from anyone more knowledgable about powershell. Please have a look at the PR, I'll leave it open for a little while in case there's some feedback, but of course it's worth pointing out potential issues even after it's merged. |
A fix for this issue has just been released as 0.12.0 |
Original issue title: Poe tries to enforce WSL on Windows 10
When running a poe
shell
-type task in Windows Powershell Core 7.0.3, it seems to attempt execution of the command inside the Windows Subsystem for Linux (WSL), but I am happy using the cross-platform Powershell for most use cases.Using the following configuration:
It complains that the WSL is not installed:
The text was updated successfully, but these errors were encountered: