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

AttributeError: 'function' object has no attribute 'run_cli' #5098

Open
wesleybl opened this issue Apr 3, 2024 · 6 comments
Open

AttributeError: 'function' object has no attribute 'run_cli' #5098

wesleybl opened this issue Apr 3, 2024 · 6 comments

Comments

@wesleybl
Copy link

wesleybl commented Apr 3, 2024

I can't run the code below:

>>> import robot.run
>>> robot.run.run_cli
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'run_cli'

But I can run:

>>> from robot.run import run_cli
>>> run_cli()
[ ERROR ] Expected at least 1 argument, got 0.

Try --help for usage information.

This is strange, because depending on the form of the import, run can be a function or a module.

@wesleybl
Copy link
Author

wesleybl commented Apr 3, 2024

This is related to #4129. The buildout generates the following code for the entry point:

import robot.run

if __name__ == '__main__':
    sys.exit(robot.run.run_cli())

Then the above error occurs when running the script.

I don't think changing the way the entry point is written would solve the problem. I think what would solve it would be to eliminate the confusion of "run" in both types of import. Of course the buildout could be wrong too, but that doesn't invalidate this issue here.

cc @choeger

@wesleybl
Copy link
Author

wesleybl commented Apr 3, 2024

but could you not switch the entry points to use the root module directly?

humm @choeger' suggestion works. If the entry point is changed to:

'robot = robot:run_cli'

The script generated by buildout would be:

import robot

if __name__ == '__main__':
    sys.exit(robot.run_cli())

and it would work.

@pekkaklarck
Copy link
Member

pekkaklarck commented Apr 4, 2024

This is due to the robot root module having both a run sub module and a run function. This isn't great design but there are historical reasons for it.

The run module exists to allow running Robot like python -m robot.run. That's not too relevant nowadays when python -m robot works, but that wasn't possible back in Python 2.6 days.

The run function is there just to have a convenient API for running Robot programmatically. I believe it was added after the run module was introduced and could have been named differently, but run felt (and feels) like a good name for this purpose and the function and the module having the same name didn't seem to cause problems.

To resolve the issue, we needed to rename either the module or the function. As I wrote otherwise, python -m robot.run usage isn't that important anymore, so I believe renaming the module would be a better idea. That would, however, be a backwards incompatible change causing issues for anyone possibly still using python -m robot.run or importing anything from the robot.run module. I'm not sure the change worth the problems it would cause.

@wesleybl
Copy link
Author

wesleybl commented Apr 4, 2024

@pekkaklarck I think it should be renamed because it causes confusion. But if it's going to cause a lot of trouble, could you at least change the entry point to work with buildout?

@pekkaklarck
Copy link
Member

Do you mean that in our setup.py we should change 'robot = robot.run:run_cli' to 'robot = robot:run_cli'? That sounds fine, but I'm slightly worried about possible side-effects and believe it would be safer to do that in RF 7.1 than in 7.0.1.

@wesleybl
Copy link
Author

wesleybl commented Apr 5, 2024

Do you mean that in our setup.py we should change 'robot = robot.run:run_cli' to 'robot = robot:run_cli'?

Yes. Remembering that the other entrypoints will require the same change.

That sounds fine, but I'm slightly worried about possible side-effects and believe it would be safer to do that in RF 7.1 than in 7.0.1.

The run module will continue to exist. So I don't see a problem with making this change in 7.0.1. I don't see anything breaking. I think it's a safe change to make.

But in any case, changing the module name cannot be lost sight of. Maybe in an 8.0 version?

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

2 participants