Skip to content

Optionally suppress 'library contains no keywords' warning #5429

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

Open
JFoederer opened this issue May 9, 2025 · 4 comments
Open

Optionally suppress 'library contains no keywords' warning #5429

JFoederer opened this issue May 9, 2025 · 4 comments

Comments

@JFoederer
Copy link
Contributor

When loading a library in Robot Framework that currently does not have any keywords, you get this warning:
Image
Although mostly helpful, in certain situations I would like to suppress this warning.

I was looking for a simple way to allow extensions to my library. By simple, I mean from a user's perspective where the core is a piece of Python code. For some background; I expect students to do algorithm design and convert the algorithm to Python. We can then run the Robot test suite to check functionality and performance.

What I came up with is having a basic Python file that can be imported by Robot Framework and then pass this library as an argument to the host library. The host library resolves the dependency using get_library_instance().

*** Settings ***
Library           myalgorithm.py
Library           hostlibrary    algorithm=myalgorithm

In the broader sense it would not just be algorithms. I expect some of the extensions to also have keywords of their own. For the simple variants it will really just be a piece of code and importing as a library will yield a warning that the library does not contain any keywords. I would like to be able to suppress that warning in this situation.

The benefit of this approach is that one can do the configuration of the extension directly from Robot Framework. No need to fiddle around with pythonpath or other import structures. Just build on the back of Robot's library management.

@JFoederer
Copy link
Contributor Author

Suggested solution available in PR: #5421 auto_keywords=None suppresses 'library contains no keywords' warning

@pekkaklarck
Copy link
Member

pekkaklarck commented May 15, 2025

Couldn't hostlibrary simply import myalgorithm using importlib? Or is the benefit of using Robot's imports that you can pass paths, not only module names, to it? In that case, perhaps you could use robot.utils.Importer that implements the importing logic?

Also, is it myalgorithm.py or hostlibrary that doesn't have keywords?

@pekkaklarck
Copy link
Member

Here are examples using the Importer:

>>> from robot.utils import Importer
>>> Importer().import_class_or_module('os.path')
<module 'posixpath' (frozen)>
>>> Importer().import_class_or_module('robot.libraries.BuiltIn')
<class 'robot.libraries.BuiltIn.BuiltIn'>
>>> Importer().import_class_or_module(Path('foo.py').absolute())
<module 'foo' from '/home/peke/Devel/robotframework/foo.py'>

The last example expects there to be file foo.py in the current working directory. While creating this example, I noticed that using a relative Path object failed for a TypeError. I submitted #5432 about that and now also relative Path objects would work.

Notice also that the Importer accepts and optional type parameter that can be used to specify what you are importing. It will be used in possible error messages.

@JFoederer
Copy link
Contributor Author

Thanks for the suggestions @pekkaklarck. You are right about the paths. Good guess, because that was not at all clear from my simplified example, I realise now.
I am using RIDE as front end, which makes it very easy to let people use the file browser to select their file (as a library) and then add the library as an argument as illustrated in the initial description.

Anyway, I am sure one of your suggestions will work as well. I will leave it up to you what to do with this issue. Feel free to use the pull request as-is or in modified form if you think it is useful in some way. If you decide to reject this request that is also totally fine. In which case I will remove the pull request as well.

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