Documentation URL of os module - python

I'm trying to crack the URL format for Python's os module for use in PyCharm's documentation window.
My attempt so far:
https://docs.python.org/3/library/os.html#{element.qname}
but I'm having trouble displaying documentations such as:
https://docs.python.org/3/library/os.path.html#module-os.path
What's the right format?

Before addressing the URL hack, it should be mentioned that the deciding setting of how documentation is shown is the "Render external documentation for stdlib" setting. You can configure it by going to File > Settings > Python Integrated Tools > Docstrings > Render external documentation for stdlib as shown in the screenshot:
If you enable the "Render external documentation for stdlib" setting (and have internet access), the IDE will automatically retrieve standard library docs from https://docs.python.org/{python.version}/library/{module.name}.html#{element.qname}. The Python version is automatically determined from the Python interpreter configured for the Project, so that's the version of the documentation shown for the file you have opened in the editor.
See how this corresponds to the online documentation:
If you disable the "Render external documentation for stdlib" setting (or don't have internet access), the IDE will show the docstrings of its integrated stub files.
Having said that, the documentation tool window does not require configuring the URL for standard library modules (e.g. for the os, sys, etc...) contrary to how it's necessary for other libraries' External Documentation. In fact, there is no option in the IDE settings to change the address for standard library modules.
What's the right format?
The complete format would be:
https://docs.python.org/{python.version}/library/{module.name}.html#{element.qname}
crack the URL format for Python's os module for use in PyCharm's documentation window.
This can be done, but it is limited to specific modules. It can not be done for the whole standard library because the base Module Name field would have to be left empty and in that case the IDE will ignore the setting.
If you use the hack for a specific module, the IDE will show the docstrings in the documentation tool window (like in example 2) but if you click the external link it will open the browser in the address configured in the external documentation. See the screenshot:
So the hack has limited usefulness.
The hack can be used with offline docs if you download the Python HTML documentation (but it would still be limited to only showing documentation like in example 2). In that use case the correct way to write the URL would depend on OS/Shell/Browser, for Windows/CMD/Firefox you could use the below URL but there's no way to escape the hash # sign so the anchor won't work, but you'll be taken to the documentation page.
file:///C:/directory_name/library/{module.name}.html#{element.qname}

Related

Is it possible to change the way PyCharm displays the OpenCV documentation?

PyCharm (PY-193.6911.25, macOS 10.15.4) doesn't correctly display the OpenCV documentation.
More concretely, this is the result.
As you can see, it's a mess. Is it possible to fix this? I installed OpenCV with pip.
After googling a lot I ended up thinking there is no easy solution but... there actually is!
What i did is:
Push CTRL Q
Scroll down to the trippledot and click open source.
Push CTRL+R(replace)
replace '. ' to ''
Now docstring looks like this:
Definately not perfect, but i think it looks a bit better.
Additionally i added this as external documentation:
https://opencv-python-tutroals.readthedocs.io/en/latest/search.html?q={element.name}&check_keywords=yes&area=default
So it brings up a cv2 'tutorial'...
In PyCharm 2020.1.1 professional edition with Python 3.7, the following warning is displayed for the cv2 docstring
You need configured Python 2 SDK to render Epydoc docstrings
Epydoc is a tool for generating API documentation for Python modules, based on their docstrings.
Pycharm can't render Epydoc docstrings
The suitable interpreter is looked up among those configured in the IDE (it has to be Python 2 since Epydoc package itself hasn't been ported to Python 3 yet). In other words, you need to set up it once so that it showed up on the list at Settings | Project: ... | Project Interpreter | Show All... -- it doesn't need to be actually used in any project. Is it true in your case?
The problem is that it's not really Epytext. OpenCV uses Doxygen for documentation that we don't support and also confuse with Epytext because of the similarity of tags. There is an open issue about it.
Doxygen is confused with Epydoc and displayed as free text (not preformatted)
I'm afraid this particular feature of PyCharm is not really extensible at the moment. Besides, displaying of documentation, injecting references to symbols inside it, completion of available tags and generation of documentation stubs -- everything is tied very closely to the fact that in Python code documentation is normally provided via designated string literals, not comments. The highest level API you can plug into to provide custom documentation source for Quick Documentation popup/tool window is com.intellij.lang.documentation.DocumentationProvider if you register yours before the default one with ID pythonDocumentationProvider. But it will cover only rendering, everything else will need to be written from scratch.
The official resolution is we don't support that

Is there a way to view Python API documentation from within code?

I am looking for a Python IDE that will display the API (standard or third party module) documentations as pop-up when I hover over the code e.g. in eclipse if you hover over the java code it will give you the details of the functions or class, given the API documentation is setup in your IDE.
I can access the documentation from the respective web-site, but this not what I am looking for.
I am using PyCharm Community version, but could not find a way to see the documentation as quick view, also trying to find out if they support such feature at all. Anyone has any experience with any other IDE that will support such feature other than Eclipse.
TIA.
Visual Studio Code Python extension has a feature that will show the documentation of a documented code. Juts type the name of a function or a class and choose the one you want from the autocomplete list.
For example:
Here on the right you can see the code documentation. You can scroll down in that window to see all.
Hope this was helpful.

Autocomplete for Automation objects in VS Code and Python

I have the Python Extensions for Windows installed. Within the PythonWin IDE I can get autocomplete on Automation objects (specifically, objects created with win32com.client.Dispatch):
How can I get the same autocomplete in VS Code?
I am using the Microsoft Python extension.
The Python Windows Extensions has a tool called COM Makepy, which apparently generates Python representations of Automation objects, but I can't figure out how to use it.
Update
Apparently, the Microsoft Python extension uses Jedi for autocompletion.
I've filed an issue on the extension project on Github.
Note that in general I have Intellisense in Python; it's only the Intellisense on Automation objects that I am missing.
Review
I have confirmed your problem in VSCode, although it may be possible IntelliSense works fine. Note Ctrl+Space invokes suggestions for a pre-defined variable:
However, there does not appear to be public attributes available for win32com.client by default. This may be why IntelliSense does not appear to work.
Test
Having installed win32com for Python 3.6, I have confirmed the following code in Jupyter notebook, IPython console and the native Python REPL:
import win32com.client
app = win32com.client.Dispatch("Word.Application")
len(dir(app))
# 55
[x for x in dir(app) if not x.startswith("_")]
# []
This issue of hidden attributes is not a new. Please confirm this test in another environment/IDE. It may be your environment or particular version of PythonWin pre-loads certain variables in the global namespace.
Verify the following:
The Python extension is installed
A Python interpreter is selected
A Python file is selected; this starts up the Python server
References
Post by the extension's creator for troubleshooting autocompletion issues.
Thread on how autocompletion works via PyScriptor
I don't think that the example you show with PythonWin is easily reproducible in VS Code. The quick start guide of win32com itself (cited below) says, its only possible with a COM browser or the documentation of the product (Word in this case). The latter one is unlikely, so PythonWin is probably using a COM browser to find the properties. And because PythonWin and win32com come in the same package, its not that unlikely that PythonWin has a COM browser built in.
How do I know which methods and properties are available?
Good question. This is hard! You need to use the documentation with the
products, or possibly a COM browser. Note however that COM browsers
typically rely on these objects registering themselves in certain
ways, and many objects to not do this. You are just expected to know.
If you wanted the same functionality from the VS Code plugin a COM browser would have to be implemented into Jedi (IntelliSense of the VS Code plugin).
Edit: I found this suggestion, on how a auto-complete, that can find these hidden attributes, could be done:
These wrappers do various things that make static analysis difficult,
unless we were to special case them. The general solution for such
cases is to run to a breakpoint and work in the live runtime state.
The auto-completer should then include the complete list of symbols
because it inspects the runtime.
The conversation is from an mailing list of the python IDE wingwide. Here you can see, that they implemented the above mentioned approach:
I think your problem is related to defining Python interpreter.
Choose proper Python interpreter by executing python interpreter command in VS Code command palette by pressing f1 or ctrl+shift+p key.

Search python docs offline?

In python I can get some rudimentary documentation for any object using help(<object>). But to be able to search the documentation, I have to go online. This isn't really helpful if I'm somewhere where the internet isn't accessible.
In R, there is a handy double question mark feature (??<topic>) that allows me to search through the documentation of all installed libraries for any function that includes <topic> in its name or documentation string. Is there anything similar for python? Perhaps even just for loaded objects?
pydoc comes with python and can do searches but only in the synopsis lines of available modules. Quoting pydoc --help:
pydoc -k
Search for a keyword in the synopsis lines of all available modules.
Note that into pydoc you can perform searches using "/".
Look in the python folder in the folder: Doc. This folder has the entire downloaded documentation of the python docs from python.org. I know this is a VERY late answer, but it brings up an easy solution.
This was mentioned in the comments already: Zeal
is similar to Dash but for Windows/Linux. It uses the same sources as Dash. It's built using Qt and is available in the repositories for several distros, for Ubuntu there is a PPA. Download it here.
Zeal is a simple offline API documentation browser inspired by Dash (OS X app), available for Linux and Windows.
Quickly search documentation using Alt+Space (or customised) hotkey to display Zeal from any place in your workspace.
Search in multiple sets of documentation at once.
Don't be dependent on your internet connection.
Integrate Zeal with Emacs, Sublime Text, or Vim. See Usage » Editor plugins for details.
It is open source (GPL), development happens on GitHub. Zeal uses the same stylesheets/HTML as the online docs, so everything should look familiar.
An in-browser alternative is devdocs.io. You can access the website even if you are offline, provided that you've marked them for local offline storage. You'll need to enable the Python 2 docs, and then mark them for offline storage here. However, as a longtime user of the online Python docs, I find the custom stylesheet that DevDocs uses a bit distracting.
Just to add another option for offline access of python docs (mostly core):
I don't have access to a linux computer at the moment, but on windows, you can navigate to your_python_dist_folder/doc to find some help files. Particularly python275.chm for instance.
If there's no doc folder on your linux machine, you can download the file here and google for a linux chm viewer:
https://www.google.com/search?q=linux+chm+viewer
::Note:
Some distributions also include docs for other packages in there... might be worth a check. Other than that, help(module) usually returns good information.
Edit:
You could get something that might be a little closer to what you want by using pydoc. E.g. you are looking for something about sin in the math module:
import math
import pydoc
[i for i in dir(math) if 'sin' in pydoc.getdoc(getattr(math,i))]
This would return the methods whose docstrings include sin:
['acos', 'acosh', 'asin', 'asinh', 'cos', 'cosh', 'isinf', 'sin', 'sinh']
for which you then could run the help() function
In case your working in a Mac there is Dash, which allows you to download docsets and then explore/search offline. Despite its documentation functionality, Dash is also a Snippet Manager.
Windows Idle - F1 from shell window or editing window gets you a windows help file of all the docs. I think it's better than the online version - it's easier to find stuff.
Although there are certainly better documentations built into your computer than help() like windows idle, another option for some of the more common topics would just be to save some of the online documentation to your computer. For the modules you use a lot and want to access offline, you could just download a text file version of the official online python documentation, which is the best place to get documentation. (file > save page as > select .txt file format)
This may not have been available at the time the question asked and answered, but python.org now makes all the documentation available online as an archive of HTML files which can be navigated and searched offline: https://docs.python.org/2/download.html
(The link directs to docs for the latest version of 2.x, but you can choose 3.x and older 2.x versions from that page)
You should try ipython.
object_name? will print all sorts of details about any object,
including docstrings, function definition lines (for call arguments)
and constructor details for classes.
The magic commands %pdoc, %pdef, %psource and %pfile will respectively print the docstring, function definition line, full source code and the complete file for any object (when they can be found). If automagic is on (it is by default), you don’t need to type the ‘%’ explicitly.

python-mode documentation for Emacs

I just installed the python-mode in Emacs and it seems to be working well. However, I could not find documentation for the package on the official site.
The package comes with a doc folder where I can see two files:
commands-python-mode.org
commands-python-mode.rst
Both files seem to be formatted for some external tool that displays the help text.
With this:
Is there a tool I can use to navigate this documentation?
Does python-mode have an online site with documentation? Any tutorials or good walk-throughs for python-mode for Emacs?
Start off with M-x describe-mode. This gives you an overview over the available key bindings. For each command use C-f name RET to see the built-in documentation. The .org file should be an org-mode file and easily readable with Emacs.
See also here
A cursory inspection of those two files and the code tells me that they're basically a listing of the docstrings found in pymacs.el and python-mode.el. That means you'll be able to access the relevant documentation through M-x apropos or C-h a and friends (specifically, search for ^py or ^pymacs to get a listing of the mode functions).
As a general rule, because elisp doesn't support namespaces, all functions/variables defined by a given mode will have a consistent prefix related to the name of the mode. That makes it fairly simple to search through the Emacs documentation.
If your a emacs user and haven't heard of org-mode before your in for treat.
Open the .org file in emacs and go to org-mode (METAxorg-mode), use TAB on the header lines. Header-lines starts with one or more *.
In addition to answers given: Try a walkthrough of the menu "Python", which appears at the head of window. It will display a short description of the commands or options.
WRT to beginnners, some introduction, examples of basic usage might be given still.
Filed a feature request:
https://bugs.launchpad.net/python-mode/+bug/1281970

Categories

Resources