

Show HN: Python Tools for Visual Studio - smortaz
http://pytools.codeplex.com

======
smortaz
Hi folks, if you happen to be on Windows & enjoy Python, please check out our
latest release of PTVS. It's a free/OSS plug-in for VS which supports CPython,
IronPython, and the usual Edit/Debug/Profile/etc. now with Django & Client
Libs for Linux & MacOS as well. Another cool feature we've added is the
Parallel Stack / Watch view and Django template intellisense/debugging.

Disclaimer: PTVS is built by few Python/OSS enthusiasts at msft & I'll be
around in case people have any questions!

Cheers.

~~~
shrikant
I'd like to check it out, but was not able find anything on the Codeplex site
about this - does it work with the Express edition of Visual Studio?

~~~
smortaz
toyg is correct. You can use PTVS w the the free "Integrated Shell" which
gives you "Python Express". Please see the installation page on
<http://pytools.codeplex.com>. thx.

~~~
shrikant
Thank you for the info -- I'll give it a whirl.

------
kami8845
One of the few times I've felt jealous as a Linux user :)

Really cool, I love the

    
    
      a={2:42}
      a.values()[0]. <int completion>
    

example. What are the limitations of such a system in Python? Are there cases
where it can be wrong? Can you reveal some more info on how this stuff works
under the hood? Do you execute parts of the code or how do you figure these
relationships out?

Thank you, it's pretty inspirational in regards to how programming in Python
could look like

~~~
DinoV
We don't actually execute any code to figure this out, it's all based upon
analysis of the code.

Basically how it works is that we do an abstract interpretation of the code.
To take this specific example first we analyze the a = {2:42} line, and the
dictionary literal produces a new unique value in the system, and obviously we
know it's key/value types. From there we'll analyze the "a.values" which will
produce a new value in the system for the bound "values" method. Then we do an
abstract call on that, and it says that it returns a list (and goes off to the
original dictionary value, and produces a list which contains the int
objects). And then we do the indexing, and finally we get back the original 42
value that the dictionary was created with. So basically at each step along
the way we are just propagating sets of abstract values. A naive
implementation of a system like this would iterate until it hits a fixed point
- we're a little more sophisticated in that we do a bunch of dependency
tracking to know what needs to be analyzed based upon changes in the system.
And then we also need to deal with a user editing the program in real time
which makes things even more complicated as we need to discard old stale
information which has been propagated from edited files. The actual
implementation of the basic Python semantics is actually the easy part, it's
getting this to perform on large programs and working correctly with live
editing which is the difficult part.

This can go wrong in a couple of ways. First off we don't model control flow,
so you could have something like:

if False: a = 42 else: a = 'bar'

And we'd think that a was an int or a bar. In the future we might model
control flow, but it's a big feature. Mainly I just need an excuse to
implement it :). Another way it could go wrong is if the user is using
exec/eval which we don't have any insight into. And finally there can be
things that we simply don't understand. So while we know about the primitive
types and the methods on them, we don't model all of Python's built-in types.
So for example if you're using deque in collections you won't get the same
results.

All of this is open source (under the Apache license) and the parser and
analysis engine are entirely stand alone components, so they could even be re-
used by other IDEs. You can check out the source code over here:
[http://pytools.codeplex.com/SourceControl/changeset/view/3b8...](http://pytools.codeplex.com/SourceControl/changeset/view/3b84fb3fc36b#Release%2fProduct%2fPython%2fAnalysis%2fAnalysis.csproj)

~~~
sho_hn
That's a nice example and good explanation. We're about in the same spot over
at KDevelop and call a an "unsure (int, string)" there: <http://simplest-
image-hosting.net/png-0-n12983>

Things like incremental reparsing on edits are handled by KDevelop's DUChain
framework, which is shared among the language plugins. The Python language
plugin actually reuses the original CPython parser to do the job, and then
plugs CPython's AST into KDevelop's DUChain representation.

And just to make me feel less like a thread hijacker, let me add that we've
been quite impressed by the work the PTVS team has been doing. You're doing
great things for the Python community over there :).

~~~
DinoV
Thanks, you're making me want to check out KDevelop to compare now. So far I
thought we had the best Python intellisense hands down, but it sounds like
you're a pretty good competitor :)

------
briancurtin
PTVS in VS2012 paired up with ViEmu is probably my favorite setup, although I
still use plain-old-vim fairly often.

