python-mode gone wrong

November 16, 2012 | categories: Python, Emacs, Programming | View Comments

tl;dr

If you recently upgraded Emacs' python-mode to version 6.0 or higher, and it feels wrong (indentation seems broken, the menu is confusing), downgrade to version 5. In Debian or Ubuntu you can do it like so:

sudo aptitude install python-central pymacs
wget http://launchpadlibrarian.net/22053597/python-mode_5.1.0-1_all.deb
sudo dpkg -i python-mode_5.1.0-1_all.deb

Broken hearts

Something terrible happened. My beloved python-mode for Emacs has been infested with featuritis, and it doesn't look like it's coming back.

Yesterday I upgraded to Xubuntu 12.10 for my work laptop. That was after it turned out that I'm not manly enough to install Debian Wheezy proper. (What the f--k is wrong with your WLAN support, Debian!!)

With Xubuntu and a few tweaks you can luckily ignore all the less fortunate decisions that Ubuntu has made recently. No Unity means no Dash means no broken privacy out of the box.

Synaptic and GDebi are quickly installed to replace the ad-ridden and sluggish Ubuntu Software Center. And packages rock again and are fast. Also, I've come to really like Xfce; but I digress...

So far so good. Then I installed Emacs and python-mode and started editing my first Python file. Which was when I fell into a deep shock. A few things felt just plain wrong. In fact so wrong that I was sure I had the wrong mode active (namely the other python.el, which ships with Emacs). For hours and hours I searched for a way to disable Emacs' own Python mode and enable the "good one", tried some hacks, but it wouldn't work. Because, really I was using the right mode all the time, but python-mode had changed so much I couldn't recognize it anymore.

Firstly, the menu entries are completely different. Instead of the two entries "IM-Python", and "Python" (which I hardly ever used), there's now five different menus called "PyShell", "PyEdit", "PyExec", "PyTools" and "Outline", each with a shitload of entries inside, with mostly either trivial things, or stuff I have no idea what they're good for.

Take an example: The newer python-mode added skeletons. So that now instead of writing a for statement, you can now call up a macro that will ask you what to put into the name and expression parts of the statement, and then it'll write it. Yes, friends, imagine that instead of writing for foo in baz:, you can now call up this insanely useful macro and it will ask you to enter foo and then you hit enter and then it asks for baz, enter, and then it will write the line for foo in baz:.

What the f--k?

