Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feature request/suggestion: libdoc invocation sets special environment variable #4906

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

Closed
suiluj opened this issue Oct 19, 2023 · 8 comments
Closed

Comments

@suiluj
Copy link

suiluj commented Oct 19, 2023

Hello,

I am relatively new to robot framework and stumpled upon a problem while developing a rf library in vscode while using the robot framework lsp extension:

The lsp extension runs libdoc while linting/checking the code.

In my library code i check for custom environment variables on class object init. These variables are only set on real test exection but of course not while just developing the tests. This results in erros of the extension while developing.

The vscode extension runs libdoc.

As a workaround I suggest that the libdoc robot framework runs sets a special environment variable like

RUN_BY_ROBOT_FRAMEWORK_LIBDOC=TRUE

Then my code could first check this environment variable and could skip the rest of the init code to avoid robot framework lsp errors.

Does this solution make sense or is my approach wrong?

Here I described my problem in the lsp repo:

robocorp/robotframework-lsp#988

@pekkaklarck
Copy link
Member

Could you clarify how checking for some environment variable set by Libdoc would be better or easier that just gracefully handling the situation where the environment variables you need during execution don't exist?

@suiluj
Copy link
Author

suiluj commented Oct 31, 2023

@pekkaklarck you were right. I found an easier solution which works in my case.

In the __init__ of my library I just check if the code was run by libdoc and just quit in that case:

if "libdoc.py" in sys.argv[0]:
    return

This is a simpler solution. Now I can load my environment in the init but still get the code completion in vscode.

@suiluj suiluj closed this as completed Oct 31, 2023
@d-biehl
Copy link
Contributor

d-biehl commented Nov 9, 2023

Not sure how I got here ;-)

But, I also regularly get such requests for robotcode that the keywords for some library cannot be loaded correctly or dead processes remain when the library is loaded in robotcode, or ... or ... or ... because people don't know that their library has to be instantiated correctly when creating a libdoc to get the keywords and that the code has to be executed in the constructor of the library.
This is why the property BuiltIn().robot_running was introduced in one of the last Robot Framework versions. With this property you can query exactly this behaviour and only initialize your library/variable file correctly if Robot is actually running, which is not the case when generating the LibDoc.
The property BuiltIn().dry_run_active should also be mentioned.

For older RobotFramework versions I always refer to the undocumented check EXECUTION_CONTEXTS.current is not None which corresponds to the check of robot_running.

Both properties are not really described anywhere. Wouldn't that be a topic for the UserGuide?

@d-biehl
Copy link
Contributor

d-biehl commented Nov 9, 2023

This is the issue for creating these properties #4666

@pekkaklarck
Copy link
Member

Mentioning these properties in the User Guide is a good idea. That should have been done already as part of #4666. I'm on mobile but try to remember to do that later. If you want to make sure it's not forgotten, please submit an issue.

@suiluj
Copy link
Author

suiluj commented Nov 9, 2023

@d-biehl thanks for your hint to these BuiltIn() methods. I will change my code to use them instead of my hacky version. ;)

@d-biehl
Copy link
Contributor

d-biehl commented Nov 17, 2023

@pekkaklarck did you allready create an issue about this? if not I can create one.

@pekkaklarck
Copy link
Member

@d-biehl I didn't submit an issue so please go ahead and submit one. Even better if you can take a look where to add this information in the User Guide.

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

3 participants