pylint + PTVS with IronPython possible?

Jan 9, 2015 at 2:07 PM
Edited Jan 9, 2015 at 2:11 PM
Hello all, I'm posting to enquire whether PTVS with pylint is compatible with projects made for IronPython in Visual Studio.

I have on my machine installed:
  • Team Explorer for Visual Studio 2013
  • PTVS 2013 2.1 with support for IronPython enabled
  • IronPython 2.7 with pylint 1.4.0 (installed in the correct location via:
    "ipy.exe -X:Frames -m ensurepip install pylint" - IIRC
I tried running pylint from the command line on my IronPython projects and it worked fine (when supplied the -X:Frames argument) but the context menu entry for pylint (python -> Run Pylint) is available only for vanilla python projects, not those made for IronPython.

I modified my .proj file to include the support for PTVS by hand, as instructed here but it seems that PTVS is not passing the -X:frame argument specified in the "Interactive Options" window.

I'm getting a well-known errorr:
Error processing line 1 of C:\Program Files (x86)\IronPython 2.7\lib\site-packages\logilab_common-0.63.2-py2.7-nspkg.pth:
  Traceback (most recent call last):
    File "C:\Program Files (x86)\IronPython 2.7\Lib\", line 164, in addpackage
      exec line
    File "<string>", line 1, in <module>
  AttributeError: 'module' object has no attribute '_getframe'
Remainder of file ignored
Unhandled exception:
Traceback (most recent call last):
  File "C:\Program Files (x86)\IronPython 2.7\Lib\", line 175, in run_module
  File "C:\Program Files (x86)\IronPython 2.7\Lib\", line 81, in _run_module_code
  File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\logilab\common\", line 29, in <module>
  File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\", line 675, in <module>
  File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\", line 665, in exec_
  File "C:\Program Files (x86)\IronPython 2.7\Lib\", line 72, in _run_code
  File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pylint\", line 31, in <module>
  File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pylint\checkers\", line 47, in <module>
AttributeError: 'module' object has no attribute '_getframe'
My question is as follows:

Is pylint compatible with IronPython projects?
Can I supply the required -X:Frames argument somehow?
Jan 9, 2015 at 6:34 PM
I cannot really speak for IronPython compatibility with pylint. I would expect it to work, generally speaking, but it's best to ask the IronPython people whether they consider it officially supported.

We don't have any means of specifying interpreter command line arguments that should be applied whenever that interpreter is used (if you look in Tools -> Options -> Python Tools -> Environment Options , we only have a path to interpreter there). If we did have something like that, then we could also change our handling of <CreatePythonCommandItem> to respect those arguments when constructing the command line to invoke Python.

Alternatively - since it really isn't a global option in this case, but pertains to a specific command (and also to a specific interpreter), perhaps we need some means for commands to specify custom interpreter switches on a per-interpreter basis. It should be doable, though coming up with good syntax for it given MSBuild constraints won't be easy.

As a workaround, in the meantime, you can add your own "PyLint (IronPython)" command. Have a look at the existing definition of <CreatePythonCommandItem> that does it for PyLint in C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Python Tools\Microsoft.PythonTools.targets. You'll want to duplicate that, but instead of using TargetType="module", use TargetType="executable", and then you'll need to use the full path to ipy.exe as Target, and prepend -X:Frame -m pylint.lint to arguments. You can place that new command item either directly in that same .targets file (in which case it'll be available for all projects), or just to your own .pyproj.
Feb 17, 2015 at 6:11 PM
Edited Feb 17, 2015 at 6:13 PM
How do you get pylint to work with ironpython? I've been fighting with it, and I can't really find any info on the web about how to make it work....I can only find random posts like this one which seem to hint that it is possible :). When I run pylint on any of my ironpython scripts it can not resolve any of the .NET framework imports...with this error "Unable to import 'System' (import-error)"
Feb 17, 2015 at 9:20 PM
Do you have IronPython set as your active environment when you're running Pylint?
Feb 18, 2015 at 4:55 PM
Yeah, my issue doesn't seem to have anything to do with happens when I manually run pylint from the command line. I've looked into it a bit and it looks like it's (possibly) rooted in the fact that imp.find_module() in IronPython will not find .NET assemblies (even though you can import them directly)....I would have expected imp to have the same behavior as import. I will post this to the IronPython boys and see what they have to say.