Stubs for common IronPython CLR assemblies.
These stubs are intended to be used with Atom + autocomplete-python package.
The goal of this project is to develop, consolidate + optimize IronPython stubs, and to provide instructions for how to use them in Atom.
Demo
This project is a fork of the repository started by Gary Edwards on Gitlab. Thank you for your work Gary - and thank you Ehsan for pointing me to it.
It uses PyCharm's Generator3 to create the stubs.
Autocomplete for Python can be quite good and easy to use in an editor like Atom.
The problem comes when you are using IronPython with modules loaded through the Common Language Runtime (clr); the autocomplete engine runs regular python, and regular python cannot access those non-native modules.
The strategy here is simple: Use IronPython to crawl through these libraries, and create 'stubs' or 'mock object' Those 'stubs' can then be used by an autocomplete engine.
This repository contains the code to create the stubs, and also stores an optimized version of them that can be used by autocomplete-python.
Behind the scenes, Atom + autocomplete-python use Jedi to analyze your code and the libraries you are using. The work Jedi's does can be quite expensive. Make sure your computer has plenty of RAM and CPU power.
Once you are setup, the Autocomplete will be a bit slow at first, but it should get better as you use it
and the engine caches the results and indexes the libraries. Jedi's index is saved here:
C:\Users\{username}\AppData\Roaming\Jedi\Jedi\{python-version}
The index can get very large - hundreds of MB up to a few Gigs. That's an issue with the Jedi Autocomplete engine and beyond the scope of this project.
Lastly, some of the stub files created were too large for Jedi to handle (Memory Errors as ram usage spiked up to +10GB).
To get it work smoothly, this project includes an optimized version of the stubs.
This version is the folder called stubs.min
. I highly recommend you use this version as well.
For more information on the 'optimization' see the proces_stubs.py
file.
-
If you haven't yet, install Atom + autocomplete-python (When asked if you want to use Kite or Local Engine, pick local engine)
-
Make sure you have no other autocomplete engine on.
-
At this point, you should make sure you have the autocomplete engine working for the native Python libraries. If it's not I recommend you start with a fresh install of atom and go back to step #1.
- Clone this repository using git or download it from here and unzip it.
- Go to your Atom Settings > Packages > autocomplete-python
- In the package's settings page, we will need to configure the following settings:
First the less important settings:
- Show Descriptions: ON - Recommended Option
- Case Insensitive: ON - Recommended Option
- Fuzzy Matches: ON - Recommended Option
- [required] Autocomplete Function Parameters - Recommended Option
Now to the ones that matter:
-
Use Kite-powered Completion: OFF - Recommended.
-
Output Provider Errors: ON - This will tell you if Jedi runs out of memory.
-
Python Executable Path
You can leave blank, or type in the path to your system's python, for example: C:/Python35/python.exe
If blank, Atom will automatically use your default system's python.
The only thing to be mindful is that you should probably make sure you are running a 64 bit version.
The 32-bit version is limited to 2GB and will likely not be enough for Jedi.
The system version is displayed when you launch python:
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)
< 64 bit
- Extra Paths for Packages
This is the most important setting. This tells the autocomplete engine where to "crawl" to find the stub files.
C:\Path\To\ironpython-stubs\stubs.min
If you have other libraries you would like to add like rpw, you add multiple paths using a semicolon.
C:\Path\To\ironpython-stubs\stubs.min
;
C:\Path\To\revitpythonwrapper.lib
That should be it. Should work like in the images below.
If you haven't yet, read Note on Performance above.
Large Namespaces such as Autodesk.Revit.DB
do not show up right away
The first time you use them could take 5-10 secondes for options to appear.
After the first time, should be quicker (~1 sec.)
clr
autodesk
rhino
You should also be able to use these stubs in Visual Studio Code:
- Install the Python Package
- Follow the instruction on the repository to set the autocomplete
extraPaths
:
"python.autoComplete.extraPaths": ["C:\Path\To\ironpython-stubs\stubs.min"]
- Performance is not great for some of the larger classes. If you know how this can be improved please let me know.
- Some of the function/constructor signatures are missing or incorrect. This is a problem with Generator3. Please send a PR or let me know if you have a fix.
- Many, probably!