docutils supports adding a wide range of unicode glyphs into documents, while still keeping the source document readable and plain ASCII.
The character mappings are available in include files, and have to be included into the document before being useful.
For example, adding a horizontal arrow is done by including 'isoamsa.txt' which provides (amongst others) the replacement |hArr|. An example document might be:
.. include:: <isoamsa.txt>
This is some text containing an arrow symbol: |hArr|
When using Doctrine 2 with a MySQL Database which has tables with ENUM datatypes, you might run into the following error message:
‘Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.’
This is because Doctrine 2 doesn’t support the ENUM DataType natively as you can read here: Doctrine Cookbook.
In their Doctrine Cookbook they give a solution how you can resolve this by mapping the ENUM to a STRING datatype. But if you’re using Zend Framework 2 you’ll probably run into the same question as I have: where do I put this stuff for it to work?
This might not be the perfect solution, but it worked for me.
Adding the required code to the onBootstrap() method of the Module.php file of the “default” module did the job.
I tend to test my REST services using curl. Most of the time the JSON responses are not pretty-printed, which makes testing larger documents a pain. Copy pasting the results in online JSON formatters was really getting annoying. So I wrote a few lines of python to do that job for me. Note that this is a two-minute-hack and by no means very generic. It works for me, and with curl. The handling for Headers is especially eerie 😛 But maybe you will still find it useful.
See the man page on the details of the extra options.
This will open up port 1080 on your local machine, providing a SOCKS proxy (SOCKS5 if I’m right). You can then specify this in any application supporting SOCKS proxies. This includes Firefox and Chrome. With Firefox it’s straight-forward. You can find it in the usual proxy page in the settings.
For chrome it’s a bit more tricky. While you can specify a SOCKS proxy, it seems to ignore it. If you want to enable your tunnel, you have to run chrome with the following command-line flag:
Once this is set up, what will happen is that your application/browser will send all requests to your locally running SSH instance. This in turn will forward it to the remote host, where the request will be sent out on the web. The response takes the inverse direction. As stated by linode, this is great if you’re on an untrustworthy network!
While cleaning up my build process using ‘closure’, I stumbled across plovr. After using it for only 20 minutes, I am convinced that this should be in the toolbox of *everyone* developing with the closure library!
While the documentation is still a bit sparse, you can have it set up in no time! There’s no need to regurgitate a basic setup example in this post. Everything necessary is readily availble over at http://plovr.com/!
The last hour or so I have been struggling with an “extern” definition using closurebuilder.py. When running the compiler manually, you specify externs like this:
My next step was to verify this by running the compiler manually. And it worked. So, without a doubt, it had something to do with closurebuilder.py. Suspecting a bug, I updated to the latest SVN revision. No luck. Still getting the same error.
So I dug into the code of closurebuilder, and the problem was obvious:
Each additional command-line flag --compiler_flags gets appended to a list. This list is then used as-is in the subprocess call. The subprocess API however expects each argument as a new item in the list. And technically --externs myexterns.js are two arguments. The first is --externs, the second is myexterns.js. The usual --compiler_flags="--compilation_level=ADVANCED_OPTIMIZATIONS" works because it is considered as one argument (it does not contain white-space).
So to get it working properly, you will have to modify the above line to the following:
Whether it makes sense to fix this inside closurebuilder.py is debatable. The arguments need to be passed as a list for security reasons (to be able to do proper shell escaping). Personally I don’t care that I have to specify my compiler flags in this wonky fashion. It’s in a makefile afterall…
Just today I needed to remove files from a package. And I realised that I forgot to mention that removing files from the MANIFEST.in files has a small gotcha… Here’s the small note I added to the original article:
When running the setup script, it will create a folder with the extension .egg-info. If you make changes to your MANIFEST.in file, you should delete this folder. It contains a file named SOURCES.txt which contains all the file in the package. If you remove files from your manifest, the will only disappear when that file is changes as well. So the easiest way is to delete the egg-info folder and let the setup script re-create it!
One of the really useful things in python are the setup scripts. When doing “serious” business, you really should look into them. Setup scripts are amazingly powerful. But they don’t necessarily need to be complex. But because of this flexibility, the documentation around them seems like a lot to read. Additionally, the state of packaging has changed quite a bit over the years. So you now have a couple of packages (distutils, setuptools, distribute) which all seem to try to solve the same problem. See the current state of packaging for more details on this.
This post attempts to summarize the important bits using a “Hello World” project and steeping through the process of creating the setup.py file:
Creating a package distribution
Automatic generation of executables
Version numbers
Dependency management
Publishing your package (thus also making it available for automatic dependency resolution)
Some more food for thought.
NOTE: The setup.py script we will construct in this post, will use two bits of code which may not work in all cases:
importing the package itself (to centralize the version number)
Reading the long_description content from a text-file
Both methodologies have their issues. Importing the package only works if you can import it cleanly (i.e. without dependencies) from standard python. Reading the text file only works if the setup.py is called from the proper location.
This is mostly true. There are corner-cases however where this is not possible. If that is the case, you will need to live without these helpful shortcuts. See the comments on this article for more on this.