diff --git a/.pylintrc b/.pylintrc index a240902..df78819 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,4 +1,4 @@ [MESSAGES CONTROL] -disable = bad-continuation, bad-whitespace, cyclic-import, duplicate-code, fixme, global-statement, line-too-long, missing-docstring, multiple-imports, multiple-statements, too-few-public-methods, too-many-arguments, too-many-branches, too-many-instance-attributes, too-many-locals, too-many-nested-blocks, too-many-statements, too-many-return-statements, unused-wildcard-import, wildcard-import, wrong-import-order, wrong-import-position +disable = cyclic-import, duplicate-code, fixme, global-statement, line-too-long, missing-docstring, multiple-imports, multiple-statements, too-few-public-methods, too-many-arguments, too-many-branches, too-many-instance-attributes, too-many-locals, too-many-nested-blocks, too-many-statements, too-many-return-statements, unnecessary-lambda-assignment, unused-wildcard-import, use-dict-literal, wildcard-import, wrong-import-order, wrong-import-position good-names=db,dx,dy,gs,gv,h,i,j,mz,w,x,x1,x2,y,y1,y2,r,g,b,_GameView diff --git a/pdf_game/js.py b/pdf_game/js.py index a69c9b2..d42f372 100644 --- a/pdf_game/js.py +++ b/pdf_game/js.py @@ -1,7 +1,7 @@ from functools import lru_cache as cached # pylint: disable=no-name-in-module, redefined-outer-name -from pyduktape import DuktapeContext +from pyduktape2 import DuktapeContext from .mod import Proxy from .mod.hero import patch_avatar, patch_info diff --git a/pdf_game/logs.py b/pdf_game/logs.py index a08e317..6c61d46 100644 --- a/pdf_game/logs.py +++ b/pdf_game/logs.py @@ -158,6 +158,7 @@ def _common_gv_ancestor(gv1, gv2): if id(gv2) in gv1_ancestor_ids: return gv2 gv2 = gv2.src_view + return None def diff_game_states(gs1, gs2): diff --git a/pdf_game/mapscript.py b/pdf_game/mapscript.py index bba307f..74ce396 100644 --- a/pdf_game/mapscript.py +++ b/pdf_game/mapscript.py @@ -49,7 +49,6 @@ def mapscript_add_enemy(coords, name, **kwargs): condition = kwargs.pop('condition', None) new_enemy = _make_enemy(name, **kwargs) # cf. https://github.com/PyCQA/pylint/issues/3877 - # pylint: disable=undefined-variable encounter_func = lambda gv, _: _mapscript_encounter_enemy(gv, new_enemy, condition) encounter_func.enemy = new_enemy encounter_func.condition = condition diff --git a/pdf_game/reducer.py b/pdf_game/reducer.py index 92a7c15..091d2a5 100644 --- a/pdf_game/reducer.py +++ b/pdf_game/reducer.py @@ -7,6 +7,8 @@ from contextlib import contextmanager from textwrap import indent +from fpdf.image_datastructures import ImageCache + from .assigner import assign_page_ids from .entities import GameMilestone from .optional_deps import tqdm @@ -87,7 +89,7 @@ def render_victory_noop(*_): pass class FakePdfRecorder: 'Fake fpdf.FPDF class that must implement all the methods used during the pages rendering' def __init__(self): - self.images = {} # images cache used by get_image_info + self.image_cache = ImageCache() self._calls = [] self._links = {} diff --git a/pdf_game/render.py b/pdf_game/render.py index f99a732..cb31ac6 100644 --- a/pdf_game/render.py +++ b/pdf_game/render.py @@ -6,6 +6,7 @@ from PIL.Image import Resampling NEAREST = Resampling.NEAREST except ImportError: # for older versions of Pillow: + # pylint: disable=no-member NEAREST = Image.NEAREST from .bitfont import bitfont_set_color_red, bitfont_render, Justify diff --git a/pdf_game/render_utils.py b/pdf_game/render_utils.py index abe0363..4b12f10 100644 --- a/pdf_game/render_utils.py +++ b/pdf_game/render_utils.py @@ -1,7 +1,7 @@ from .entities import Position from .js import action, REL_RELEASE_DIR -from fpdf.image_parsing import get_img_info +from fpdf.image_parsing import preload_image BACKGROUNDS = 'black,nightsky,tempest,interior'.split(',') @@ -126,12 +126,5 @@ def link_from_page_id(pdf, page_id): def get_image_info(pdf, img_filepath): - # Replicates some logic from FPDF.image(). - # Could be exposed as a FPDF method with a minor refactor. - info = pdf.images.get(img_filepath) - if not info: - info = get_img_info(img_filepath) - pdf.images[img_filepath] = info - info['i'] = len(pdf.images) - info['usages'] = 1 + _, _, info = preload_image(pdf.image_cache, img_filepath) return info diff --git a/requirements.txt b/requirements.txt index 28463a4..49466ad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ fpdf2 humanfriendly # purely optional pillow -pyduktape +pyduktape2 tqdm # purely optional diff --git a/trailer/gen_promo_images.py b/trailer/gen_promo_images.py index 91bec7f..ee78165 100755 --- a/trailer/gen_promo_images.py +++ b/trailer/gen_promo_images.py @@ -17,6 +17,12 @@ from fpdf import FPDF from livereload import Server from PIL import Image +try: + from PIL.Image import Resampling + NEAREST = Resampling.NEAREST +except ImportError: # for older versions of Pillow: + # pylint: disable=no-member + NEAREST = Image.NEAREST from qrcode import QRCode @@ -121,7 +127,7 @@ def gen_card(fpdf): def scale(factor, images): return [img.resize((factor * config().VIEW_WIDTH, factor * config().VIEW_HEIGHT), - resample=Image.NEAREST) for img in images] + resample=NEAREST) for img in images] def title_screen(fpdf, text, sizes=(8,)): assert sizes diff --git a/trailer/img_as_pdf.py b/trailer/img_as_pdf.py index 4351e6c..e0c7762 100644 --- a/trailer/img_as_pdf.py +++ b/trailer/img_as_pdf.py @@ -1,6 +1,12 @@ from contextlib import contextmanager from PIL import Image +try: + from PIL.Image import Resampling + NEAREST = Resampling.NEAREST +except ImportError: # for older versions of Pillow: + # pylint: disable=no-member + NEAREST = Image.NEAREST class ImageAsPdf: @@ -46,7 +52,7 @@ def _image(self, img_added, x=None, y=None, w=0, h=0, link="", title=None, alt_t y = 0 rc_width, rc_height = map(int, (rc_width, rc_height)) # .resize box arg must be an int tuple img_added = img_added.crop((crop_x, crop_y, crop_x + rc_width / scale, crop_y + rc_height / scale))\ - .resize((rc_width, rc_height), resample=Image.NEAREST) + .resize((rc_width, rc_height), resample=NEAREST) else: assert not (w or h), 'Not implemented yet' x, y = map(int, (x, y)) # .paste box arg must be an int tuple