I've spent a lot of time in Visual Studio over the years and have come to
really like it when I'm doing C/C++/C#, so when this first came out I jumped
all over it. The recently added feature of creating a project from existing
code is pretty sharp, and removes the need for a third-party "explorer"
plugin.

------
ConstantineXVI
"Send to Interactive"[0]

In general, is there a particular reason we don't see this more often in
tooling for other (REPL-friendly) languages, outside of the Lisps? Admittedly
I haven't spent a significant amount of time in the Python community lately
(so not sure if this is common in Python tooling or not), but after becoming
addicted to SLIME via Clojure, I'd have killed to be able to dump Ruby blocks
from my editor straight to the REPL.

[0]
[http://pytools.codeplex.com/wikipage?title=Features%20Intera...](http://pytools.codeplex.com/wikipage?title=Features%20Interactive%20REPL#SendTo)

~~~
thronemonkey
I'm currently struggling to find a satisfactory IDE for python for this exact
reason. This seemingly obvious feature has to be hacked on to just about every
popular coding tool. The best things I've found so far are the ipython web
notebook (the only problem being that it stores my code as JSON and has
poor/no keybindings) and emacs python-mode (which is buggy as all hell).

NB: The only tool I've ever found that works in the manner I want it to as far
as REPL languages go is RStudio. If I had an RStudio that was language
agnostic so it could work with python, ruby, lisps, or what have you, I would
be a happy, happy man.

edit: if anyone has any suggestions in this regard, please, leave a comment!

~~~
randlet
I use WingIDE's[1] professional version (which includes the editor source
code) and it has the ability to highlight a section and evaluate it either in
the REPL or at the current breakpoint in a debug probe.

It also has decent vi and emacs keybinding support, really nice interactive
debugger (including template debugging for Django) and great intellisense.
It's the best Python IDE I have found, the support is great and I have been a
very happy customer for three years now. (I was using emacs for everything
before).

[1]<http://wingware.com/>

~~~
thronemonkey
Do you know if it supports ipython? I'm on the scientific computing side of
the python world, so django is less important to me . . .

~~~
randlet
It does not unfortunately. You can do interactive matplotlib plotting but it
doesn't behave in the same "shell + REPL" way that ipython does.

------
mahmoudimus
I hope the dev team at Jetbrains are looking at these features for future
integration into PyCharm :)

Good job PTVS team :) You're making me envious!

~~~
smortaz
Thanks! PyCharm, Wing, KDevelop, IPython, Komodo, ... are all pretty darn
good, each with its own strengths. It's a good time to be a Python developer!

------
theboywho
Why is the photo hosted at imgur ? <http://i.imgur.com/tyvjN.png>

~~~
smortaz
You know, I don't have a good answer... I was going to host it on another page
on codeplex, but my teammate insisted on something w a direct link & no misc.
stuff around it. I'll use your comment & tell him "Seeee!" :).

~~~
irahul
I would have said "imgur is great" except it deletes images. Imgur is simple
for the consumer, and you don't pay the bills for bandwidth usage but
<http://imgur.com/faq#long> says if it doesn't get at least 1 view in 6
months, it can deleted.

[http://meta.askubuntu.com/questions/1523/imgur-com-is-
deleti...](http://meta.askubuntu.com/questions/1523/imgur-com-is-deleting-
images)

------
jbevain
Given the very sad state of the extensibility of Visual Studio (I wrote about
it earlier this year [http://evain.net/blog/articles/2012/02/27/visual-studio-
your...](http://evain.net/blog/articles/2012/02/27/visual-studio-youre-doing-
it-wrong)), it turns out that not only are the Python Tools an excellent
plugin to write Python code in VS, it's also one of the best example of how to
implement support for a new language or a debugger in Visual Studio >= 2010.

Some things we do in my product would not have been possible without having
access to the source of the Python Tools (which again say a lot about the sad
story of extending VS).

Shameless plug, if that's still too much work for you, you can contact my
company to integrate your language in VS.

~~~
smortaz
jb - Thanks! Glad that PTVS has been useful in that regard. & yes, VS
Extensibility can be a PITA compared to Eclipse which was built from ground up
with that in mind. They're working on improving it.

------
Jarshwah
Really really impressive! Django development on windows is a PITA (compared to
linux/mac), and all other (free) IDEs that I've taken a look at haven't really
given me too much. I'll definitely give this a go for a test application to
see what it does for me.

~~~
smortaz
Thanks! Would love to get your feedback. Note that you can use PTVS for Django
development/debugging & then push to a cloud of your choice (ie, not Azure) as
well. See this link for some info: [https://www.windowsazure.com/en-
us/develop/python/tutorials/...](https://www.windowsazure.com/en-
us/develop/python/tutorials/django-with-visual-studio/)

