Skip to content
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

Solaris failures from pipenv #25

Open
philkav opened this issue Sep 9, 2019 · 5 comments
Open

Solaris failures from pipenv #25

philkav opened this issue Sep 9, 2019 · 5 comments

Comments

@philkav
Copy link

philkav commented Sep 9, 2019

Hi, I've hit an issue on Solaris 11.4 when trying to invoke a shell using pipenv version 2018.11.26 (python3.7)

Similar to:
detect_shell fails on IBM i / AIX #21

The messages I would see were like so:

host# pipenv shell
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 6, in <module>
    from pipenv import cli
  File "/usr/local/lib/python3.7/site-packages/pipenv/__init__.py", line 47, in <module>
    from .cli import cli
  File "/usr/local/lib/python3.7/site-packages/pipenv/cli/__init__.py", line 3, in <module>
    from .command import cli
  File "/usr/local/lib/python3.7/site-packages/pipenv/cli/command.py", line 7, in <module>
    import crayons
  File "/usr/local/lib/python3.7/site-packages/pipenv/patched/crayons.py", line 49, in <module>
    is_powershell = "powershell" in shellingham.detect_shell()[0]
  File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/shellingham/__init__.py", line 22, in detect_shell
    shell = get_shell(pid, max_depth=max_depth)
  File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/shellingham/posix/__init__.py", line 54, in get_shell
    mapping = _get_process_mapping()
  File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/shellingham/posix/__init__.py", line 15, in _get_process_mapping
    mapping = impl.get_process_mapping()
  File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/shellingham/posix/proc.py", line 64, in get_process_mapping
    tty, ppid = _get_stat(pid, stat_name)
  File "/usr/local/lib/python3.7/site-packages/pipenv/vendor/shellingham/posix/proc.py", line 36, in _get_stat
    return parts[STAT_TTY], parts[STAT_PPID]
IndexError: list index out of range

The real issue here is that when shellingham tries to split the data it reads from /proc/PID/status, it fails, because the formatting is not as it expected.

In order to get around this, I modified posix/proc.py like so:

--- proc.py     Mon Sep  9 17:31:45 2019
+++ /usr/local/lib/python3.7/site-packages/pipenv/vendor/shellingham/posix/proc.py      Mon Sep  9 17:25:12 2019
@@ -4,6 +4,7 @@
 import sys
 
 from ._core import Process
+from .._core import ShellDetectionFailure
 
 
 STAT_PPID = 3
@@ -33,7 +34,10 @@
     with io.open(path, encoding='ascii', errors='replace') as f:
         # We only care about TTY and PPID -- all numbers.
         parts = STAT_PATTERN.findall(f.read())
-        return parts[STAT_TTY], parts[STAT_PPID]
+        try:
+            return parts[STAT_TTY], parts[STAT_PPID]
+        except IndexError:
+            raise ShellDetectionFailure
 

This solved the failures on my end.

Perhaps this is already fixed by 'Switch to parse 'ps wwl' for better compatibility #23'.
I can test this if necessary.

@uranusjr
Copy link
Member

uranusjr commented Sep 9, 2019

Is there documentation what format Solaris uses for its proc? And more importantly, why is it in a different format? Is it following a different spec?

@philkav
Copy link
Author

philkav commented Sep 11, 2019

Yes, the documentation for the format of proc(4) can be found here:
https://docs.oracle.com/cd/E19455-01/816-3327/6m9k7qvih/index.html#psinfo

It appears that /proc/pid/psinfo would be the right place to get the tty and ppid.

I've seen an implementation of this in python here:
https://github.com/oracle/solaris-ips/blob/master/src/modules/misc.py#L813

I'm not sure about the reasoning for the formatting/spec

@philkav
Copy link
Author

philkav commented Sep 11, 2019

Might be easier to get this info from 'ps'

@anilj
Copy link

anilj commented Nov 6, 2019

I just ran into this too on SmartOS (Solaris...). I guess pipenv is a NOOP for me now because of this unless I do that hack above.

@uranusjr
Copy link
Member

@anilj If Pipenv is your main concern Id suggest filing a PR to catch this error at the call site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants