Posts about python (old posts, page 42)

2012-12-18 16:58

Rst2pdf 0.93 released

A bit ahead of schedule, I just uploaded version 0.93 of rst2pdf a tool to convert restructured text into PDF files.

Here are some of the changes in this version:

  • Fixed Issue 447: Double-sided always starts on the right (By Rob Ludwick)
    • Removed --first-page-even as it was not used anywhere.
    • Added --first-page-on-right
  • Fixed Issue 464: support alignment via :class: in image directives.
  • Fixed Issue 482: Line blocks with indented parts get extraneous spacing
  • Fixed Issue 470: Support for :target: in figures.
  • New style "image" to be applied to image directives.
  • Fixed Issue 485: Better styling support for figures/images (spaceBefore/After)
  • Support rst2pdf [inf [outf]] syntax to be more compatible with rst2*
  • Implemented Issue 389: New --strip-element-with-class option
  • Fixed Issue 474: CellStyle1 is not there in reportlab 2.6
  • Removed default padding from DelayedTable, which looked bad on headers/footers.
  • Improvements to the math directive (font color and size)
  • Better support for styling literals.
  • Fixed Issue 454 (Splitting failure)
  • Regressed Issue 374 (some literal blocks get oversplit)
  • Switched from svglib to svg2rlg
  • Removed uniconvertor support
  • Fixed Issue 477: Sink footnote separator (patch by asermax)
  • Fixed Issue 473: Support "code" directive like an alias of code-block.
  • Fixed Issue 472: Implemented MyImage._unRestrictSize
  • Fixed Issue 471: Respect class in lineblocks.
  • Fixed Issue 455: New pisa/xhtml2pdf has very different imports
  • Marked Issue 358 as fixed.
  • Fixed Issue 410: always include full lines in code-blocks (mmueller patch)

2012-12-17 16:20

Nikola is Python 2 1/2 ready

On my free time, lunch hours, and such I have been tweaking Nikola, my static site generator to make it python 3 friendly. Well, I somewhat-accidentally-my-dog-made-me-do-it may have committed a lot of that into master.

So, right now, things may be somewhat broken on python2 and somewhat working a little on python3.

In any case, feel free to try it out, and let me know what to fix.

2012-12-13 22:11

Rst2pdf progress

I have set for myself a priority list of bugs that bother me in rst2pdf, my tool to convert restructured text into PDFs in order of decreasing shamefulness.

I have been fixing a few today (early morning + late night hack) so the following is now correct:

  • Use of included stylesheets
  • Vertical spacing of indented lineblocks
  • Use of :target: in figure directives

There are 46 open issues but I am not planning on fixing them all. My personal hitlist has 10 more bugs in it, but regardless of how many I fix, I intend to release anyway, because:

  • Last release is broken with latest reportlab
  • Last release is a bit broken with docutils 0.10 which will be out soon
  • Last release was over six months ago

And that last one is the critical one. Working at Canonical has shown me that release cadence is good. Specially in a project where trunk is very rarely broken (like rst2pdf) there is no reason for slow release cycles. Rst2pdf should release monthly.

I fully intend to take that approach, so the next release will be done on December 21st.

2012-12-11 14:32

¡Python 2 Debe Morir! -- Charla en PyCon Argentina 2012

Spanish post because it's about a video in spanish. Fell free to watch it anyway, of course ;-)


Gracias a los organizadores de PyCon Argentina 2012, ya está disponible el video de mi charla "¡Python 2 debe morir!".

Si quieren ir siguiendo los slides, están acá

Y acá está el video:

No estoy super feliz con mi charla, me veo confuso, con problemas de manejo de tiempo, y muy pelado. Vean los videos de las otras charlas, que están muy buenos! :-)

2012-12-08 22:58

Rst2PDF Release Plans

I have spent a little time on rst2pdf these last few days. It doesn't look too bad, considering the long neglect, but there is some breakage.

After going over almost 300 integration tests by hand, I identified a few regressions (and a couple of bugs that fixed themselves, yay).

So, in order to do a release, I am hoping to fix these:

I probably will not fix them all, and trunk works much better for many cases than 0.92 so I should not block a release on any of these, really. I will give myself a couple of weeks to see how many (if any) I can get done.

On the other hand, if anyone reading this feels adventurous, and wants to lend a hand, help is always welcome.

In the meantime, this is a list of what's changed in trunk from version 0.92:

  • Support rst2pdf [inf [outf]] syntax to be more compatible with rst2*
  • Implemented Issue 389: New --strip-element-with-class option
  • Fixed Issue 474: CellStyle1 is not there in reportlab 2.6
  • Removed default padding from DelayedTable, which looked bad on headers/footers.
  • Improvements to the math directive (font color and size)
  • Better support for styling literals.
  • Fixed Issue 454 (Splitting failure)
  • Switched from svglib to svg2rlg
  • Removed uniconvertor support
  • Fixed Issue 477: Sink footnote separator (patch by asermax)
  • Fixed Issue 473: Support "code" directive like an alias of code-block.
  • Fixed Issue 472: Implemented MyImage._unRestrictSize
  • Fixed Issue 471: Respect class in lineblocks.
  • Fixed Issue 455: New pisa/xhtml2pdf has very different imports
  • Marked Issue 358 as fixed (Literal blocks rendered with large bottom margin)
  • Fixed Issue 410: always include full lines in code-blocks (mmueller patch)

2012-12-04 22:21

New rst2pdf feature: --strip-elements-with-class