~~~
jeromeparadis
What are the clouds of your choice other than Azure? I don't see them
mentioned in the tutorial. I'm on Windows but my Python projects are on a
Ubuntu VM and I push to AWS, Racksace Coud, dedicated servers, etc. My project
can also interact with the shell, phantomjs, node js, Redis, etc. How can I
benefit from the VS IDE for my python projects? I've seen mentions of Linux
clients but not sure what they mean. thanks. I'm dearly looking for a good IDE
with debugging support.

~~~
smortaz
Sorry i should have been more clear. I meant that you can take advantage of
PTVS's editor/intellisense/template debugging facilities for Django, but then
take further steps to push to another cloud yourself. Some folks have used
PTVS this way for their MPI debugging w Linux for example. Also, Amazon has a
good add-in for VS to interface with their cloud which maybe of use in your
scenario: <http://aws.amazon.com/visualstudio/>

------
leddt
Looks great! I don't use Python, but I do use Visual Studio every day and this
looks like a really complete implementation.

Did you find that Visual Studio easy to integrate with, or did you have to
fight it to do what you wanted?

~~~
DinoV
Integrating with VS is definitely a non-trivial task. But I work at Microsoft
and have access to all of the VS source code, so that's a big help. And when
that fails I can usually track down someone who owns that feature. But usually
it's only an issue when going off an implementing some brand new integration
point for the 1st time, most of the time is spent working on our own bits.

------
davidacoder
Earlier releases emphasized NumPy/SciPy for IronPython. Is that effort dead?
There were major holes, like no support for matplotlib, and I had kind of
hoped that these would be filled over time, but now it looks as if the whole
thing is moving into other directions?

~~~
smortaz
David, our group funded that effort (development by Enthought) and the code is
still out there and mostly functional, but it really never got traction. The
1st phase involved major surgery on the NumPy/SciPy libraries which they
needed anyway, so some good came out of it. We'd love to see some kind
volunteers finish the remaining "10" percent. It would be very useful to other
.Net users as well... yeah, I shed a tear :(.

------
bourgeoismedia
Looks pretty neat!

Does it integrate with virtualenv/pip?

~~~
DinoV
There's nothing built-in yet, but we do have a feature tracking it that I'd
encourage you to vote for: <http://pytools.codeplex.com/workitem/691>

The priority of this has gone up for us after PEP 405 but we weren't able to
get to it for 1.5. You can go to Tools->Options->Python Tools->Interpreter
Options and setup a custom interpreter which points to your virtualenv, but we
need to make it easier than doing that.

------
AUmrysh
That kind of reminds me of the IPython notebook. I really like the variable
watching too. Are there any issues using virtualenv with it?

~~~
smortaz
Yup! We're big fans of IPython. So much so that we collaborated with them on
two front2: IPython on Azure (w a Linux or Windows backend):
[https://www.windowsazure.com/en-
us/develop/python/tutorials/...](https://www.windowsazure.com/en-
us/develop/python/tutorials/ipython-notebook/) and directly incorporating its
REPL into PTVS (right window): <http://i.imgur.com/tyvjN.png>

With the IPython notebook on Azure you can basically use Linux/Mac with
Chrome, FF, Safari, ... and have a nice browser based Python IDE and
completely cut Windows & IE out of the picture :).

------
rpm4321
Some kind of interesting stuff, but at $500, and as a freelancer without a
cushy corporate budget, I'll stick with Komodo.

~~~
smortaz
Komodo's a great IDE. PTVS also has a free edition that does everything minus
profiling.

------
borplk
Cool! Pardon my ignorance, but can this be used as a decent Python IDE? Or
does it have a more specific/narrow use case?

~~~
smortaz
It really depends on your definition of decent :). It's built on on VS, so if
you're looking for something extremely lightweight (eg editor++) this isn't
it. OTOH, it has many advanced features such as really good intellisense, MPI
debugging, inline graphics, integrated IPython, Profiling, etc etc. I'd take a
look at the videos on the page & decide for yourself. This should give u a
basic idea:
[http://www.youtube.com/watch?v=7CoGsSlrxKk&hd=1](http://www.youtube.com/watch?v=7CoGsSlrxKk&hd=1)
; more videos on the project home page at <http://pytools.codeplex.com>

edit: missing link.

~~~
borplk
Thanks that was great. Looks very promising. Will try it out.