Surely, you could say I can ignore all of this seemingly useless functionality. After all, it might be useful to someone (it's NOT!!). But it still leaves a very bad taste in my mouth. I feel alarmed that my beloved python-mode seems to have taken a step into a very bad direction. And I wonder if with all these added features, is it going to be as well-maintained? Is it going to make similar decisions in the future, ones that will affect me more? (This is software that I rely on for my daily work.)

And it looks like my fears are already confirmed. It turns out python-mode gets indentation wrong, arguably the most fundamental feature of any Python editing mode, or has anyway changed the way it works. As an example, if you hit enter where the X is below, it will indent four characters:

class Bar:
    def foo(self):
        pass

Xclass Baz:

So that you'll end up with:

class Bar:
    def foo(self):
        pass

    class Baz:

(Where what you really wanted is put a blank line between them, or maybe add a new method to Bar.)

So what I did after I realized what was going on was to downgrade to python-mode 5.1, and finally my blood pressure went back to normal.

I'd be interested to hear other people's experiences with python-mode 6, I wonder if I'm alone.

Screenshots

Here's the two versions with their respective menus.

python-mode version 5

Simple is better than complex

python-mode version 5

python-mode version 6

F--k simple, let's do a million features because we can

python-mode version 6

Read and Post Comments

Pyramid EuroPython tutorial video

August 16, 2012 | categories: Python, Web, Pyramid, Programming | View Comments

Here's the videos and material for the Writing a Pyramid application tutorial that I gave at last month's EuroPython 2012.

The tutorial is around 3,5 hours long. The accompanying material includes code and documentation for the seven individual steps of the tutorial (ex1_hello through ex7_final).

(Head here if the videos aren't displayed.)

This is the tutorial's complete description of the tutorial from the EuroPython website:

Pyramid is a very general open source Python web framework. As a framework, its primary job is to make it easier for a developer to create an arbitrary web application. The type of application being created isn’t really important; it could be a spreadsheet, a corporate intranet, or a social networking platform. Pyramid is general enough that it can be used in a wide variety of circumstances.

In this tutorial you will build from scratch a simple app in which users each have their individual workspaces, and can invite other users to collaboratively edit content.

While writing the application, you will learn about many aspects of Pyramid. Concretely, you will learn how to:

  • Install Pyramid within a virtualenv
  • Use Pyramid's scaffolds to quickstart your project
  • Work efficiently with templates (using Chameleon)
  • Create models and views
  • Write your own user authentication
  • Make use of Pyramid's Access Control Lists support
  • Use Pyramid's Traversal to map URL paths to your objects
  • Create forms using the deform form library
  • Work with the ZODB, a convenient database to store your Python objects in.

The tutorial will be split into steps with each step accomplishing a certain set of goals. Documented code for all the individual steps, including the final application, will be made available to participants.

Prerequisites: If you're on Mac OSX or Windows and you don't have Python 2.6 or Python 2.7 installed, you might want to run through the Pyramid installation instructions prior to the tutorial.

Read and Post Comments

Kotti Werkpalast Sprint Wrap Up

May 28, 2012 | categories: Python, Web, Pyramid, Programming, Kotti | View Comments

Last week's Kotti sprint in Berlin was full of win. Here's a summary of what we worked on. (Sprinters: If I forgot to mention anything, please let me know and I'll update.)

IMG_0660

Search and kotti_solr

Andi (witsch), Marco and Nuno worked on adding search to Kotti. Kotti now has a search box at the top right of the site that searches the 'title' and 'description' fields of content in the database. A setting called kotti.search_content allows the search function to be overridden. Which is where kotti_solr hooks in to provide search through Solr. kotti_solr has a buildout that installs Solr, and it's already working, but will currently only search the same 'title' and 'description' fields. (That is, it will need to grow adapters so that we can extract all searchable text from content.)

The basic search has already landed in Kotti's master branch in Git and will be available in the next version. There's still a few issues that need to be worked on here before that can happen though:

  • Do permission checks with search results; at the moment search will return all items, whether the user has permission to see them or not. (Maybe this is a good time to consider adding something like CMF's allowedUsersAndRoles index to Kotti's Node.)
  • Document the kotti.search_content setting.

We could also use some help in styling the search box and search results better. You can test drive the search on the demo site.

Snippets, slots and pyramid_snippets

Christian, Florian, Krille and Ibi worked on adding support for what Wordpress calls Shortcodes and MoinMoin calls macros.

With this, users will be able to insert codes like [gallery] into their pages and have these render to dynamic elements in the public view. Shortcodes may also take arguments like [table-of-contents level=3]. We discussed this idea back in February on the list.

The team decided they would move the core functionality behind what they call snippets into a separate package pyramid_snippets. The idea is that snippets behave like views with the advantage that they can be easily pulled in via AJAX and be used in other places in the site, like in the portlet columns. The integration with Kotti is happening in the snippets branch. Plans are to add a button to TinyMCE that allows users to add snippets instead of having to remember the codes and syntax.

We also want to eventually deprecate Kotti's slots and unify them with snippets so that slot renderers will become views and can be used as snippets and vice versa.

Images

Anreas (disko) added a new Image type and image scaling to Kotti core. He extracted these out of the nice kotti_imagegallery add-on that he had written earlier.

Predefined image scales include span1 (60x120) to span12 (1160x2320). Additional image scales can be configured through the kotti.image_scales variables.

Rich text editing

Andreas (disko) and Daniel worked on improving the rich text editing story for Kotti. Based on the work done on images and scaling by Andreas, they created kotti_tinymce, which is an add-on that provides image and file upload, browsing and insertion through TinyMCE.

kotti_tinymce is actually based on the Products.TinyMCE add-on for Plone, and uses the exact same JavaScript resources. Only page templates and CSS are overridden and the server-side AJAX hooks implemented to work with Kotti. (We were quite amazed at how well this worked out.)

One problem with kotti_tinymce is that there's no functional tests. We've just verified that things are working by clicking through all the dialogues manually. Considering that Products.TinyMCE is evolving separately and that we want to maintain upstream compatibility, we really want to implement some browser-based functional tests to be able to guarantee a reasonable level of stability. These tests will also help us fix the remaining bugs in kotti_tinymce.

You can try out the rich text editing improvements on the demo site!

HTTP Caching

Andreas (disko) and Daniel added HTTP caching into the Kotti core. There's now a default caching policy which may be overridden using the kotti.caching_policy_chooser setting. The default policy is to not cache HTML, cache media for four hours, cache static resources for a month and so on.

The http caching code is based on code previously written by Daniel.

Paster templates

Marco and Tom worked on kotti_paster which Marco initially started. They've been working on a set of accumulative templates for Kotti that are based around Buildout and try to define best practices for different aspects of Kotti and Pyramid development for beginners.

IMG_0665

Read and Post Comments

How to write an add-on for the Kotti CMS

November 30, 2011 | categories: Python, Web, Pyramid, Programming | View Comments

This screencast guides you through the process of creating an add-on for the Kotti content management system. In this tutorial we'll write a simple commenting system in 21 minutes in real-time.

You'll be guided through:

  • Installing Kotti itself
  • Creating your own Kotti add-on (a Python package)
  • Configuring your Kotti site to include your add-on

(Click here if you don't see the video.)

Where to go from here

Read and Post Comments

Pyramid is too damn easy - a success story

March 16, 2011 | categories: Python, Web, Pyramid, Programming | View Comments

Note: This isn't a programming tutorial. If you're looking for a tutorial because you want to learn Pyramid on your own, head over to the Tutorials section in the offical Pyramid docs.

Recently, the University of Coimbra in Portugal rolled out a shiny new collection of web apps for students and staff. Users can now access through a single platform:

  • their email account
  • a personalized calendar
  • a homepage app where they can manage their own online presence
  • their profile, as it's stored in the uni's LDAP, which they can update
  • a central panel to manage subscriptions to all Mailman mailing lists available to them
  • a help desk application that integrates with the Request Tracker ticket-tracking system
  • an application to access documents in the KnowledgeTree document management system
http://danielnouri.org/media/uc-apps-menu.png

The apps are demoed (rather quickly) in this Portuguese language video. Skip to 1:23 to see them in action:

(Click here if you don't see the video.)

Mario José Bernardes, the project coordinator, draws a diagram that visualizes the different components involved under the hood:

http://danielnouri.org/media/uc-apps-diagram.png

And what you can see here is in fact implemented as a WSGI pipeline. The three boxes AP1 to AP3 at the bottom are the WSGI apps. In front of that we have PA which is a repoze.who based middleware that provides user authentication and single sign-on through Shibboleth and LDAP. And at the top there is a Deliverance middleware that provides the look & feel as well as the header and footer for all pages, including the menu to navigate between the apps.

http://danielnouri.org/media/uc-apps-pipeline.png

Now what's really remarkable about this project, apart from its brilliant execution, is that it was developed mostly in-house by a small team of developers and admins, most of who hardly knew Python before they started the project.

How did they end up using Python and Pyramid?

The university is a long-time Silva user, using it for their public website for four years now, and they're very happy with it. They knew that they like Python and wanted to use it to solve more problems.

And that's when I got involved. Back in December '09, I was asked to do two Python tutorial sessions with three days each. The trainees were the in-house developers and most of them complete Python newbies. So the first half of the tutorial was an introduction to Python from the ground up and the second half explained WSGI, Paste and Pyramid (which was still repoze.bfg back then).

In parallel to the training sessions, we put our heads together to think about how a Python implementation of their envisioned web apps portal could look like. Back home from Portugal, I went ahead and wrote some of the core utilities and one example app that could be used as a reference point for programmers writing other apps.

And then it happened: After I delivered the first app, things got very silent. I stopped getting calls, no more emails, not even a single postcard! ... until I realized: the team didn't need me anymore. Python and Pyramid were too damn easy! My days as a consultant would soon be counted. :-)

Lessons learned

  • Don't teach Pyramid, you'll become useless soon
  • Instead recommend hard-to-learn frameworks, or better yet, vendor-tied and hard-to-install black boxes
  • Find a new job quick before more people find out about Pyramid

Seriously, what more important metric do we have for choosing one framework over another if not that: How long does it take your team to learn it and be productive with it?

Who did it

These guys rocked apps.uc.pt: Mario José Bernardes, Valentim Branquinho, João Santos, Hugo Branquinho, Pedro Pinheiro, Pedro Almeida and myself.

Read and Post Comments

« Previous Page -- Next Page »