You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enhance public robot.api.Languages and robot.api.Language APIs #4494
In order to support languages reasonably in RobotCode (and other tools), it would be nice if we could talk about the Language API again.
To give the user a good error message which language or custom language was not loaded or found, it should be possible to load individual languages and import custom language files.
In the current implementation I can either create the Languages class in the hope that it works, in case of error I can not easily filter out the language that does not work.
add_language can't load user defined language files
There should be a public API that returns all available languages.
already exists, is just not public
The process of loading custom language files should be separated from loading the real language.
Before loading the real languages, the custom language files should be loaded, only then you can load the language
I think this should also be done with the command line parameters, there should be 2 arguments, one for loading the custom language files and the current one for the real language
it should be possible to create a Languages instance that does not insert English and the deprecated single forms of the headers automatically
I currently have to filter it out again if I want to show only the specified languages e.g. in the completion.
Could you give examples of what you'd like to do and how you'd like to use these APIs? It's kind of hard to understand this otherwise. If there's something simple, we can still get it done but anything bigger needs to wait for 6.1. I definitely want rc 2 out still this week so that we get the final release out at some point as well.
I would like to get a list of all available languages to show them in autocompletion
given that I have two settings, one with a list of custom language files and a list of languages to be supported, then I want to load these entries individually to filter out invalid languages and tell the user that they are invalid, but still load the valid ones.
To make sure that the custom languages can be instantiated, you have to make sure that the custom language files are already loaded. If the user specifies them in the wrong order in the current implementation, there will be an error.
I was hoping you could give concrete code examples using new/enhanced APIs so that I could implement them. It seems you already started implementation (c7d4bb9) and just providing a PR obviously works as well. New APIs should get unit tests to make sure we don't accidentally break them in the future. When do you have time to continue with this? I'd hope we get rc 2 out latest on Monday.
Just got back from RoboConDE and the imbus QS-Day.
I thought the changes speak for themselves. i didn't actually change anything, just changed the visibility of the methods and made them static and introduced a new parameter.
But you are right, if it is a public API there should be tests for it. I will add some unittests this weekend.
Usages of the renamed methods haven't been updated. Tests will obviously catch this and the above issue.
get_available_languages and import_languages should get docstrings now that they are part of the public API. Especially the latter would need it because its name isn't too clear. Perhaps it should be renamed to import_language_module to make it more explicit. Also argument name could possibly be better than the current lang.
Languages class would benefit from a docstring as well.
I already fixed the self and the usages, because failing tests ;-) if you go to the Files Changed tab you will see.
The other things I will add/change.
One point I did not implemented yet: I think there should be 2 commandline parameters regarding the language, one for loading the custom language files and one for enabling the language. The other way is, at using the --language command line parameter, we must add a hint to the documentation, that if the user want's to use a custom language module, the module must be given before the language.
What do you think?
I only looked at the commit that referred this issue and thus didn't see additional changes.
I don't think another cli option is needed. If you have a custom language in lang.py, you can simply use --language lang.py and it will be loaded and enabled.
Extending add_language so that also language modules can be loaded was also my first thought.
On RobotCode side I have to create a new language instance every time I want to check if a language or a language module exists and can be loaded. This can happen very often, in the simplest case when the user changes the settings, in principle every time the user changes a file, because it always has to be parsed and analyzed again. It is enough to determine the languages to create them later if needed.
With code completion (I type `language: ' and the code completion shows all possible languages) I only need the names and the codes of the language, but no complete instances of the languages.
It costs time and memory to instantiate the classes each time.
In addition, I would like to load the language modules in a new process, so I don't pollute the language server instance. Once a module is loaded, you can't get it out again. Topic language bleeding ;-) Transferring whole instances or just the class names is a difference.
i think there should be a unified way to get all possible languages and also their names and codes. This is not given if I only use the Language.subclasses, because then I also have to rebuild the algorithm, how RobotFramework determines the names and codes. Whether they are normalized or not. But you can specify that. We can also use the robot.utils.normalizing.NormalizedDict as return value?
I just noticed that: subclasses returns only the direct subclasses, if I want to override e.g. the BDD_prefixes for a certain language this does not work.
If on RobotFramework side the implementation is changed, I have to reprogram that too.
see 1 and:
import_language_module and get_available_languages are static methods in PR, in current implementation they are not, but could be, since they do not use self.
We can also move them from class to global namespace. Then it is no longer possible to call langs.import_language_module like this.
Just to clarify, I want to stay as close as possible to RobotFramework with RobotCode and like to reuse as much as possible and dislike reprogramming code. Preferably with a good API!
I don't understand why any of these points would require adding import_language_module or get_available_languages. It would be easier to understand if you showed concrete code where enhancing add_language and making English optional doesn't work. With the earlier example you showed in the comments of the PR, that approach made the code a lot simpler.
I understand you want as much of the logic to be on Robot side as possible, but that adds more maintenance burden to Robot which is not what I want. I want simple APIs that provide needed functionality and that we can preserve in the future. This is especially important with these new language APIs because they will certainly need to be enhanced in the future anyway. More convenience can be added to these APIs when they are otherwise stable.
changed the title [-][ENHANCEMENT] Enhanced public API for detecting and loading languages[/-][+]Enhance public `robot.api.Languages` and `robot.api.Language` APIs[/+]on Oct 11, 2022
Most of the functionality was added in PR #4496 by @d-biehl. My commit above did these additional changes:
More doc strings.
Change exception used by Languages.add_language on error to match exception used when initializing Languages.
Make Language.code/name propertys accessible also from class. This required implementing new @classproperty decorator.
I consider this issue now ready, but I leave it open to give Daniel some time to review my changes and see how everything works in practice with RobotCode. If there are small and/or critical enhancements, then can still be considered but anything bigger and less urgent can wait for RF 6.1.
Did you @d-biehl have time to look at the latest changes? The commit above added support to use add_language with Language instances and what the earlier commit did was explained in my previous comment.
If there's something still to be changed, let me now ASAP. I just got RF 6.0 rc 2 release notes ready and plan to create the release candidate very soon.
Activity
d-biehl commentedon Oct 4, 2022
I can make a proposal, but not before the end of the week...
pekkaklarck commentedon Oct 4, 2022
Could you give examples of what you'd like to do and how you'd like to use these APIs? It's kind of hard to understand this otherwise. If there's something simple, we can still get it done but anything bigger needs to wait for 6.1. I definitely want rc 2 out still this week so that we get the final release out at some point as well.
d-biehl commentedon Oct 6, 2022
d-biehl commentedon Oct 6, 2022
pekkaklarck commentedon Oct 6, 2022
I was hoping you could give concrete code examples using new/enhanced APIs so that I could implement them. It seems you already started implementation (c7d4bb9) and just providing a PR obviously works as well. New APIs should get unit tests to make sure we don't accidentally break them in the future. When do you have time to continue with this? I'd hope we get rc 2 out latest on Monday.
d-biehl commentedon Oct 6, 2022
Just got back from RoboConDE and the imbus QS-Day.
I thought the changes speak for themselves. i didn't actually change anything, just changed the visibility of the methods and made them static and introduced a new parameter.
But you are right, if it is a public API there should be tests for it. I will add some unittests this weekend.
pekkaklarck commentedon Oct 6, 2022
Few things to fix and enhance in the code:
self.get_available_languagesandimport_languagesshould get docstrings now that they are part of the public API. Especially the latter would need it because its name isn't too clear. Perhaps it should be renamed toimport_language_moduleto make it more explicit. Also argument name could possibly be better than the currentlang.Languagesclass would benefit from a docstring as well.d-biehl commentedon Oct 6, 2022
I already fixed the self and the usages, because failing tests ;-) if you go to the
Files Changedtab you will see.The other things I will add/change.
One point I did not implemented yet: I think there should be 2 commandline parameters regarding the language, one for loading the custom language files and one for enabling the language. The other way is, at using the --language command line parameter, we must add a hint to the documentation, that if the user want's to use a custom language module, the module must be given before the language.
What do you think?
pekkaklarck commentedon Oct 6, 2022
I only looked at the commit that referred this issue and thus didn't see additional changes.
I don't think another cli option is needed. If you have a custom language in
lang.py, you can simply use--language lang.pyand it will be loaded and enabled.pekkaklarck commentedon Oct 6, 2022
The PR implementing this is #4496.
d-biehl commentedon Oct 10, 2022
add some docs and tests for the public API's. Can you review it?
pekkaklarck commentedon Oct 10, 2022
Reviewed.
5 remaining items
d-biehl commentedon Oct 10, 2022
Extending
add_languageso that also language modules can be loaded was also my first thought.On RobotCode side I have to create a new language instance every time I want to check if a language or a language module exists and can be loaded. This can happen very often, in the simplest case when the user changes the settings, in principle every time the user changes a file, because it always has to be parsed and analyzed again. It is enough to determine the languages to create them later if needed.
With code completion (I type `language: ' and the code completion shows all possible languages) I only need the names and the codes of the language, but no complete instances of the languages.
It costs time and memory to instantiate the classes each time.
In addition, I would like to load the language modules in a new process, so I don't pollute the language server instance. Once a module is loaded, you can't get it out again. Topic language bleeding ;-) Transferring whole instances or just the class names is a difference.
i think there should be a unified way to get all possible languages and also their names and codes. This is not given if I only use the Language.subclasses, because then I also have to rebuild the algorithm, how RobotFramework determines the names and codes. Whether they are normalized or not. But you can specify that. We can also use the
robot.utils.normalizing.NormalizedDictas return value?I just noticed that: subclasses returns only the direct subclasses, if I want to override e.g. the BDD_prefixes for a certain language this does not work.
If on RobotFramework side the implementation is changed, I have to reprogram that too.
see 1 and:
import_language_moduleandget_available_languagesare static methods in PR, in current implementation they are not, but could be, since they do not useself.We can also move them from class to global namespace. Then it is no longer possible to call
langs.import_language_modulelike this.Just to clarify, I want to stay as close as possible to RobotFramework with RobotCode and like to reuse as much as possible and dislike reprogramming code. Preferably with a good API!
pekkaklarck commentedon Oct 10, 2022
I don't understand why any of these points would require adding
import_language_moduleorget_available_languages. It would be easier to understand if you showed concrete code where enhancingadd_languageand making English optional doesn't work. With the earlier example you showed in the comments of the PR, that approach made the code a lot simpler.I understand you want as much of the logic to be on Robot side as possible, but that adds more maintenance burden to Robot which is not what I want. I want simple APIs that provide needed functionality and that we can preserve in the future. This is especially important with these new language APIs because they will certainly need to be enhanced in the future anyway. More convenience can be added to these APIs when they are otherwise stable.
Enhancements to public `robot.api.Languages´ API (#4496) #4494
Some further enhancements to public robot.api.Languages API.
[-][ENHANCEMENT] Enhanced public API for detecting and loading languages[/-][+]Enhance public `robot.api.Languages` and `robot.api.Language` APIs[/+]pekkaklarck commentedon Oct 11, 2022
Most of the functionality was added in PR #4496 by @d-biehl. My commit above did these additional changes:
Languages.add_languageon error to match exception used when initializingLanguages.Language.code/namepropertys accessible also from class. This required implementing new@classpropertydecorator.I consider this issue now ready, but I leave it open to give Daniel some time to review my changes and see how everything works in practice with RobotCode. If there are small and/or critical enhancements, then can still be considered but anything bigger and less urgent can wait for RF 6.1.
Languages.add_language: Support input as Language instance.
pekkaklarck commentedon Oct 11, 2022
Did you @d-biehl have time to look at the latest changes? The commit above added support to use
add_languagewithLanguageinstances and what the earlier commit did was explained in my previous comment.If there's something still to be changed, let me now ASAP. I just got RF 6.0 rc 2 release notes ready and plan to create the release candidate very soon.
d-biehl commentedon Oct 11, 2022
It's OK. Everything fits.
pekkaklarck commentedon Oct 11, 2022
Awesome! Looking forward for the new RobotCode release with enhancements related to this and other recent features.