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

Exception with run_command using python_api: AttributeError: 'int' object has no attribute 'stdout' #13922

Open
2 tasks done
dgoeries opened this issue May 14, 2024 · 6 comments
Labels
pending::feedback indicates we are waiting on feedback from the user source::community catch-all for issues filed by community members type::support neither a bug nor feature, is really just a user having questions or difficulty somewhere

Comments

@dgoeries
Copy link

Checklist

  • I added a descriptive title
  • I searched open reports and couldn't find a duplicate

What happened?

Sorry, we have an exception now in our conda builder. I went through all issues and could not find it. Are we overlooking something. This issue appeared after we upgraded python and conda, but we are not able to pin this problem exactly.

I copy&paste code example

from conda.cli.python_api import Commands, run_command

def conda_run(command, *args, **kwargs):
    stdout, stderr, ret_code = run_command(command, *args, **kwargs)
    if ret_code != 0:
        msg = f'Command {command} [{args}] ' \
              f'{kwargs} returned {ret_code}\n' \
              f'STDOUT:\n {stdout}\n' \
              f'STDERR:\n {stderr}'
        raise RuntimeError(msg)
    return stdout

conda_run(Commands.RUN, '-n', 'base',  'conda', 'config', '--set', 'pip_interop_enabled', 'True')

Getting an exception

  File "C:\DIR\build.py", line 53, in __init__
    conda_run(Commands.RUN, '-n', 'base',
  File "C:\DIR\utils.py", line 11, in conda_run
    stdout, stderr, ret_code = run_command(command, *args, **kwargs)
  File "C:\Users\USERNAME\Miniconda3\lib\site-packages\conda\cli\python_api.py", line 128, in run_command
    raise e
  File "C:\Users\USERNAME\Miniconda3\lib\site-packages\conda\cli\python_api.py", line 119, in run_command
    stdout = result.stdout
AttributeError: 'int' object has no attribute 'stdout'

Conda Info

active environment : base

           shell level : 1
          conda version : 23.7.4
    conda-build version : 3.24.0
         python version : 3.10.14.final.0
       virtual packages : __archspec=1=x86_64
                          __win=0=0
       base environment : C:\Users\USER\Miniconda3  (writable)
      conda av data dir : C:\Users\USER\Miniconda3\etc\conda
               platform : win-64
             user-agent : conda/23.7.4 requests/2.31.0 CPython/3.10.14 Windows/10 Windows/10.0.19045
          administrator : True
             netrc file : None
           offline mode : False

Conda Config

No response

Conda list

No response

Additional Context

No response

@dgoeries dgoeries added the type::bug describes erroneous operation, use severity::* to classify the type label May 14, 2024
@dgoeries
Copy link
Author

Downgrading CONDA to 22.9.0 solved the problem locally, exception is not appearing anymore

@travishathaway
Copy link
Contributor

@dgoeries,

Did you experiment with upgrading to the latest conda version 24.4.0? I'm curious to see if that resolves your issue.

@travishathaway travishathaway added source::community catch-all for issues filed by community members pending::feedback indicates we are waiting on feedback from the user labels May 15, 2024
@dgoeries
Copy link
Author

Yes, I have tried upgrading before (24.5) but was not succeeding

@travishathaway
Copy link
Contributor

travishathaway commented May 15, 2024

Also, is there a reason you're running conda commands with conda run? That seems a little redundant.

@conda-bot conda-bot added pending::support indicates user is waiting on support from triage engineers and removed pending::feedback indicates we are waiting on feedback from the user labels May 15, 2024
@travishathaway
Copy link
Contributor

travishathaway commented May 15, 2024

This works for me with newer versions of conda (24.3.0):

from conda.cli.python_api import Commands, run_command


def conda_run(command, *args, **kwargs):
    stdout, stderr, ret_code = run_command(command, *args, **kwargs)
    if ret_code != 0:
        msg = f'Command {command} [{args}] ' \
              f'{kwargs} returned {ret_code}\n' \
              f'STDOUT:\n {stdout}\n' \
              f'STDERR:\n {stderr}'
        raise RuntimeError(msg)
    return stdout

def main():
    conda_run(Commands.CONFIG, '--set', 'pip_interop_enabled', 'True')


if __name__ == "__main__":
    main()

@travishathaway travishathaway added pending::feedback indicates we are waiting on feedback from the user type::support neither a bug nor feature, is really just a user having questions or difficulty somewhere and removed pending::support indicates user is waiting on support from triage engineers type::bug describes erroneous operation, use severity::* to classify the type labels May 15, 2024
@dgoeries
Copy link
Author

dgoeries commented May 15, 2024

thanks a lot, I will have a detailed look. We are using a file with name dunder main py

@conda-bot conda-bot added pending::support indicates user is waiting on support from triage engineers and removed pending::feedback indicates we are waiting on feedback from the user labels May 15, 2024
@travishathaway travishathaway added pending::feedback indicates we are waiting on feedback from the user and removed pending::support indicates user is waiting on support from triage engineers labels May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending::feedback indicates we are waiting on feedback from the user source::community catch-all for issues filed by community members type::support neither a bug nor feature, is really just a user having questions or difficulty somewhere
Projects
Status: 🆕 New
Development

No branches or pull requests

3 participants