Implementing virtualenv with fabric for python projects

I have found this interesting topic in stackoverflow and want to share it as I think its a very good practice.

I just set something like this up at work using pip, Fabric and git. The flow is basically like this, and borrows heavily from this script:

  • In our source tree, we maintain a requirements.txt file. We’ll maintain this manually.
  • When we do a new release, the Fabric script creates an archive based on whatever treeish we pass it.
  • Fabric will find the SHA for what we’re deploying with git log -1 –format=format:%h TREEISH. That gives us SHA_OF_THE_RELEASE
  • Fabric will get the last SHA for our requirements file with git log -1 –format=format:%h SHA_OF_THE_RELEASE requirements.txt. This spits out the short version of the hash, like 1d02afc which is the SHA for that file for this particular release.
  • The Fabric script will then look into a directory where our virtualenvs are stored on the remote host(s).
    • - If there is not a directory named 1d02afc, a new virtualenv is created and setup with pip install -E /path/to/venv/1d02afc -r /path/to/requirements.txt
      - If there is an existing path/to/venv/1d02afc, nothing is done

    The little magic part of this is passing whatever tree-ish you want to git, and having it do the packaging (from Fabric). By using git archive my-branch, git archive 1d02afc or whatever else, I’m guaranteed to get the right packages installed on my remote machines.

    I went this route since I really didn’t want to have extra virtuenvs floating around if the packages hadn’t changed between release. I also don’t like the idea of having the actual packages I depend on in my own source tree.

    Unable to connect to node rabbit@

    My whole day spent by doing http://tinyurl.com/63mlku8
    I have updated my Perl5, updated Erlang. Re-installing Rabbitmq etcetra etcetra.
    But at last I found a work around to get my Rabbitmq working yet know idea why it has happened in the first place.

    Try locating schema.DAT and remove.
    Restart your computer and here you go.

    locate scheme.DAT
    sudo rm -rf schema.DAT

    Hope that helps.

    Clean up deleted remote branch in GIT

    Suppose you have multiple users working on the repo and a user has deleted some unused branches. The other user might still be able to see the remote branches using git branch -r, which is unexpected.

    To clean up deleted remote branch use git remote prune origin, the code will delete all stale tracking branches under origin.

    Also some other important command for pruning:
    git gc --prune=now, gc works as defragment for git files
    git remote rm origin, Remove the remote named . All remote tracking branches and configuration settings for the remote are removed.

    Installing mysql for python throws mysql_config not found

    I am just re-inventing the wheel here. I had this article on this site but the previous hosting was expired and my database file was corrupted, so I had to do this again. And I also know at least one person will be looking for that information soon, so I am contributing to the community again in some simple steps,

      Download the latest version of MySQLdb
      Locate mysql_config locate mysql_config
      Open site.cfg and update mysql_config path
      Run sudo python setup.py build
      Run sudo python setup.py install

    Now if you import MySQLdb in your python CLI it should just work fine. Let me know if you still have some problem. I will try to reshape my reinvented wheel.