Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/6197.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update shell detection to only check the end of the command used.
18 changes: 9 additions & 9 deletions pipenv/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ def _get_activate_script(cmd, venv):
This is POSIX-only at the moment since the compat (pexpect-based) shell
does not work elsewhere anyway.
"""
# Suffix and source command for other shells.
# Support for fish shell.
if "fish" in cmd:
# Suffix and source command for various shells.
if cmd.endswith("/sh", "/bash", "/zsh"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work on older python versions -- I am raising a PR:

matteius@matteius-VirtualBox:~/opensensor-api$ pipenv shell
Loading .env environment variables...
Launching subshell in virtual environment...
bash
Traceback (most recent call last):
  File "/home/matteius/.local/bin/pipenv", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/matteius/pipenv/pipenv/vendor/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matteius/pipenv/pipenv/cli/options.py", line 52, in main
    return super().main(*args, **kwargs, windows_expand_args=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matteius/pipenv/pipenv/vendor/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/matteius/pipenv/pipenv/vendor/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matteius/pipenv/pipenv/vendor/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matteius/pipenv/pipenv/vendor/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matteius/pipenv/pipenv/vendor/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matteius/pipenv/pipenv/vendor/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matteius/pipenv/pipenv/cli/command.py", line 400, in shell
    do_shell(
  File "/home/matteius/pipenv/pipenv/routines/shell.py", line 48, in do_shell
    shell.fork_compat(*fork_args)
  File "/home/matteius/pipenv/pipenv/shells.py", line 111, in fork_compat
    c.sendline(_get_activate_script(self.cmd, venv))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matteius/pipenv/pipenv/shells.py", line 40, in _get_activate_script
    if cmd.endswith("/sh", "/bash", "/zsh"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: slice indices must be integers or None or have an __index__ method

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there are other issues with this change -- I recommend reverting it -- for example, my cmd is just "bash" not "/bash" so fixing that yields:

ValueError: unknown shell bash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #6230 fixing this.

suffix = ""
command = "."
elif cmd.endswith("/fish"):
suffix = ".fish"
command = "source"
# Support for csh shell.
elif "csh" in cmd:
elif cmd.endswith("/csh"):
suffix = ".csh"
command = "source"
elif "xonsh" in cmd:
elif cmd.endswith("/xonsh"):
suffix = ".xsh"
command = "source"
elif "nu" in cmd:
elif cmd.endswith("/nu"):
suffix = ".nu"
command = "overlay use"
else:
suffix = ""
command = "."
raise ValueError(f"unknown shell {cmd}")
# Escape any special characters located within the virtualenv path to allow
# for proper activation.
venv_location = re.sub(r"([ &$()\[\]])", r"\\\1", str(venv))
Expand Down