-
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
Add support for the (prefix) shell #9
base: main
Are you sure you want to change the base?
Changes from all commits
2a730c4
aaef7db
3a6d384
f768060
2b7a264
ee83339
ec9f986
8b96476
f058762
5352a07
3ea6774
8789c31
0cd06d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -164,6 +164,41 @@ def executable(self): | |||||
return "zsh" | ||||||
|
||||||
|
||||||
class ShellShell(PosixShell): | ||||||
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. I think we should rename this to avoid confusion:
Suggested change
|
||||||
Activator = activate.ShellActivator | ||||||
|
||||||
def executable(self): | ||||||
return "shell" | ||||||
|
||||||
def args(self): | ||||||
return ("--interact", "--norc") | ||||||
|
||||||
def spawn_popen( | ||||||
self, command: Iterable[str] | None = None, **kwargs | ||||||
certik marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
) -> subprocess.Popen: | ||||||
try: | ||||||
with NamedTemporaryFile( | ||||||
prefix="conda-spawn-", | ||||||
suffix=self.Activator.script_extension, | ||||||
delete=False, | ||||||
mode="w", | ||||||
) as f: | ||||||
f.write(self.script()) | ||||||
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. Don't you need a newline here too? 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. I assumed |
||||||
f.write(f"{self.prompt()}\n") | ||||||
if command: | ||||||
f.write(" ".join(command)) | ||||||
return subprocess.Popen( | ||||||
[self.executable(), *self.args(), f.name], env=self.env(), **kwargs | ||||||
) | ||||||
finally: | ||||||
self._files_to_remove.append(f.name) | ||||||
|
||||||
def spawn(self, command: Iterable[str] | None = None) -> int: | ||||||
proc = self.spawn_popen(command) | ||||||
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. Can't we use the tty in Unix systems? 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. We probably can. I wanted to keep the code uniform to work on all platforms. Do you want to have different code for Windows and Unix? 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. Ttys are needed for PS1 support I'm afraid. 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. I was using the example from PowerShell. Do ttys work on Windows? 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. Regarding the
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. 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. In some shells, the PS1 variable is not ever exported, only local to the current session. So a process like But if Prefix's 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. Currently we are not exporting |
||||||
proc.communicate() | ||||||
return proc.wait() | ||||||
|
||||||
|
||||||
class CshShell(Shell): | ||||||
pass | ||||||
|
||||||
|
@@ -260,6 +295,7 @@ def args(self) -> tuple[str, ...]: | |||||
"posix": PosixShell, | ||||||
"powershell": PowershellShell, | ||||||
"pwsh": PowershellShell, | ||||||
"shell": ShellShell, | ||||||
"tcsh": CshShell, | ||||||
"xonsh": XonshShell, | ||||||
"zsh": ZshShell, | ||||||
|
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 surprising 🤔 Isn't shell supposed to be cross-platform? Why do they need different separators 🤔 Just curious.
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 actually at the core of the issue of being cross platform. On Windows the
$PATH
environment variable contains;
, on Linux and macOS it contains:
as a separator. Consequently, there are two ways to deal with this: we either emulate a more posix like environment (posix requires:
) from inside the script, but we must revert back to $PATH with;
for any programs that we call from the script, otherwise they won't work, since on Windows programs expect;
as a separator (that is for example whatXonsh
orgit-bash
is doing); or you keep things native, you don't emulate anything. And that is what theshell
is doing.This is related to an issue of absolute paths: posix doesn't allow paths like
C:\something
, each absolute path must start with/
. Again, one has two options, emulating paths and translating them for programs (git-bash
) or using native paths (shell
).In order to write cross-platform scripts, one must either user relative paths, or use some platform-independent mechanism to append to
$PATH
.