Monday, April 29, 2013

spyderlib split

[UPDATE 2013-06-03] Spyderlib-2.2.0 has been released and all of the issues mentioned in this post have been resolved! How's that for support! Thanks spyderlib team for being so quick and responsive!

In addition, pdb debugging is now integrated into Spyder with a swank breakpoints window and debug toolbar with standard step, step-in, return & continue buttons. Either it's always been there and I just haven't noticed, or it is something new. So nice! This really makes Spyder a top notch IDE for python and a serious rival to PyDev.

Spyder is the IDE that comes packaged with Python (x, y), and for a community lead project it is a very impressive achievement. For those migrating from MATLAB, they will appreciate the variable explorer, the built in command window, directory and project browser and help.

If only the debugger was better, but it does link to winpdb, which will be more familiar to most MATLAB users than pdb CLI variants. (And now in Spyderlib-2.2.0, it is; see 2013-06-03 update!)

The trouble is that it consistently has little annoying bugs, which in some cases I think are really show stoppers unfortunately. So I recommend that if you are going to rely on Spyder, download the Python (x, y) distribution or the new Enthought Canopy distribution, because they are tested and frozen at releases that are reliable. (True there have been some bugs, but the responsiveness of the Spyderlib developers is fast and courteous. All of my issues have been addressed, and the release cycle is blazingly fast! And so sorry, but Enthought Canopy is **not** free for x64, but Syderlib-2.2.0 has a installer for Windows x64.)

The latest version of Spyder is 2.1.13.1 and like the version before it, there are at least 2 bugs, which intermittantly effect Windows users. The first is the userconfig.py, which will crash the program as soon as it is started, rendering Spyder useless. The fix is simple, apply the patch in comment #7 from issue 1086. The other bug that is not as bad only affects if you try to start Spyder from a BASH console like msysgit Git Bash  or MSYS. For some bizarre reason the shebang for the Spyder script is the WinPython binary, instead of the traditional:
    #! /usr/bin/env python
So just change it to the traditional python shebang and you can now use the script to start spyder from bash.

See updates above. Both these bugs (issue 1086, 1242 &1331) have been resolved in Spyderlib-2.2.0!

Also if you want to use git in Spyder, then apply this patch too, although all it does is start either gitk or git-gui, which is fine and actually better than nothing. (The patch is unnecessary! Just add
C:\Program Files (x86)\Git\cmd\ on Windows x64
or
C:\Program Files\Git\cmd\ on Windows x86
and gitk or git-gui will open from Spyder just fine! The msysgit developers have placed native win32 versions of gitk and git-gui in this folder. Thanks!)

ipdb is soo much nicer than pdb

You use Ipython right? So why not use ipdb, its debugger.

However on Windows you  might have an issue if you call ipdb.set_trace() recursively, where the color coding breaks:
Starting ipdb inside ipython breaks color coding (windows)
The fix may be to comment or alter line 43 in __main__. Or just don't call ipdb.set_trace() in a loop, or from ipython :) .

Or even better use Doug Hellmann's tip and call ipdb from the command line using Python's call module option, `-m`.

Saturday, April 27, 2013

Sphinx domains for MATLAB

[UPDATE 2013-06-20] sphinxcontrib-matlabdomain is now at the cheese factory, so you should be able to install it using Pip or easy_install, or download the and unzip the source and use

>>> python setup.py install

Sphinx is a Python module that generates beautiful documentation using ReStructuredText. It is extensible to other "domains" other than Python. I've made a MATLAB domain that you can install on Bitbucket. Fork or clone it.

To use it you must have Sphinx and its dependencies. Then install the matlabdomain by cloning my fork of the sphinx-contrib repository from Bitbucket. Then run `python setup.py install` from inside the `matlabdomain` directory. If you run `pip freeze` you sill see it listed but there is a warning that the `dependency_links` are not in an svn repository - this is a known bug. After you've run sphinx-quickstart, edit conf.py to include `sphinxcontrib.matlab` in the list of `extensions` and also add the following line:

primary_domain = 'mat'

Voila! You can now document MATLAB in Sphinx, as in the example above. Do note the TODO in matlab.py - I have not added autodocs for MATLAB. It wouldn't make sense anyway, since MATLAB function and class definitions do not use ReStructuredText markup for their H1 and help comment lines.

Sphinx matlabdomain

I wrote a post on installing Sphinx with latex support. Also you will need a working make binary.

Old still shots of demo from before I added the iframe:

Tuesday, April 16, 2013

JGit & MATLAB Matrimony

MATLAB is a Java interpreter. See Java Libraries in MATLAB help. Now it just so happens that there is an excellent Java implementation of Git, the most widely used distributed version control system, called JGit. So it seems obvious that the best way to use Git in MATLAB is with JGit, and it turns out this is surprisingly easy, because JGit has a porcelain class.



I have written a ridiculous wrapper to use JGit in MATLAB that you can clone from Github or download from the MATLAB Central File Exchange. Try my wrapper, but then either contribute or branch out and just use the JGit package. It is surprisingly easy.