First new feature in rst2pdf in a long long time, but it was easy to do, and there was an actual user needing it.

This exposes functionality rst2html already had, so that's probably why it was easy to do ;-)

In any case, what is it and what is it good for?

If you mark something with a class, you can now omit it from the output:

.. class:: ignored

This will not be in the output if you use --strip-elements-with-class=ignored

And it's useful, for example, so you can keep slides and presentation notes in the same file. You just put your notes in a class you strip when producing the slides.

Since some classes are automatically assigned for admonitions, this is extra simple:

.. note:: This is a note admonition.

   Note admonitions always have the note class. So you can strip them easily.

And if you don't strip them, they will look pretty.

2012-12-03 14:11

Nikola v5 Released

A new version of Nikola is out! You can get it at the usual place.

This version is not completely backwards compatible, thus the new major version number, but switching to it should be easy-ish. If you are using version 4.0.3:

  1. Remove your dodo.py
  2. Use nikola build instead of doit from now on
  3. use nikola serve instead of doit serve, nikola new_post instead of doit new_post, and so on. Some other doit task are also converted into nikola command you can get the list using nikola help

The integration of doit into Nikola is not done in a very nice way, that's still ongoing work, but it should be Good Enough To Work (TM).

Hope you enjoy this release!

Features

  • Templates now know their name from template_name in their context.
  • Made most of Nikola into Yapsy plugins.
  • Recurse galleries/ and render each folder as a gallery.
  • Breadcrumbs and folder links in image galleries.

Bugfixes

  • Fixed doc installation
  • Put webassets cache in cache/webassets
  • Update to doit 0.17
  • Don't crash on incomplete translations
  • Fixed Issue 160: render_tags didn't call scan_posts()
  • Fixed Issue 161: webassets setting USE_BUNDLES was ignored (fix by schettino72)
  • Fixed Issue 153: index.txt was being ignored in galleries.

2012-09-11 18:50

Nikola is Pluginificated.

So, the git master of Nikola now has plugins. In fact, not only does it have plugins, but is basically made of plugins.

You see, the code used to mostly be inside a class (called Nikola), and ... it had grown. That class had grown up to around 2000 lines of code. Which is completely ridiculous.

So, using Yapsy I turned the code inside out: almost all the code that was in that monster class was moved into plugins and the class turned into a smart plugin loader.

This has brought several advantages:

  • Now you can extend Nikola for your own purposes. Just create a plugin folder in your site, and put the extra functionality there.
  • Support for whole categories of things is now modular. Want to support a different markup? A different template system? Just write a plugin.
  • Want to add completely new functions to Nikola? Like, say, a way to import data from another blog tool, or something like planet software? Well, just add a "command plugin".

What has changed for the user?

  • You can delete dodo.py from your site.
  • Use nikola build instead of doit
  • Use nikola serve instead of doit serve

Some minor things still need doing in this area (notable, fixing the docs), but the main refactoring is there.

2012-09-05 10:13

Taxes, Game Theory, and Python (Part 1 of 2)

Let's consider the following scenario, based completely on things I know, not things I do ;-)

Suppose that in a city called San Isidro, there is a house. Houses in San Isidro pay a municipal tax, in exchange for the service of garbage collection, street sweeping, tree trimming, and street lighting.

It's a very small tax, but let's say it's $100 a month because it's a nice, easy to handle number.

Also, San Isidro is in a country called Argentina. In that country there are several laws that affect the home owners:

  1. You can't sell a house if you owe any taxes.
  2. The owner has a 1% chance of wanting to sell the house each month.
  3. Debts expire after 5 years.
  4. If you are sued and you lose, you pay they other guy's lawyer fees.
  5. Lawyer fees are capped to 25% of the money being disputed.
  6. Lawyers are reluctant to help you sue someone if they get very little money (defined as less than $2000)
  7. If sued by the city for owed taxes, the owner always loses.
  8. Unpaid taxes accrue 2% compound interest monthly. So, if you don't pay your $100, you will owe $102, then $104.04, $106.0128 etc.

With all those elements in place, let's play a game called "Tax Golf"!

The game is played by an indetermined number of players called owners and one special player called city.

The game is played to 100 "months" or until all property has been sold.

The goal of the game, for the owners, is to pay as little money as they can. The score is calculated like this: amount of money you paid divided by the time you owned the house.

The owner with the lowest score is the winner.

The goal of the game for the city, is to get as much money as he can. He's not competing against the players, for him it's a sort of solitaire where he competes against his past performance.

This, my friends is math. Math is a tool that helps you (among other things) do the right thing in this sort of complicated, arbitrary, real life scenario.

So, what's a good strategy for a owner, and for the city?

In a second post next wednesday, I will give some answers to those questions, using python.

2012-09-03 21:47

Improved Wordpress.com Importer and a Question

So, if you were to try to use nikola_wordpress_importer from master now, it would:

  1. Not crash ;-)
  2. Download attachments
  3. Fix links to attachments so they work on the new site

However, I am now unsure of what exactly is in wordpress.com's export XML file. The posts themselves are in this form:

Muchas gracias Nico por hacer el video este. Groso, quedó muy bueno.

[youtube=http://www.youtube.com/watch?hl=es&v=882qxARXa6c]

Two things jump to me:

  1. That's not HTML
  2. WTF is that youtube thing?

I am having some success processing it as markdown, since that handles the paragraph breaks and some other stuff. Maybe the youtube embedding is done with a markdown extension?

Anyone knows?

Contents © 2000-2018 Roberto Alsina