thefuck icon indicating copy to clipboard operation
thefuck copied to clipboard

psutil: platform cygwin is not supported (thefuck won't install on Cygwin)

Open WillemMali opened this issue 9 years ago • 3 comments

Hi, I'm on Cygwin trying to install thefuck, but I get the following output when running pip install thefuck:

[project (master)] pip install thefuck
You are using pip version 6.1.1, however version 8.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting thefuck
  Using cached thefuck-3.3-py2.py3-none-any.whl
Collecting psutil (from thefuck)
  Using cached psutil-4.0.0.tar.gz
    Complete output from command python setup.py egg_info:
    platform cygwin is not supported

Do you have any idea how I could fix this? I'm willing to work on this myself but I'm not sure where I should start. Any help would be greatly appreciated.

EDIT: I also tried installing it using pip3 but it gave the same error. Any have experience on getting thefuck running on the latest 64-bits Cygwin?

WillemMali avatar Mar 02 '16 09:03 WillemMali

You have two options, use thefuck from a native Windows installation, or tweak it to not need psutil.

For the first option, install Python to Windows directly, install thefuck through that Python, and call that installation from Cygwin. So instead of eval "$(thefuck --alias)" in your startup script, you'll need to skip the eval and make the alias directly like this:

alias fuck='TF_CMD=$(TF_ALIAS=fuck PYTHONIOENCODING=utf-8 TF_SHELL_ALIASES=$(alias) /cygdrive/c/Users/`whoami`/AppData/Local/Programs/Python/Python35-32/Scripts/thefuck.exe $(fc -ln -1)) && eval $TF_CMD && history -s $TF_CMD'

Which works for me on Windows 10.

Howeber, if you don't want to install Python to Windows, then you have to deal with the fact that psutil doesn't support Cygwin. So, you'd have to remove the need for psutil. It only seems to be used in a few calls. I'm currently tossing together a quick, kinda hacky version of thefuck that will run on Cygwin, but I wouldn't consider it reliable.

from __init__.py, in line 6 we have the import:

from psutil import Process

and line 23 is the only use of that command:

proc = Process(os.getpid())

proc is then uses for proc.name(), proc.name, proc.parent(), and proc.parent. This is all in the _get_shell() function. Find a different way to reliably get the shell, and you that should be taken care of.

from types.py we have the import on line 6:

from psutil import Process, TimeoutExpired

on line 74 is the use of Process:

proc = Process(popen.pid)

and on line 78 is TimeoutExpired

except TimeoutExpired

This one seems a bit more involved than the previous use. It calls proc.wait(settings.wait_command), proc.children(recursive=True), and proc.kill(). This is all in _wait_output, which kills the command if it takes too long (which is where TimeoutExpired) comes in.

If you feel like tackling all that, you'll probably want to dig through the psutil documentation to figure out how best to emulate their commands.

SnoringFrog avatar Jul 12 '16 14:07 SnoringFrog

If you check out my fork, you'll find my hacked-together version that runs on Cygwin. It won't work outside of a Linux environment, and ignores the checks for command timeouts, so using the original is likely a better option, but it's there if you want a Cygwin-only install.

SnoringFrog avatar Jul 12 '16 16:07 SnoringFrog

For the first option, install Python to Windows directly, install thefuck through that Python, and call that installation from Cygwin. So instead of eval "$(thefuck --alias)" in your startup script, you'll need to skip the eval and make the alias directly like this:

alias fuck='TF_CMD=$(TF_ALIAS=fuck PYTHONIOENCODING=utf-8 TF_SHELL_ALIASES=$(alias) /cygdrive/c/Users/`whoami`/AppData/Local/Programs/Python/Python35-32/Scripts/thefuck.exe $(fc -ln -1)) && eval $TF_CMD && history -s $TF_CMD'

This alias doesn't work for me anymore:

alias fuck="TF_CMD=$(TF_ALIAS=fuck PYTHONIOENCODING=utf-8 TF_SHELL_ALIASES=$(alias) '/c/Program Files/Python311/Scripts/thefuck.exe' $(fc -ln -1)) && eval $TF_CMD && history -s $TF_CMD"

gives the error:

/home/xxxxx/.zshrc:fc:145: no such event: 0
usage: thefuck [-v] [-a [ALIAS]] [-l SHELL_LOGGER]
               [--enable-experimental-instant-mode] [-h] [-y | -r] [-d]
               [command ...]

atri-dastidar-snkeos avatar Dec 08 '22 09:12 atri-dastidar-snkeos