-
-
Notifications
You must be signed in to change notification settings - Fork 705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a --timeout option to the CLI API #1909
Comments
That’s a good idea. It should be possible to pass the default URL fetcher with timeout set to given value in |
Hey, interested in picking this issue |
Cool! Don’t hesitate to ask if you want some hints! |
Wondering if there should be multiple types of timeout options? When looking at Although, I'd also like to have the ability to control the timeouts of individual stages, e.g. I'd also consider what the error behaviour would be? Should that be configurable? Potentially someone doesn't want their entire pdf generation to die if 1 out of 10 images takes longer than 10 seconds to fetch. Seems like an undesirable situation, yes, I wouldn't my company logo to be missing on 1 random report out of 100, however there's always a situation for these things. Perhaps if timeout control is introduced for url fetching, potentially control for retries also needs to be considered? Not sure about the best way to implement this though, as adding 8 new obscure arguments may be overkill and clutter the help menu. On the other hand, all of my favourite CLI tools completely fill my screen when I run |
I think that WeasyPrint can have a An option to control the overall time is useful to, but it’s much harder to implement. Moreover, other tools already exist to handle this, like For more complex cases, we won’t be able to handle everything users will want using simple CLI options. That’s why users can use their own URL fetchers and do whatever they want in Python. So, my advice is to do what’s in the original comment: a |
Hey @MalanB, are you still working on this? If not I would love to have a go at it. |
@azhar316 please go ahead, day job is hectic and I don't seem to find time till now :( |
Thanks! @MalanB Hey @liZe, I have some questions it would be really helpful if you can answer them.
assert_same_renderings = <function assert_same_renderings.<locals>.<lambda> at 0x10ccf4040>
@assert_no_logs
def test_image_exif(assert_same_renderings):
> assert_same_renderings(
'''
<style>@page { size: 10px }</style>
<img style="display: block" src="not-optimized.jpg">
''',
'''
<style>@page { size: 10px }</style>
<img style="display: block" src="not-optimized-exif.jpg">
''',
tolerance=25,
)
@assert_no_logs
def test_font_stretch():
page, = render_pages('''
<style>
p { float: left; font-family: %s }
</style>
<p>Hello, world!</p>
<p style="font-stretch: condensed">Hello, world!</p>
''' % SANS_FONTS)
html, = page.children
body, = html.children
p_1, p_2 = body.children
normal = p_1.width
condensed = p_2.width
> assert condensed < normal
E assert 101.546875 < 101.546875
FAILED tests/draw/test_image.py::test_image_exif - AssertionError: Pixel (8, 8) in image_exif_1: expected rgba(210, 210, 210), got rgba(75, 75, 75)
FAILED tests/layout/test_inline.py::test_font_stretch - assert 101.546875 < 101.546875
url_fetcher = default_url_fetcher
if args.timeout:
url_fetcher = (lambda url, timeout=args.timeout, ssl_context=None:
default_url_fetcher(url, timeout, ssl_context))
del args.timeout is this good or should I explore a different method?
|
Hi @azhar316,
For the second test, you need to install the DejaVu fonts, including condensed ones. I’ve just updated the documentation about that! But for the first one, I’ve never seen someone complain (tests pass for sure on my computer, on Linux distributions packaging platforms and on CI). That’s strange. That’s be interesting to find the reason for that, but you can safely ignore the problem if you don’t want to fall down the rabbit hole!
This idea should work! You can:
That would be complex to test the timeout, but we can at least test that the option is accepted and gives the right document as a first step. |
Will do it as and when I find some time (past one week has been quite hectic work wise!).
Done.
Have added the below lines of code to the 'test_command_line_render' function of 'test_api.py' file: _run('combined.html out23.pdf --timeout 30')
assert tmpdir.join('out23.pdf').read_binary() == pdf_bytes Let me know if this is acceptable. I will create a PR! |
@azhar316 That would be perfect! |
Version 60.1 ------------ Released on 2023-09-29. Bug fixes: * `#1973 <https://github.com/Kozea/WeasyPrint/issues/1973>`_: Fix crash caused by wrong UTF-8 indices Version 60.0 ------------ Released on 2023-09-25. New features: * `#1903 <https://github.com/Kozea/WeasyPrint/issues/1903>`_: Print form fields * `#1922 <https://github.com/Kozea/WeasyPrint/pull/1922>`_: Add support for textLength and lengthAdjust in SVG text elements * `#1965 <https://github.com/Kozea/WeasyPrint/issues/1965>`_: Handle <wbr> tag * `#1970 <https://github.com/Kozea/WeasyPrint/pull/1970>`_: Handle y offset of glyphs * `#1909 <https://github.com/Kozea/WeasyPrint/issues/1909>`_: Add a --timeout option Bug fixes: * `#1887 <https://github.com/Kozea/WeasyPrint/pull/1887>`_: Fix footnote-call displayed incorrectly for some fonts * `#1890 <https://github.com/Kozea/WeasyPrint/pull/1890>`_: Fix page-margin boxes layout algorithm * `#1908 <https://github.com/Kozea/WeasyPrint/pull/1908>`_: Fix IndexError when rendering PDF version 1.4 * `#1906 <https://github.com/Kozea/WeasyPrint/issues/1906>`_: Apply text transformations to first-letter pseudo elements * `#1915 <https://github.com/Kozea/WeasyPrint/pull/1915>`_: Avoid footnote appearing before its call * `#1934 <https://github.com/Kozea/WeasyPrint/pull/1934>`_: Fix balance before "column-span: all" * `#1935 <https://github.com/Kozea/WeasyPrint/issues/1935>`_: Only draw required glyph with OpenType-SVG fonts * `#1595 <https://github.com/Kozea/WeasyPrint/issues/1595>`_: Don’t draw clipPath when defined after reference * `#1895 <https://github.com/Kozea/WeasyPrint/pull/1895>`_: Don’t ignore min-width when computing cell size * `#1899 <https://github.com/Kozea/WeasyPrint/pull/1899>`_: Fix named pages inheritance * `#1936 <https://github.com/Kozea/WeasyPrint/pull/1936>`_: Avoid page breaks caused by children of overflow hidden boxes * `#1943 <https://github.com/Kozea/WeasyPrint/issues/1943>`_: Use bleed area for page’s painting area * `#1946 <https://github.com/Kozea/WeasyPrint/issues/1946>`_: Use margin box of children to define available width for leaders
I'm thinking of something like
weaseyprint --timeout 30 https://weasyprint.org /tmp/weasyprint-website.pdf
The provided value would just have to be passed to the
default_url_fetcher(url, timeout=10, ssl_context=None)
method.The text was updated successfully, but these errors were encountered: