Python3 development with Emacs

I am currently working on a mix of Python2/Python3 projects, and as such, I need to find a way to customize a few things on a per-project basis. This post contains notes I'm going to take along the path.

Per-directory variables

Using .dir-locals.el, you can customize things on a per-directory basis. Changes will affect all files in the directory containing this file, and all its subdirectories.

Note: you can use the M-x add-dir-local-variable command to quickly setup dir-locals. You'll be prompted to provide all the required information.

Custom flake8 executable

Set the flycheck-python-flake8-executable variable to the ...

Even better testing, with py.test + tox + travis

I recently wrote a post about using py.test and tox. Now I improved the technique a bit, so here it is a new post with all the recent improvements.

(Please refer to that post for the problems I had to solve, and reasons behind the need of this kind of customizations).

The new test class

In order to properly support Python3, I'm using this test class in my setup.py:

from setuptools.command.test import test as TestCommand

class PyTest(TestCommand):
    test_package_name = 'MyMainPackage'

    def finalize_options(self):
        TestCommand.finalize_options(self)
        _test_args = [
            '--verbose',
            '--ignore=build',
            '--cov={0}'.format(self.test_package_name ...

GitHub-pages-like publishing

I really love using GitHub pages for publishing stuff: I can easily setup the required steps to build & publish my website, and then forget about it.

When I need to make a change, I can just pull the latest copy, do the changes, push back and publish.

No need to remember to update remote copies, restart services, etc.

So, I decided to figure out a way to use the same workflow on my servers too, and this is what I came out with.

First, let me introduce ghp-import

It's a nice script to quickly import a directory in the ...

Auto-starting tmux with panes & services

I'm working on a django-based project that uses celery workers in order to run some heavy tasks. Plus, the UI is built using brunch.

So, each time I want to start all the needed services, I have to:

  • Open a bunch of terminals (usually in a tmux session)
  • Enable virtualenv in each terminal
  • Start the django development server
  • Start a celery worker
  • Start the brunch file-watcher service
  • Maybe open a htop too, just to monitor the resources usage

Of course, I'm not going to do that by hand each time. Instead, I wrote a tmux configuration script ...

Using Apache Tika from Python, with jnius

I needed a library to extract metadata and plaintext transcript from various file formats, for indexing purposes.

After looking around for a while, I found out that Apache Tika might be the right tool for the job (or, at least, it does quite a good job in extracting information from files).

Sadly though, that thing is written in Java.

At first, I tried it by running the jar via subprocess and then parsing the json output. I quickly discarded that approach, as:

  • It required to launch the process twice (once for extracting metadata, and once to extract the plain-text version ...

« Page 2 / 3 »