Skip to content

Include library and keyword source information in Libdoc spec files #3507

Closed

Description

@fabioz

Provide which are the sources that generated a given .libspec 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.

Activity

  1. pekkaklarck commented on Mar 17, 2020

    @pekkaklarck
    Member

    The problem with including source information is that it only makes sense with files on the machine where spec files (or HTML files) are generated. That said, I see it being a very important feature e.g. with editors. Some initial ideas about this below:

    1. This functionality should be configurable with a command line option. When enabled, source would be added to XML spec files but shown also in HTML output files. Not sure what the option should be named, perhaps something like --includesource with a suitable short option.

    2. Should also configurable programmatically.

    3. I don't think it is a good idea to enable this automatically with *.libspec files (Libdoc: Support *.libspec extension when reading library information from spec files #3491). It's easy to enable the functionality when needed and documentation is easier if there are no special cases. I'm not strongly against this, though.

    4. Source should be stored as an absolute path to avoid breaking it if the spec file is moved.

    5. Should check could keywords also get line numbers. I would expect editors to benefit from this.

    6. Need to think should we allow giving the source externally as well. If there are not concrete use cases now, this can easily be added later if needed.

  2. added this to the v3.2 milestone on Mar 17, 2020
  3. fabioz commented on Mar 17, 2020

    @fabioz
    ContributorAuthor

    I agree about all those points... some observations:

    1/2/3. the use case is automatically generating those for libraries that don't have them, so, having the --includesource as an option passed from the client seems good (being default is not needed).

    1. Having line numbers would be nice for a go to definition... some notes here:
    • the file for the main imported module should be there globally for the spec (as we want to regenerate the libspec if it changes).
    • there should be a source tied to each specific keyword -- it's not uncommon in Python to have the functions in one place and having the API be just a bunch of imports, so, we want the actual place of the function (it may be skipped if it matches the global filename).
    1. I don't think this is needed for now.
  4. aaltat commented on Mar 17, 2020

    @aaltat
    Contributor

    With dynamic libraries, like SeleniumLibrary, keywords can locate in multiple files. It could be good option to have keyword specific location instead of library level location.

  5. pekkaklarck commented on Mar 17, 2020

    @pekkaklarck
    Member

    Thanks for comments @fabioz and @aaltat. We clearly need also keyword level source information. I think it could work like this:

    • Library can have source information as discussed earlier.
    • Each keyword can have source information in format path:lineno where both parts are optional. If path is not present, then the library level source can be used instead.
  6. pekkaklarck commented on Mar 19, 2020

    @pekkaklarck
    Member

    Prototyped this a bit and here are the findings:

    1. With Python based libraries using the static or hybrid API we can easily get the actual function/method implementing the keyword. From it we can get the source file with inspect.getsourcefile and line number with inspect.getsourcelines. We can do this only when using Libdoc and when getting source is explicitly requested. That avoids all possible performance problems.

    2. With dynamic libraries we cannot get the actual method in a generic manner. This is a problem in general, but it is an especially big problem because SeleniumLibrary utilizes the dynamic API. We probably could special case libraries using the PythonLibCore like SL does, but that's not a fully generic solution. Alternatively we could add get_keyword_source method to the dynamic API and enhance PythonLibCore to support it. Do you have an opinion about this @aaltat?

    3. The dynamic API supporting getting keyword source would mean that also JavalibCore could support it. Any comments about that @Hi-Fi?

    4. I don't know could we get keyword source info from Java based libraries utilizing the static API. Need to investigate that but I don't consider it a blocker if that's not possible.

    5. Not sure what we should do with the remote API. If the dynamic API is enhanced, we could also enhance the remote API but I'm not sure is it worth the effort at this point.

  7. aaltat commented on Mar 20, 2020

    @aaltat
    Contributor

    I don't see problems adding new method for dynamic library API. Should not be that difficult to implement in the python lib core.

    I don't know about remote libraries, because I haven't used them that much. I could imagine that the remote library source code could be available somewhere in the local file system and it could be useful to jump to the keyword.

  8. pekkaklarck commented on Mar 20, 2020

    @pekkaklarck
    Member

    No, it's not hard to add to the APi or to the DynamicCore. Let's do that.

    That means we need a new PythonLibCore release for SL to be able to use this feature and to benefit from go-to-definition with LSP. Not a huge task either.

  9. fabioz commented on Mar 20, 2020

    @fabioz
    ContributorAuthor

    One thing that just crossed my mind is that it should be possible for filenames to be relative too (if we want libraries to generate it when doing a release and distribute it along the sources, filenames need to stored relative to the .libspec location).

  10. pekkaklarck commented on Mar 20, 2020

    @pekkaklarck
    Member

    Should they be relative to the library installation directory or where? Should this be the default behavior?

  11. fabioz commented on Mar 20, 2020

    @fabioz
    ContributorAuthor

    They should be relative to the location of the .libspec file (my expectation is that library users will generate it on the ci as a part of the release process and the .libspec file will be put in the place where it'll be distributed relative to other resources).

    I think it should be the default (as it's what users that want to distribute the sources should do), whereas the absolute path is valid just for the current machine.

  12. pekkaklarck commented on Mar 20, 2020

    @pekkaklarck
    Member

    How would this work if you install a lib with pip? Should the lib contain the spec or should you download it separately? In the latter case, how can we known what should be the root dir?

    What's in general the use case for distributing spec files if Libdoc can be used to generate them as needed?

    Perhaps better to move further discussion to Slack and return her when we agree on the details.

  13. fabioz commented on Mar 20, 2020

    @fabioz
    ContributorAuthor

    I think that if you install with pip it should be distributed along.

    As for the use case, I think there are 2 things:

    1. Library discoverability
      Right now it's hard to know which are the available libraries as they can appear to be plain Python modules (so, having a .libspec file at the PYTHONPATH would help a lot there -- right now, I just try to create a .libspec after the user imports it -- and I pre-create the bultin libraries -- so, I can't offer suggestions of the libraries to import unless it was already imported once and that file was opened and had a request for code-completion, which isn't ideal).

    2. I think that it's a bit wasteful having to regenerate the .libspec at each user machine.
      I did some measurements here: at my machine, it currently takes around 5 seconds to generate the docs for the libraries which are builtin... I'm not sure how long it would take for other libraries, but the main problem is that right now this relates to the first time a library is used (so, the first time it takes around 0.5 seconds more to generate the code completion and it feels quite sluggish in that case -- sure, it's cached afterwards, but that's a first bad impression... usually I'd give a timeout error if a code completion request takes 0.5 seconds).

  14. 21 remaining items

  15. pekkaklarck commented on Mar 28, 2020

    @pekkaklarck
    Member

    This functionality was documented in the User Guide by 7212ed3 and some corner cases fixed by earlier commits. I guess we can 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