Coder Social home page Coder Social logo

Paths and import of libraries about red HOT 8 CLOSED

nokia avatar nokia commented on July 24, 2024
Paths and import of libraries

from red.

Comments (8)

michalanglart avatar michalanglart commented on July 24, 2024

Hello,

thank you very much for your kind words!

As to your remarks:

  1. When library paths are relative, they are treated to be relative in regard to workspace location. Once you choose a library to be added, RED will check if the library file is contained in your workspace or not. If it lies inside one of your projects in workspace then relative path will be used e.g. myproject/library, otherwise absolute path will be stored. Currently it is not possible to use relative path to location outside the workspace using double-dots e.g. ../../../lib.py, but we have such task defined in our issue tracker, so after implementing that it should be possible to have relative paths pointing to any location at local file system, not only inside the workspace.

  2. Basically all those errors and warnings (called markers in eclipse world) are generated during project build/validation. By default automatic build is enabled (in top-level 'Project' menu 'Build automatically' option is checked) which means that when files are changed they will be revalidated, so old markers would be removed and probably new ones could be reported. Also if you open some robot file in editor it would be revalidated quite frequently when its content changes.

    I suspect that in your case the single file you've opened was revalidated so the errors were gone as the library was added to red.xml file. Currently RED does not revalidate all the files which are affected when new library is added, but you can always rebuild and revalidate all the files by choosing 'Project' -> 'Clean'. Clean itself just removes all the warnings and errors, but if automatic build is enabled this will trigger revalidation of whole project. When automatic build is disabled you will have a chance to choose whether you want to run project build inside 'Clean' dialog.

    Additionally you can try to discover libraries used by project by clicking RMB on your project in Project Explorer view and choosing 'Robot Framework' -> 'Automatically discover and add libraries to red.xml' from context menu. RED will analyze the suite/resource files and will try to discover where libraries in use are located.

  3. Yes this may seem to be odd, but it is unavoidable. In order to give you e.g. content assistant (Ctrl+Space in editor to see list of possible keywords) and other features RED has to know where are the libraries located, so you have to list libraries in use inside red.xml file. If there is no entry for certain library then you will have error generated by RED, because it does not see keywords and library itself. On the other hand RobotFramework will run the test properly because the library is probably located under some path defined in PYTHONPATH, so it will import properly and just run.

    The problem here is that under locations defined in PYTHONPATH there are probably hundreds python files, but only couple of them constitutes proper RF library and there is no easy way to say which file is a library and which isn't - they all just some python code - and RED needs this information in order to generate libdoc and provide couple of nice features. That's why user has to manually or semi-manually assist us in the process of recognizing which file is a library. This is done mainly by adding library in red.xml file or semi-automatically using libraries discovering feature I've mentioned in 2 remark.

Hope this clarifies your doubts; feel free to ask further if you find something more, we will be happy to help and assist!

Cheers,
Michał

from red.

rpwerner avatar rpwerner commented on July 24, 2024

Hello Michal!

Thank you a lot for your reply and sorry for the delay with a reply. I was trying out all you mentioned here :) So lets go to the points:

  1. I had to do what you said and put the project exactly where all my robot files and libraries were. By doing that, I could use the relative path and let the red.xml file generic
  2. this was a good tip! I removed the automatic build and once I had all my libraries in place, I did the clean and all my files were "green".

The only thing that didnt work for me was the 'Automatically discover and add libraries to red.xml'. When I performed what you mentioned, a new screen pops up, but no library was found. Do you know what that might be?

  1. I understood the point here and I tested that out. Regarding the PYTHONPATH I used to import the python libraries, like SudsLibrary or DatabaseLibrary... I defined them in the xml like this:

and I have a pythonpath variable pointing to the site-packages folder.

thank you for everything one more time!

Cheers,
Rafael

from red.

michalanglart avatar michalanglart commented on July 24, 2024

Hi,

this was a good tip! I removed the automatic build and once I had all my libraries in place, I did the clean and all my files were "green".

to clarify: once you've disabled automatic build and did simple clean without building the project again, the files are rather "not validated", than "green"

The only thing that didnt work for me was the 'Automatically discover and add libraries to red.xml'. When I performed what you mentioned, a new screen pops up, but no library was found. Do you know what that might be?

This is relatively new feature, but it should work quite right already. In essence it looks through all the files in your project (when run on project) for library imports and tries to locate them. In order to make it work properly the library should be located either somewhere in your project or in PYTHONPATH (either in system, or added in red.xml). If the test with this library import runs correctly then it should also be discovered in most cases.

Is it possible for you to prepare some tiny example which does not work? A project with suite which imports the library and this library cannot be discovered should be sufficient.

I understood the point here and I tested that out. Regarding the PYTHONPATH I used to import the python libraries, like SudsLibrary or DatabaseLibrary... I defined them in the xml like this:

it seems that you wanted to add some paragraph here, but it's missing.

Cheers,
Michał

from red.

adam-wypych avatar adam-wypych commented on July 24, 2024

@rpwerner: Any feedback?

from red.

rpwerner avatar rpwerner commented on July 24, 2024

Hello,

Unfortunately I had some realocations and I couldn't work on the plugin for our project anymore. Fornow I wasn't able to do the small example.

But all the other hints were very welcome and I distributed to other developers and they work as expected for them as well.

Cheers,
Rafael

from red.

thangaroja avatar thangaroja commented on July 24, 2024

Hi,

I followed the above and get the library recognized in my resource file. Now there is no red line over the specified library. But when calling a java method as keyword for the same library, it errors as "unknown keyword 'givenmethodnamed' ". Please help me overcome this issue.

from red.

michalanglart avatar michalanglart commented on July 24, 2024

Hi,

In order to see keywords from libraries RED has to generate library specification file (using robot.libdoc tool provided with Robot). To do it in your project you have to:

  • Have your library added to red.xml (project configuration file). Open red.xml, go to 'Referenced libraries' and use 'Add Java library' (it is Java library, right?). Add your library and save the changes.
  • Assuming you have automatic build enabled (top-level 'Project' menu -> 'Build automatically') it should generate the file and you should see the library with keywords in Project Explorer under 'Robot Referenced libraries' entry. If autobuilding is disabled you can trigger the build manually by using 'Project' -> 'Clean' with 'Start a build immediately' checked).

After project is built and validated you should see keywords in content assist of editor (Ctrl+Space) as well as there should be no errors reported on those keywords.

from red.

NehaDua avatar NehaDua commented on July 24, 2024

Hi Team ,
Thanks much for this amazing plugin "RED", we have started using RF and found this plugin really helpful.
My requirement is to use same Resource file across all the RF projects in eclipse ,s o kept common resource file outside project directory and getting warning message ,can you please assist if RED supports it or not?
Tried using absolute and relative path but getting below warning :

•Path '../../CommonFiles/CommonUpointKeywords.resource' points to location outside your workspace
•RED does not support importing resources located outside of workspace. Keywords from this resource will not be recognized. Try to use Quick Fix (Ctrl+1) to link folder into the project.

from red.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.