Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support IntelliSense with ontology information #591

Open
5 tasks
pablo-de-andres opened this issue Mar 17, 2021 · 4 comments · Fixed by #599
Open
5 tasks

Support IntelliSense with ontology information #591

pablo-de-andres opened this issue Mar 17, 2021 · 4 comments · Fixed by #599
Assignees
Labels
📜 ontology 🌱 new feature Solving the issue involves the incorporation of a new feature. 💬 discussion The idea is not mature enough to result in an implementation, and needs further discussion.

Comments

@pablo-de-andres
Copy link
Member

pablo-de-andres commented Mar 17, 2021

It would be a nice feature to get autocompletion and argument information when instantiating objects from the ontology classes.
For example, the code:

from osp.core.namespaces import cuba

wrapper = cuba.Wrap

Should suggest the autocompletion to Wrapper, and inform that it requires a session parameter.

I am not sure how easy, or even if it is possible, but I think it is definitely worth looking into at some point.

Things that should be implemented:

  • Autocompletion of namespace elements (IPython).
  • Autocompletion of namespace elements (IDE).
  • Get info about ontology classes, relationships and attributes based on the ontology annotation properties using the IPython ? and ?? operators.
  • Tooltip with info about ontology classes, relationships and attributes based on the ontology annotation properties on IDEs.
  • Make pico update the stubs on installation/uninstallation/reinstallation of ontologies.
@pablo-de-andres pablo-de-andres added 💬 discussion The idea is not mature enough to result in an implementation, and needs further discussion. feature request 💡 📜 ontology labels Mar 17, 2021
@pablo-de-andres
Copy link
Member Author

Possibly related, detection of the existing namespaces would also be useful.
See:
image

@kysrpex kysrpex self-assigned this Mar 23, 2021
@kysrpex kysrpex added the 🔨 simple fix Likely to be solvable in at most a few hours (full-time). label Mar 23, 2021
@kysrpex kysrpex linked a pull request Mar 23, 2021 that will close this issue
3 tasks
@kysrpex kysrpex removed the 🔨 simple fix Likely to be solvable in at most a few hours (full-time). label Mar 24, 2021
@kysrpex
Copy link
Contributor

kysrpex commented Mar 24, 2021

I started to work on this in the linked pull request, but later I realized that it is only possible to solve this issue in a simple way when the user is working with IPython.

When using IPython (i.e. Jupyter notebooks), some times the user will be coding when the namespace has been already imported. Therefore, the __dir__ method of the osp.core.namespaces package will have been defined, and autocompletion is possible. Of course, if the user has not yet imported the namespace, then the autocompletion of the ontology entities will not be possible. Nevertheless, implementing this would still be a positive change, so I did it.

However, when using an IDE such as VSCode or Pycharm, the story is different. The IDE does not run the code and keep a Python kernel with the result, so it cannot use the __dir__ method for autocompletion. So in principle, unless officially supported by the IDE or as a plug-in, this would be imposibble.

There is however a hacky "solution", which I do not like too much, but maybe @yoavnash, which is a user of OSP-core and I think needs this feature can give better input on this. There exist Python type hinting stub files (pyi extension), which allow a developer to supply type hinting while keeping the code in the py file itself clean, so that for example, it can be kept compatible with Python 2.

The trick is, that in this file you can specify types for things that do not actually exist in the py file itself. Look at the picture below.

image

It is up to the IDE to support those pyi files. I know that at least PyCharm supports them. I do not know about the VSCode Python plugins. When the file pictured above is included, indeed PyCharm is offering me to autocomplete both the namespace name and the Integer entity inside it.

Since these stub files do not need to be included in the same package as the python files themselves, I though that OSP-core could generate a osp-core-ontology-stubs package each time an ontology is installed or uninstalled, and put it in ~/.osp_ontologies. Then either the user could reinstall the package or OSP-core itself could launch the reinstallation.

Do you think this would bring the intended benefit and is worth implementing? Did any better idea come to your mind? Should we just accept that this is too hacky and close the issue?

@pablo-de-andres
Copy link
Member Author

I think it might relate to this?

@kysrpex
Copy link
Contributor

kysrpex commented Mar 24, 2021

I think it might relate to this?

Exactly, this person wants the same functionality as us.

@kysrpex kysrpex added 🌱 new feature Solving the issue involves the incorporation of a new feature. and removed 💡 feature request labels Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📜 ontology 🌱 new feature Solving the issue involves the incorporation of a new feature. 💬 discussion The idea is not mature enough to result in an implementation, and needs further discussion.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants