Skip to content

Libdoc: Support *.libspec extension when reading library information from spec files #3491

Closed

Description

@pekkaklarck

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:

  1. Change Libdoc to consider *.libspec files as spec files when reading information.
  2. Automatically use XML format when the output file extension is *.libspec like we do if the extension is *.xml.
  3. We could also consider specifying this so that *.libspec files should use XML:HTML format (Libdoc: Support converting docs to HTML with XML outputs #3301) i.e. have the library and keyword docs converted to HTML.

Activity

  1. added this to the v3.2 milestone on Mar 6, 2020
  2. michalanglart commented on Mar 6, 2020

    @michalanglart

    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:

    • 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.

    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#L70

  3. pekkaklarck commented on Mar 9, 2020

    @pekkaklarck
    MemberAuthor

    It seems we all agree the *.libspec extension is a good idea. This is my thinking about the more detailed design:

    1. 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.

    2. 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.

    3. 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.

  4. pekkaklarck commented on Mar 9, 2020

    @pekkaklarck
    MemberAuthor

    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.

  5. fabioz commented on Mar 9, 2020

    @fabioz
    Contributor

    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).

  6. pekkaklarck commented on Mar 9, 2020

    @pekkaklarck
    MemberAuthor

    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.

  7. fabioz commented on Mar 10, 2020

    @fabioz
    Contributor

    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.

  8. pekkaklarck commented on Mar 10, 2020

    @pekkaklarck
    MemberAuthor

    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.

  9. pekkaklarck commented on Mar 10, 2020

    @pekkaklarck
    MemberAuthor

    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.

  10. pekkaklarck commented on Mar 13, 2020

    @pekkaklarck
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions