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
Libdoc: Support *.libspec extension when reading library information from spec files #3491
Libdoc allows creating XML files with information about a certain library:
$ python -m robot.libdoc BuiltIn BuiltIn.xml
When using the --format option, it is possible to use also other extensions than *.xml:
$ python -m robot.libdoc --format xml BuiltIn BuiltIn.libspec
Having a custom extension for these spec files is handy, but unfortunately Libdoc itself cannot read information from them anymore as it only supports the *.xml extension:
$ python -m robot.libdoc BuiltIn.xml version
3.2b2
$ python -m robot.libdoc BuiltIn.libspec version
Importing test library '/path/BuiltIn.libspec' failed: Not a valid file or directory to import.
The problem is that internally Libdoc considers only *.xml files to be spec files and tries to import others as libraries or resource files. This also affects Libdoc's public API (#3448) possibly used by the LSP project (robocorp/robotframework-lsp#20).
We could enhance Libdoc to auto-detect the type of the given argument by looking at what it contains, but that would be somewhat complicated and also error prone. It's a lot easier if we just agree on an explicit extension to use. The *.libspec extension is apparently already used by the RED editor and we should just standardize that. It would basically mean these changes:
Change Libdoc to consider *.libspec files as spec files when reading information.
Automatically use XML format when the output file extension is *.libspec like we do if the extension is *.xml.
this one looks like an imporvement from RED point of view. It only changes the way we obtain rich HTML-based documentation. Currently we do it this way:
we generate the .libspec file using robot.libdoc functions on our python-robot integration server
we read the documentation string
the documentation string is send to integration server
inegration server converts it to html using DocToHtml from robot.libdocpkg.htmlwriter
Having html documentation written already in the specification file would make this process straight and faster altough we would be able to drop current way once we drop support for 3.1.
It seems we all agree the *.libspec extension is a good idea. This is my thinking about the more detailed design:
Change the lower level DocumentationBuilder to handle *.libspec files the same way it currently handles *.xml files. It allows creating HTML docs based on *.libspec files using Libdoc and, more importantly in the LSP usage, allows using LibraryDocumenation('example.libspec'). This is a trivial change that I assume everyone agrees.
Consider adding option resource_extension and spec_extensions arguments to DocumentationBuilder and LibraryDocumenation to programmatically configure what extensions to use. This would be a trivial change making the API a bit more flexible but I'm not certain is it really needed. Regardless is this done or not, I wouldn't spent time exposing on the CLI.
Change the code so that if the output extension is *.libspec, the format is XML:HMTL by default. Ought to be a simple change as well.
Notice @michalanglart that regardless what's done to this issue, #3301 has already made it possible to get docs in XML spec files to be HTML. That was a very good idea by @Snooz82.
Better support for deprecation sounds like a good idea. As you apparently know, Robot Framework automatically emits a deprecation warning if keyword documentation starts with *DEPRECATED*. Libdoc could easily check that and add this information to its own model and to spec files to make it easily available for external tools. Please submit an issue and I promise to take a bit closer look on it.
So, for LSP it'd probably be better if HTML is not the default for .libspec (I think that the original reST or other formats may be more readable than extracting text from HTML -- although I'll probably implement the option to do that in the future, I'd rather have the original source for the LSP).
It's unfortunate LSP doesn't support HTML. I commented the aforementioned issue and explained our position. Anyway, it seems it's best for *.libspec files to use whatever is the original doc format by default. It will be possible to use --format XML:HTML to force HTML anyway.
Another thing that would be useful is if the spec had some way for telling which are the sources that generated that file (when possible).
For instance, if a keyword was generated from a method in some Python file, I'd like to track that file for modifications to know that I have to regenerate the spec if that file changes... I know there are cases where this isn't possible, but when it is, it'd be nice to have it.
I can see the including the path to the original source file and possibly also line number would be handy, but there's a problem that it would work only with locally generated files. We can discuss what would be best way to solve this e.g. on Slack, but possible RF enhancement would anyway require a separate issue.
This is implemented (incl. tests and docs) by the above commit. I don't close this yet because I'm still not certain should *.libspec mean XML or XML:HTML format by default. I kind of think the latter would be more generic even if it couldn't be used by LSP. Either way, the format can be set explicitly with the --format option.
After thinking this a bit more, decided to use the XML:HTML format (i.e. automatically convert docs to HTML) with *.libspec files by default. It's a lot easier for external tools to consume HTML than to support all our doc formats. If needed, the format can be set to "normal" XML with --format xml regardless the extension. This change was done by 45268b5 and I consider this issue done.
Activity
michalanglart commentedon Mar 6, 2020
Hi,
this one looks like an imporvement from RED point of view. It only changes the way we obtain rich HTML-based documentation. Currently we do it this way:
Having html documentation written already in the specification file would make this process straight and faster altough we would be able to drop current way once we drop support for 3.1.
From my point of view I could only suggest a tiny thing for rather minor issue: maybe it would be nice to have depracated keywords better flagged in the generated specification file? This can be beneficial for editors because they can e.g mark such keywords with strikeout font or raise a warning when deprecated keyword is used. RED does this however it looks into documentation text to see if keyword is deprecated and it is not really reliable because it's just some pattern matching. It would be great if library specification file could have something like
<deprecated>true</deprecated>inside a keyword so that we wouldn't need to do this: https://github.com/nokia/RED/blob/0ed43aacc6cc4564b9026eae6b576a656747961f/src/RobotFrameworkCore/org.robotframework.ide.core-functions/src/main/java/org/rf/ide/core/libraries/KeywordSpecification.java#L70pekkaklarck commentedon Mar 9, 2020
It seems we all agree the
*.libspecextension is a good idea. This is my thinking about the more detailed design:Change the lower level DocumentationBuilder to handle
*.libspecfiles the same way it currently handles*.xmlfiles. It allows creating HTML docs based on*.libspecfiles using Libdoc and, more importantly in the LSP usage, allows usingLibraryDocumenation('example.libspec'). This is a trivial change that I assume everyone agrees.Consider adding option
resource_extensionandspec_extensionsarguments toDocumentationBuilderand LibraryDocumenation to programmatically configure what extensions to use. This would be a trivial change making the API a bit more flexible but I'm not certain is it really needed. Regardless is this done or not, I wouldn't spent time exposing on the CLI.Change the code so that if the output extension is
*.libspec, the format isXML:HMTLby default. Ought to be a simple change as well.pekkaklarck commentedon Mar 9, 2020
Notice @michalanglart that regardless what's done to this issue, #3301 has already made it possible to get docs in XML spec files to be HTML. That was a very good idea by @Snooz82.
Better support for deprecation sounds like a good idea. As you apparently know, Robot Framework automatically emits a deprecation warning if keyword documentation starts with
*DEPRECATED*. Libdoc could easily check that and add this information to its own model and to spec files to make it easily available for external tools. Please submit an issue and I promise to take a bit closer look on it.fabioz commentedon Mar 9, 2020
For the LSP, HTML is not a supported format (see: microsoft/language-server-protocol#781).
So, for LSP it'd probably be better if HTML is not the default for
.libspec(I think that the original reST or other formats may be more readable than extracting text from HTML -- although I'll probably implement the option to do that in the future, I'd rather have the original source for the LSP).pekkaklarck commentedon Mar 9, 2020
It's unfortunate LSP doesn't support HTML. I commented the aforementioned issue and explained our position. Anyway, it seems it's best for
*.libspecfiles to use whatever is the original doc format by default. It will be possible to use--format XML:HTMLto force HTML anyway.fabioz commentedon Mar 10, 2020
Another thing that would be useful is if the spec had some way for telling which are the sources that generated that file (when possible).
For instance, if a keyword was generated from a method in some Python file, I'd like to track that file for modifications to know that I have to regenerate the spec if that file changes... I know there are cases where this isn't possible, but when it is, it'd be nice to have it.
pekkaklarck commentedon Mar 10, 2020
I can see the including the path to the original source file and possibly also line number would be handy, but there's a problem that it would work only with locally generated files. We can discuss what would be best way to solve this e.g. on Slack, but possible RF enhancement would anyway require a separate issue.
Libdoc: Support `*.libspec` extension (#3491)
pekkaklarck commentedon Mar 10, 2020
This is implemented (incl. tests and docs) by the above commit. I don't close this yet because I'm still not certain should
*.libspecmeanXMLorXML:HTMLformat by default. I kind of think the latter would be more generic even if it couldn't be used by LSP. Either way, the format can be set explicitly with the--formatoption.pekkaklarck commentedon Mar 13, 2020
After thinking this a bit more, decided to use the
XML:HTMLformat (i.e. automatically convert docs to HTML) with*.libspecfiles by default. It's a lot easier for external tools to consume HTML than to support all our doc formats. If needed, the format can be set to "normal" XML with--format xmlregardless the extension. This change was done by 45268b5 and I consider this issue done.Libdoc: Support `*.libspec` extension (robotframework#3491)