YourLabs.org


Showing posts tagged python

Partition your data with django-parting

Just stumbled on django-parting which provides a nice API to partition your data.

For those not familiar with data partitioning, I recommend reading partitionning on mysql.


PyCon 2013 videos are online !

Check them out.


Enable global site packages in an existing virtualenv

Nowadays, virtualenv uses --no-site-packages by default. This means that the created virtualenv will not access global site-packages modules ie. /usr/lib/python2.7/site-packages/.

To enable global site-packages again, just remove this file::

your_env/lib/python2.7/no-global-site-packages.txt

Why would you do that ?

Some modules are complicated to install (xpyb) or take too much time to compile (pyqt). Using the distro packages can be pretty useful !


There’s no magic: virtualenv for beginners

Allison from hacker school published an interesting article about virtualenv for beginners.


Jedi-vim/rope takes too long

For those using jedi-vim are indirectly using rope refactoring library.

If you are also using a home-level virtualenv ie. in ~/env/ then your vim instance might take crazy long time.

First things first, rope creates a .ropeproject directory where it thinks the project root is. And it will scan every file in every sub directory. A quick and dirty solution is to create empty .ropeproject folders lower in the $HOME filesystem. Rope will automatically use this folder if it finds no other .ropeproject folder at a lower level.

But, if you want a home-level .ropeproject, then you should configure ~/.ropeproject/config.py. It is well commented, you might end with something like this:

# Custom source folders:  By default rope searches the project
# for finding source folders (folders that should be searched
# for finding modules).  You can add paths to that list.  Note
# that rope guesses project source folders correctly most of the
# time; use this if you have any problems.
# The folders should be relative to project root and use '/' for
# separating folders regardless of the platform rope is running on.
# 'src/my_source_folder' for instance.
prefs['source_folders'] = ['env/src']

# You can extend python path for looking up modules
prefs['python_path'] = '/home/jpic/env/lib/python2.7/site-packages/'

Playlistnow.fm source code is now open !

Playlistnow.fm is a social network based on music made in Python/Django. The catalog is powered by last.fm and the videos come from youtube.

Before its final death, we decided to release the source code under Apache 2.0 license.


Using Ghost.py to test Django applications with LiveServerTestCase

I’m posting this because it took me quite a few hours to get to this point:

Ghost.py seem to have a nicer API and to be faster than selenium so far.


django-smarter: the CRUD app I’ve been waiting for

django-smarter looks way cool, check it out !


Fantastic python code auto-complete: jedi

It’s been a few days since I’m using jedi auto complete for vim, but for now all I can say is that it’s highly recommendable.

It’s not perfect of course, particularly when it comes to autocompleting self., but still, it’s a great addition to python-mode.


Using rst for documentation on both GitHub and Sphinx/RTFD: code-block tip

Good documentation should be readable from source, and usable to generate fancy HTML. That’s why RST is so commonly used:

  • readable as text source,
  • usable to generate HTML and even PDF
  • GitHub knows how to render it,
  • Sphinx and ReadTheDocs know how to render it.

Good documentation should often show code. This article demonstrates an inconsistency between RTFD and GitHub rendering, and how to fix it.

As far as sphinx is concerned, the default highlight language for code blocks is Python. This will render as Python on Sphinx/RTFD:

Try this example code::

    do_something()

But on GitHub, this will render as plain, sad black text. To fix it, set .. code-block:: python:

Try this example code:

.. code-block:: python

    do_something()

This will enable the right syntax coloration on both GitHub (example) and RTFD (example).

This works with any language ie.:

Try this example python:

.. code-block:: python

    do_something()

Try this example html:

.. code-block:: html

    <input type="text" />

Try this example javascript:

.. code-block:: js

    do_something()

Credits

Thanks to jodal@#readthedocs for helping me debug my docs. Always check that it is rendered properly on GitHub before expecting good rendering on RTFD which is stricter.