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

subprocess.run does not work inside side_effect #1411

Open
tnyeanderson opened this issue Nov 2, 2023 · 0 comments
Open

subprocess.run does not work inside side_effect #1411

tnyeanderson opened this issue Nov 2, 2023 · 0 comments

Comments

@tnyeanderson
Copy link

For some reason, using subprocess.run() inside of a side_effect function doesn't seem to work. Take the following, which demonstrates the expected behavior:

$ cat /tmp/subprocess_raw.py
import subprocess
print(subprocess.__file__)
subprocess.run(["which", "free"])

$ python3 /tmp/subprocess_raw.py
/usr/lib/python3.11/subprocess.py
/usr/bin/free

When the same subprocess.run(["which", "free"]) call is made from inside a side_effect function, the free command is somehow executed instead of which free!

The output of thefuck --version (something like The Fuck 3.1 using Python 3.5.0 and Bash 4.4.12(1)-release):

The Fuck 3.32 using Python 3.11.4 and Bash 5.2.15(1)-release

Your system (Debian 7, ArchLinux, Windows, etc.):

Ubuntu 23.04

How to reproduce the bug:

Create ~/.config/thefuck/rules/subprocess_test.py, which is a very simple rule which basically tries to run which free as a side effect:

import subprocess
from thefuck import logs

priority = 0
requires_output = True
enabled_by_default = True

def match(command):
    return True

def get_new_command(command):
    return 'echo "--- running subprocess check --"'

def side_effect(command, fixed_command):
    logs.debug(subprocess.__file__)
    subprocess.run(["which", "free"])

Reload thefuck (open a new shell) and run fuck until the rule is tried and applied. You get the (erroneous) output seen below.

The output of The Fuck with THEFUCK_DEBUG=true exported (typically execute export THEFUCK_DEBUG=true in your shell before The Fuck):

...
DEBUG: Trying rule: subprocess_test; took: 0:00:00.000002
echo "--- running subprocess check --" (+side effect) [enter/↑/↓/ctrl+c]
DEBUG: /usr/lib/python3.11/subprocess.py
DEBUG: PYTHONIOENCODING: utf-8
DEBUG: Total took: 0:00:01.429646
               total        used        free      shared  buff/cache   available
Mem:        32771404    12371052     4576880      399764    16688000    20400352
Swap:        2097148           0     2097148
--- running subprocess check --

If the bug only appears with a specific application, the output of that application and its version:

N/A

Anything else you think is relevant:

N/A

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

1 participant