Fixing Python virtualenv on OS X

This weekend I’ve been toying with an old project I created in Django a while (~2 years) ago. The project uses virtualenv, as commonly happens in this kind of projects. The original project was created originally on a different machine, and migrated to the current one. Original machine had OS X Lion, I think… or Snow Leopard, not sure. The point is, the project had been migrated thought 4 or 5 major OS X versions… and Python was a different version from the original one used to create the original virtualenv.

So, back to the problem, trying to use Anaconda for Sublime Text, I found that the Python interpreter I was specifying in the configuration was not working. After some Googling, I found a link (I’m not able to find it again…) on how to troubleshot the configuration, which at the end it boiled down to execute the Python interpreter inside your virtualenv with the following command:

~/Virtualenvs/myvirtualenv/bin/python -c pass

 
In my case, the result was the folling:

dyld: Library not loaded: @executable_path/../.Python
  Referenced from: ~/Virtualenvs/myvirtualenv/bin/python
  Reason: image not found
[1]    74178 trace trap  ~/Virtualenvs/myvirtualenv/bin/python -c pass

 
After some Googling about this problem, I found the following post: “dyld: Library not loaded: @executable_path/../.Python” Basically: “dump the packages configuration, recreate the virtualenv, restore packages, and move everything there”. In my case, the “move everything there” was a bit tricky, and the “restore packages” was even worst, as it was using some unsupported packages which was impossible to install (no pip support, and manually install was quite time consuming…). So, I tried to do something in between, and finally I found the real difference, and the reason the interpreter was failing (notice different python version):

$ ls -la old-virtualenv
...
lrwxr-xr-x   1 myuser  staff      78 29 nov  2014 .Python -> /usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/Python
...

$ ls -la new-virtualenv
...
lrwxr-xr-x   1 myuser  staff      80  5 mai 22:42 .Python -> /usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/Python
...

 
So, the real fix in my case was:

$ cd old-virtualenv
$ rm .Python
$ ln -s /usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/Python .Python

Problems with Instant Run (Android Studio 2.0 beta 4) and Retrofit

This morning I was playing with a toy app I have which uses Retrofit, and I’ve found the following problem with it (and Instant Run):

02-16 07:41:55.550 2976-2976/com.test.android A/art: art/runtime/thread.cc:1329] Throwing new exception 'length=227; index=1017' with unexpected pending exception: java.lang.ArrayIndexOutOfBoundsException: length=227; index=1017

The exception was in the call itself, so it was either Retrofit doing strange things or something deeper. I found the problem to be because of some interaction between ART and Instant Run, and it was already reported.

The original reporter has opened a bug in the AOSP and it’s still unsolved. See also (Retrofit).

All in all, currently there is no fully reliable solution. So, if you find this problem in a call using Retrofit, the best course of action is to disable Instant Run and rebuild. Preferences -> Build, Execution, Deployment -> Instant Run -> (uncheck) Enable Instant Run to hot swap code/resource changes on deploy (default enabled)

Disable Instant Run

Hilarious Git plugin: git-blame-someone-else

This plugin allows to change the commit author information. Super-useful to avoid to be the one to blame for bugs and mistakes. ;)

“I love git-blame-someone-else!!” –Linus Torvalds says*

*Linus Torvalds didn’t really approve of this. It’s a joke to prove it works. See his fake commit here

Kotlin RC and kotlinx

I’ve been toying with Kotlin for a while. Yesterday RC was released, making it one step closer to have a stable version.

One small change that has made me scratch my head a little, even if I read the solution, has been the changes regarding Kotlin Extensions. This had been integrated with the main Kotlin plugin (instead of being a separated plugin) but on RC you need to change your Gradle file a little to keep using it.

The symptom is that you find an “Unresolved reference: kotlinx” plus others that come from the same namespace. Resolution is easy: in the announcement for the release Kotlin 1.0 Release Candidate is Out! in the section Tooling, it reads (bold is mine):

To enable Android Extensions in Gradle in a more idiomatic way, we now say:

apply plugin: 'kotlin-android-extensions'

in the build.gradle file (individually for each project).

The old way doesn’t work any more and prints fixing instructions to the output.

So, I haven’t found this instructions, but the solution is easy: apply the new kotlin-android-extensions plugin right after the kotlin-android plugin in your gradle file. Usually, the end result will be like this:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

After that you just need to sync your Gradle configuration and rebuild the whole project.

FizzBuzz in CSS

Wat

Fun moment: Wat

Re-enabling Xcode plugins

After updating my Xcode, I noticed that plugins got disabled. To reenable them, the easiest way is just “touching” all the plugin directories:

$ cd ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins
$ touch *

After that, restart Xcode and you will get a dialog asking if plugins should be loaded.

An alternate take on this is can be found here: Re-enable Alcatraz on Xcode 6.3.2 or Newer

Additional tip: if the update was the OS, maybe this StackOverflow answer can be also useful: CocoaPods doesn’t work after upgrading Mac OS X EI Capitain.

UPDATE: I’ve updated to Xcode 7.2 today, and suddenly all the plugins stopped to work. There is an update for Alcatraz. See also this tweet.

UPDATE2: There is a new upgrade for Alcatraz for Xcode 7.3. See this tweet. You need to first update it, then “touch” the plugins (see above), execute:

$ defaults delete com.apple.dt.xcodebuild DVTPlugInManagerNonApplePlugIns-xcodebuild-7.3
$ defaults delete com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-7.3

Additionally, I guess that some plugins need an update, because they are not working (for example CocoaPods).