librelist archives

« back to archive

[ANN] Flask-WeasyPrint 0.1

[ANN] Flask-WeasyPrint 0.1

From:
Simon Sapin
Date:
2012-07-19 @ 13:47
Hi Flaskers,

I am glad to announce the first release of Flask-WeasyPrint, a new Flask 
extension that integrates your application with (you guessed it) WeasyPrint.

WeasyPrint is an open-source converter that produces PDF from web 
documents (HTML, CSS, SVG, ...) It is not based on WebKit or Gecko but 
his its own engine in Python, designed for paged media and 
print-specific features.

Flask-WeasyPrint uses Flask’s test client to make requests at the WSGI 
level for URLs that are within the same application. Thus you can for 
example have a PDF document with a vector graph made from a dynamic SVG 
with Pygal, all of this without hitting the network.

Documentation: http://packages.python.org/Flask-WeasyPrint/
Source code and issues: https://github.com/SimonSapin/Flask-WeasyPrint/
Releases: http://pypi.python.org/pypi/Flask-WeasyPrint
WeasyPrint: http://weasyprint.org/
Pygal: http://pygal.org/


I think that Flask-WeasyPrint meets requirements for approved 
extensions, *except* that:

* "python setup.py test" can not install some of WeasyPrint’s 
dependencies: Pango, PyGObject and pycairo do not install with pip/distutils

* Flask-WeasyPrint only support Python 2.6 and 2.7 (not 2.5), ie. the 
versions supported by both Flask and WeasyPrint. (WeasyPrint uses 
__future__.unicode_literals a lot, which is not available on Python 2.5)


Have fun,
-- 
Simon Sapin

Re: [flask] [ANN] Flask-WeasyPrint 0.1

From:
Audrius Kažukauskas
Date:
2012-07-19 @ 18:08
On Thu, 2012-07-19 at 15:47:40 +0200, Simon Sapin wrote:
> Hi Flaskers,
> 
> I am glad to announce the first release of Flask-WeasyPrint, a new Flask 
> extension that integrates your application with (you guessed it) WeasyPrint.
> 
> WeasyPrint is an open-source converter that produces PDF from web 
> documents (HTML, CSS, SVG, ...) It is not based on WebKit or Gecko but 
> his its own engine in Python, designed for paged media and 
> print-specific features.

This looks awesome, pity that I can't try it out, as my Linux distro of
choice (Slackware) doesn't have GTK+3 Python bindings (yet).

BTW, you want to remove trailing colons from decorator lines in your
example.  ;-)

-- 
Audrius Kažukauskas
http://neutrino.lt/

Re: [flask] [ANN] Flask-WeasyPrint 0.1

From:
Simon Sapin
Date:
2012-07-19 @ 18:18
Le 19/07/2012 20:08, Audrius Kažukauskas a écrit :
> This looks awesome, pity that I can't try it out, as my Linux distro of
> choice (Slackware) doesn't have GTK+3 Python bindings (yet).

We only use a few functions from Pango. It could use PyGTK instead of 
PyGObject. (In fact early versions were like that.) But PyGTK officially 
had its last release more than a year ago and using PyGObject instead is 
recommended.

PyGObject and Pango+introspection are also hard to install on OS X. 
Maybe we’ll reconsider and switch back to PyGTK … or maybe support both.

It’s all here, if you’re interested:
https://github.com/Kozea/WeasyPrint/blob/master/weasyprint/text.py


> BTW, you want to remove trailing colons from decorator lines in your
> example.;-)

Good catch, thanks!

-- 
Simon Sapin

Re: [flask] [ANN] Flask-WeasyPrint 0.1

