Skip to content

Commit

Permalink
Merge pull request #2195 from OmeGak/patch-1
Browse files Browse the repository at this point in the history
Update `cache` argument in docs
  • Loading branch information
liZe authored Jul 3, 2024
2 parents b6b1543 + 1f41486 commit e5fa17e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
8 changes: 4 additions & 4 deletions docs/first_steps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ Image Cache and Optimization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

WeasyPrint provides many options to deal with images: ``optimize_images``,
``jpeg_quality``, ``dpi`` and ``image_cache``.
``jpeg_quality``, ``dpi`` and ``cache``.

``optimize_images`` can enable size optimization for images. When enabled, the
generated PDF will include smaller images with no quality penalty, but the
Expand All @@ -540,7 +540,7 @@ generated PDF.
HTML('https://weasyprint.org/').write_pdf(
'weasyprint.pdf', optimize_images=True, jpeg_quality=60, dpi=150)
``image_cache`` gives the possibility to use a cache for images, avoiding to
``cache`` gives the possibility to use a cache for images, avoiding to
download, parse and optimize them each time they are used.

By default, the cache is used document by document, but you can share it
Expand All @@ -552,12 +552,12 @@ time when you render a lot of documents that use the same images.
cache = {}
for i in range(10):
HTML(f'https://weasyprint.org/').write_pdf(
f'example-{i}.pdf', image_cache=cache)
f'example-{i}.pdf', cache=cache)
It’s also possible to cache images on disk instead of keeping them in memory.
The ``--cache-folder`` CLI option can be used to define the folder used to
store temporary images. You can also provide this folder path as a string for
``image_cache``.
``cache``.


Logging
Expand Down
9 changes: 9 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@ def test_python_render(assert_pixels_equal, tmp_path):
).write_png() == rotated_png_bytes


@assert_no_logs
def test_unknown_options():
with capture_logs() as logs:
pdf_bytes = FakeHTML(string='test').write_pdf(zoom=2, unknown=True)
assert len(logs) == 1
assert 'unknown' in logs[0]
assert pdf_bytes


@assert_no_logs
def test_command_line_render(tmp_path):
css = b'''
Expand Down
2 changes: 2 additions & 0 deletions weasyprint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ def render(self, font_config=None, counter_style=None, **options):
:returns: A :class:`document.Document` object.
"""
for unknown in set(options) - set(DEFAULT_OPTIONS):
LOGGER.warning('Unknown rendering option: %s.', unknown)
new_options = DEFAULT_OPTIONS.copy()
new_options.update(options)
options = new_options
Expand Down
3 changes: 2 additions & 1 deletion weasyprint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ def main(argv=None, stdout=None, stdin=None, HTML=HTML): # noqa: N803
if args.timeout is not None:
url_fetcher = partial(default_url_fetcher, timeout=args.timeout)

options = vars(args)
options = {
key: value for key, value in vars(args).items() if key in DEFAULT_OPTIONS}

# Default to logging to stderr.
if args.debug:
Expand Down

0 comments on commit e5fa17e

Please sign in to comment.