NOTE: Did I mention that you do not need to install anything! JGit is your Git client. JGit is not a wrapper for C/C++/Perl scripts. It is a pure Java implementation of Git. That really makes this the one of the easiest way to use Git if you are also using MATLAB.

Enjoy!

Sunday, April 7, 2013

The -mno-cygwin option has been deprecated for years

[UPDATE: 2015-03-19] Yay! Issue #12641 was closed in September-2013, and the latest releases of Python>=2.7.6 no longer have it.

So true. And there's even a bug filed in Python tracker. I also talked about it in this post. Here's how they deal with it in Mercurial (a.k.a. Hg).

# the -mno-cygwin option has been deprecated for years
Mingw32CCompiler = cygwinccompiler.Mingw32CCompiler
class HackedMingw32CCompiler(cygwinccompiler.Mingw32CCompiler):
    def __init__(self, *args, **kwargs):
        Mingw32CCompiler.__init__(self, *args, **kwargs)
        for i in 'compiler compiler_so linker_exe linker_so'.split():
            try:
                getattr(self, i).remove('-mno-cygwin')
            except ValueError:
                passcygwinccompiler.Mingw32CCompiler = HackedMingw32CCompiler

Saturday, April 6, 2013

build python packages with VS2008C++

[UPDATED 2013-04-06]

So you wanted to install jinja (1 not 2) and you typed:
you@box $ pip install jinja
but pip complains, "uh-oh, couldn't find vcvarsall.bat?" Check SO quick. What, Python uses Visual Studio to compile package binaries? True, and it only uses Visual Studio 2008 C++, not VS2010 or VS2012, although you can use MinGW or MinGW-w64 GCC too. But I am already running msysgit, and I don't want another MSYS installation. Don't bother - using mingw/mingw-w64 is a much tougher row to hoe! Check out this newer post on building C-extensions on windows. This will solve all of your problems, and doesn't require you to install any version of the behemoth visual studio!

Friday, April 5, 2013

root permission on VZW DROID RAZR HD


[UPDATED 2012-04-09]
Matt Groff has updated Droid RAZR HD Utility to version 1.20, it includes Dan's motochopper and Motopocalypse a new custom CWM recovery by Hashcode (of safestrap).
Also my phone's touchscreen recently stopped working, out of the blue. I know, very sad, but it was still under warranty so I sent it back - but first I reused Matt's awesome utility to wipe it and reinstall the stock system, kernel, radio and recovery.
I know there are numerous sites that provide the details to unrooting your XT926 (download stock rom, edit xml to remove getvar, install RSD-lite and flash while in fastboot) but Matt's utility takes care of all of that in a single download with a few button clicks.

[UPDATED 2012-04-09]
Dan Rosenberg has cracked the Motorola bootloader for rooted phones only. Hopefully this will be followed by a rash of awesome new ROMS for the RAZR HD.
Today I rooted my Verizon Wireless DROID RAZR HD (JB 4.1.1). This was unbelievably easy to achieve namely thanks to two individuals: djrbliss and mattlgroff.  djrbliss discovered the kernel exploit that he calls motofail2go. I used mattlgroff's Droid RAZR HD Windows Utility 1.10, and the bundled windows drivers, which were insanely easy to follow. Almost a one click root. Verbatim from mattlgroff's xda post:
  1. Fastboot Restore 0.6.25 (ICS 4.0.4 Official Software) - just click
  2. Root for ICS 4.0.4 by djrbliss (motofail2go method) - this involves triggering a bug by pressing several keys at once and a unique vibrate signals the bug report was triggered
  3. Install Voodoo's OTA Rootkeeper App by supercurio - more important than you will ever know
  4. Install Safestrap 3.05.17 App by Hashcode - useful for keeping a stock ICS rom, or trying batakang.
After obtaining root permissions, use Voodoo to "protect root" and then "temp unroot". Now go to settings, about phone and software update. Take all of the OTA's. Do not make any changes to your phone's stock rom until all of the OTA's have installed. Finally go back to Voodoo and "restore root". Q.E.D. For even more detail see Matt's "Best" methods.

Note that once the latest JB 4.1.2 is installed Motorola or Verizon have made it impossible to revert to ICS 4.0.4. Unfortunately this also means that if you have already upgraded you will not be able to "root" your phone (until Motorola releases the bootloader unlock codes).

Also note you are asked to wipe your phone before reverting, and it's probably a good idea, so back up your phone first. Both your internal memory and your sdcard are wiped.

What does root get you? Well not much actually. WiFi tether is now mostly free or you can use OpenGarden or FoxFi. Koush has made a rootless tether. There are only a few roms but the obvious biggy is CM10.1 which is unofficially released for razr hd installed on safestrap, since the bootloader is still locked. Then there's also batakang. I guess the main thing you get is a sense of control over something that you purchased and belongs to you. Pretty vague. Or you could go crazy and start hacking into your phone. I've done worse.

Enjoy!

Fork me on GitHub