From:
Audrius Kažukauskas
Date:
2012-07-22 @ 18:33
On Thu, 2012-07-19 at 20:18:39 +0200, Simon Sapin wrote:
> Le 19/07/2012 20:08, Audrius Kažukauskas a écrit :
> > This looks awesome, pity that I can't try it out, as my Linux distro of
> > choice (Slackware) doesn't have GTK+3 Python bindings (yet).
> 
> We only use a few functions from Pango. It could use PyGTK instead of 
> PyGObject. (In fact early versions were like that.) But PyGTK officially 
> had its last release more than a year ago and using PyGObject instead is 
> recommended.
> 
> PyGObject and Pango+introspection are also hard to install on OS X. 
> Maybe we’ll reconsider and switch back to PyGTK … or maybe support both.

I figured out that the latest 3.x version of PyGObject can be installed
together with last 2.x release (that's included in Slackware currently),
so I made a package for it.  Now WeasyPrint works.  Will be playing with
it in the next few days.

If there are any Slackware users in this mailing list, here's the
SlackBuild for PyGObject 3.x:

https://bitbucket.org/audriusk/slackbuilds/src/4f97cc81f68e/python/pygobject3

-- 
Audrius Kažukauskas
http://neutrino.lt/

Re: [flask] [ANN] Flask-WeasyPrint 0.1

From:
Simon Sapin
Date:
2012-07-22 @ 18:43
Le 22/07/2012 20:33, Audrius Kažukauskas a écrit :
> I figured out that the latest 3.x version of PyGObject can be installed
> together with last 2.x release (that's included in Slackware currently),
> so I made a package for it.  Now WeasyPrint works.  Will be playing with
> it in the next few days.
>
> If there are any Slackware users in this mailing list, here's the
> SlackBuild for PyGObject 3.x:
>
> https://bitbucket.org/audriusk/slackbuilds/src/4f97cc81f68e/python/pygobject3

Great!

I’m not familiar with Slackware packaging so if you want to write up 
instructions on how to install WeasyPrint on Slackware, I’ll gladly link 
to or copy them. (Otherwise I’ll just link to your package.)

Thanks,
-- 
Simon Sapin

Re: [flask] [ANN] Flask-WeasyPrint 0.1

From:
Audrius Kažukauskas
Date:
2012-07-22 @ 20:22
On Sun, 2012-07-22 at 20:43:54 +0200, Simon Sapin wrote:
> Le 22/07/2012 20:33, Audrius Kažukauskas a écrit :
> > If there are any Slackware users in this mailing list, here's the
> > SlackBuild for PyGObject 3.x:
> >
> > https://bitbucket.org/audriusk/slackbuilds/src/4f97cc81f68e/python/pygobject3
> 
> Great!
> 
> I’m not familiar with Slackware packaging so if you want to write up 
> instructions on how to install WeasyPrint on Slackware, I’ll gladly link 
> to or copy them. (Otherwise I’ll just link to your package.)

SlackBuilds are simple shell scripts which build software and make a
Slackware package out of it.  It's the most common way to create a
package in Slackware world, and many users are familiar with it.  So I
believe that simply linking to it and mentioning that this will build a
package for pygobject 3.x is enough.

That's the only thing I needed to install into my system (besides
virtualenv, which I already had), that wasn't coming from Slackware.
WeasyPrint itself and the rest of its dependencies were installed inside
venv.

I should have noted in my previous mail that this was done using
Slackware-current which is the development branch of next Slackware
version.  This will most likely not work in the last stable version,
because it lacks gobject-introspection package.

-- 
Audrius Kažukauskas
http://neutrino.lt/

Re: [flask] [ANN] Flask-WeasyPrint 0.1

From:
Simon Sapin
Date:
2012-07-22 @ 18:47
Le 22/07/2012 20:33, Audrius Kažukauskas a écrit :
> I figured out that the latest 3.x version of PyGObject can be installed
> together with last 2.x release (that's included in Slackware currently),
> so I made a package for it.  Now WeasyPrint works.  Will be playing with
> it in the next few days.
>
> If there are any Slackware users in this mailing list, here's the
> SlackBuild for PyGObject 3.x:
>
> https://bitbucket.org/audriusk/slackbuilds/src/4f97cc81f68e/python/pygobject3

Also, now that you have this, it’s not really useful to you anymore if I 
add compatibility with PyGTK in WeasyPrint. Or would it still help?

Regards,
-- 
Simon Sapin

Re: [flask] [ANN] Flask-WeasyPrint 0.1

From:
Audrius Kažukauskas
Date:
2012-07-22 @ 20:28
On Sun, 2012-07-22 at 20:47:00 +0200, Simon Sapin wrote:
> Also, now that you have this, it’s not really useful to you anymore if I 
> add compatibility with PyGTK in WeasyPrint. Or would it still help?

Well, as I already noted, this won't work in the last stable version of
Slackware.  And there are probably other Linux distributions still using
the old PyGObject and PyGTK.  Supporting these cases may be useful to
some.

-- 
Audrius Kažukauskas
http://neutrino.lt/

Re: [flask] [ANN] Flask-WeasyPrint 0.1

From:
Simon Sapin
Date:
2012-07-23 @ 19:33
Audrius, I just released WeasyPrint 0.13 which falls back on PyGTK when 
PyGObject 3 is not available. I installed it and ran the test suite on 
Debian stable without problem.

Let me know how it goes if you feel like trying it on Slackware.

Cheers,
-- 
Simon Sapin

Re: [flask] [ANN] Flask-WeasyPrint 0.1

From:
Audrius Kažukauskas
Date:
2012-07-23 @ 20:37
On Mon, 2012-07-23 at 21:33:20 +0200, Simon Sapin wrote:
> Audrius, I just released WeasyPrint 0.13 which falls back on PyGTK when 
> PyGObject 3 is not available. I installed it and ran the test suite on 
> Debian stable without problem.
> 
> Let me know how it goes if you feel like trying it on Slackware.

Installed Flask-WeasyPrint on Slackware 13.37 (full install) inside LXC
container with only virtualenv as additional package.  Example app is
working fine.

Tried running WeasyPrint tests using the following command:

  $ WEASYPRINT_USE_PYGTK=1 py.test

Three tests in tests/test_api.py are failing with the same exception:

  TypeError: Surface.write_to_png takes one argument which must be a
  filename (str), file object, or a file-like object which has a "write"
  method (like StringIO)

Python version is 2.6.6, PyGObject 2.26.0, PyGTK 2.22.0, PyCairo 1.8.10.
If you need more details, let me know.

-- 
Audrius Kažukauskas
http://neutrino.lt/

Re: [flask] [ANN] Flask-WeasyPrint 0.1

From:
Anderson Cardoso
Date:
2012-07-19 @ 20:10
seems, great. A while back I was searching for a solution like that.
att

Anderson

2012/7/19 Simon Sapin <simon.sapin@exyr.org>

> Le 19/07/2012 20:08, Audrius Kažukauskas a écrit :
> > This looks awesome, pity that I can't try it out, as my Linux distro of
> > choice (Slackware) doesn't have GTK+3 Python bindings (yet).
>
> We only use a few functions from Pango. It could use PyGTK instead of
> PyGObject. (In fact early versions were like that.) But PyGTK officially
> had its last release more than a year ago and using PyGObject instead is
> recommended.
>
> PyGObject and Pango+introspection are also hard to install on OS X.
> Maybe we’ll reconsider and switch back to PyGTK … or maybe support both.
>
> It’s all here, if you’re interested:
> https://github.com/Kozea/WeasyPrint/blob/master/weasyprint/text.py
>
>
> > BTW, you want to remove trailing colons from decorator lines in your
> > example.;-)
>
> Good catch, thanks!
>
> --
> Simon Sapin
>



-- 
Anderson Pierre Cardoso
Computer Engineer - University of São Paulo
*
http://www.apierrecardoso.com*
twitter: *@apierre_cardoso* <https://twitter.com/#%21/apierre_cardoso>