From a8edc17c1895f135caeb9e4f8d3587dc618e84b9 Mon Sep 17 00:00:00 2001 From: Mathias Leimgruber Date: Fri, 1 Sep 2023 11:23:34 -0400 Subject: [PATCH 1/5] Make sure the hash key changes after cropping an image. --- CHANGES.rst | 4 +++ src/plone/app/imagecropping/storage.py | 7 +++++ .../app/imagecropping/tests/test_cropping.py | 28 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 463cff00..9d90e496 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -18,6 +18,10 @@ Bug fixes: [petschki] (#0) +- Make sure the hash key changes after cropping an image. + [mathias.leimgruber] + + Internal: diff --git a/src/plone/app/imagecropping/storage.py b/src/plone/app/imagecropping/storage.py index 4da83ace..0c684863 100644 --- a/src/plone/app/imagecropping/storage.py +++ b/src/plone/app/imagecropping/storage.py @@ -1,3 +1,4 @@ +from Acquisition import aq_base from persistent.dict import PersistentDict from plone.app.imagecropping import PAI_STORAGE_KEY from plone.app.imagecropping.events import CroppingInfoChangedEvent @@ -44,6 +45,12 @@ def store(self, fieldname, scale, box): self.remove(fieldname, scale) key = self._key(fieldname, scale) self._storage[key] = box + + context = aq_base(self.context) + field = getattr(context, fieldname, None) + if field is not None: + field._p_changed = True # Force a new hash key + notify(CroppingInfoChangedEvent(self.context)) def read(self, fieldname, scale): diff --git a/src/plone/app/imagecropping/tests/test_cropping.py b/src/plone/app/imagecropping/tests/test_cropping.py index 057394ab..870ace54 100644 --- a/src/plone/app/imagecropping/tests/test_cropping.py +++ b/src/plone/app/imagecropping/tests/test_cropping.py @@ -9,6 +9,7 @@ from zope.annotation.interfaces import IAnnotations from zope.lifecycleevent import ObjectModifiedEvent +import transaction import unittest @@ -84,6 +85,33 @@ def test_accessing_images(self): "imagescaling does not return cropped image", ) + def test_create_new_key_hash_for_copped_images(self): + """Even though the origunal image did not change, + the cache key needs to change, otherwise cache proxies and browser + don't about the 'new' cropped image. + + Since the original image does not change, we need to force update + the modification (_p_mtime) on the field + + Hint: the has key has the modification time included. + """ + + view = self.img.restrictedTraverse("@@crop-image") + view._crop(fieldname="image", scale="thumb", box=(14, 14, 218, 218)) + transaction.commit() # needed in order to have a _p_mtime on objects + + # another use-case: call plone.app.imaging's ImageScaling view + thumb2 = self.img.restrictedTraverse("@@images") + tag_thumb2 = thumb2.tag(scale="thumb") + + view._crop(fieldname="image", scale="thumb", box=(14, 14, 100, 100)) + transaction.commit() + + thumb3 = self.img.restrictedTraverse("@@images") + tag_thumb3 = thumb3.tag(scale="thumb") + + self.assertNotEqual(tag_thumb2, tag_thumb3) + def test_image_formats(self): """make sure the scales have the same format as the original image""" From 471874eb0aef8b429107f49c233c01be8b6aab47 Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Mon, 11 Sep 2023 11:18:24 +0200 Subject: [PATCH 2/5] `plone/meta` updates --- .editorconfig | 1 + .github/workflows/meta.yml | 10 ++++++++++ .gitignore | 3 +++ .meta.toml | 2 +- .pre-commit-config.yaml | 18 ++++++++++++++---- pyproject.toml | 1 - tox.ini | 19 +++++++++++++++++++ 7 files changed, 48 insertions(+), 6 deletions(-) diff --git a/.editorconfig b/.editorconfig index 919b4116..8ae05aaa 100644 --- a/.editorconfig +++ b/.editorconfig @@ -36,6 +36,7 @@ indent_size = 2 [*.{json,jsonl,js,jsx,ts,tsx,css,less,scss,html}] # Frontend development # 2 space indentation indent_size = 2 +max_line_length = 80 [{Makefile,.gitmodules}] # Tab indentation (no size specified, but view as 4 spaces) diff --git a/.github/workflows/meta.yml b/.github/workflows/meta.yml index 8b320761..39a164d7 100644 --- a/.github/workflows/meta.yml +++ b/.github/workflows/meta.yml @@ -13,6 +13,16 @@ on: - main workflow_dispatch: +## +# To set environment variables for all jobs, add in .meta.toml: +# [github] +# env = """ +# debug: 1 +# image-name: 'org/image' +# image-tag: 'latest' +# """ +## + jobs: qa: uses: plone/meta/.github/workflows/qa.yml@main diff --git a/.gitignore b/.gitignore index d8370c31..3fc10fc3 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ *.pyc *.pyo +# translation related +*.mo + # tools related build/ .coverage diff --git a/.meta.toml b/.meta.toml index 4b36e2ee..be86b0d6 100644 --- a/.meta.toml +++ b/.meta.toml @@ -3,7 +3,7 @@ # See the inline comments on how to expand/tweak this configuration file [meta] template = "default" -commit-id = "c1677eef" +commit-id = "21759c8c" [pyproject] codespell_skip = "*.js,*.min.js,*.min.js.map,*.css.map,yarn.lock,robot_*,test_*" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index df6024cb..d18d2373 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ ci: repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.8.0 + rev: v3.10.1 hooks: - id: pyupgrade args: [--py38-plus] @@ -16,7 +16,7 @@ repos: hooks: - id: isort - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.7.0 hooks: - id: black - repo: https://github.com/collective/zpretty @@ -32,7 +32,7 @@ repos: # """ ## - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 6.1.0 hooks: - id: flake8 @@ -71,10 +71,20 @@ repos: - id: check-python-versions args: ['--only', 'setup.py,pyproject.toml'] - repo: https://github.com/collective/i18ndude - rev: "6.0.0" + rev: "6.1.0" hooks: - id: i18ndude + +## +# Add extra configuration options in .meta.toml: +# [pre_commit] +# i18ndude_extra_lines = """ +# _your own configuration lines_ +# """ +## + + ## # Add extra configuration options in .meta.toml: # [pre_commit] diff --git a/pyproject.toml b/pyproject.toml index ca7e6ab7..4e810fea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -126,7 +126,6 @@ Pillow = ['PIL'] # "gitpython = ['git']", # "pygithub = ['github']", # ] -# """ ## [tool.check-manifest] diff --git a/tox.ini b/tox.ini index 8e8a1bf0..3c0e18c7 100644 --- a/tox.ini +++ b/tox.ini @@ -32,6 +32,13 @@ commands = echo "Unrecognized environment name {envname}" false +[testenv:init] +description = Prepare environment +skip_install = true +commands = + echo "Initial setup complete" + + [testenv:format] description = automatically reformat code skip_install = true @@ -86,11 +93,20 @@ set_env = # test_environment_variables = """ # PIP_EXTRA_INDEX_URL=https://my-pypi.my-server.com/ # """ +# +# Set constrain_package_deps .meta.toml: +# [tox] +# constrain_package_deps = "false" ## deps = zope.testrunner -c https://dist.plone.org/release/6.0-dev/constraints.txt + ## +# Specify additional deps in .meta.toml: +# [tox] +# test_deps_additional = "-esources/plonegovbr.portal_base[test]" +# # Specify a custom constraints file in .meta.toml: # [tox] # constraints_file = "https://my-server.com/constraints.txt" @@ -128,6 +144,7 @@ deps = coverage zope.testrunner -c https://dist.plone.org/release/6.0-dev/constraints.txt + commands = coverage run --branch --source plone.app.imagecropping {envbindir}/zope-testrunner --quiet --all --test-path={toxinidir}/src -s plone.app.imagecropping {posargs} coverage report -m --format markdown @@ -144,6 +161,7 @@ deps = build towncrier -c https://dist.plone.org/release/6.0-dev/constraints.txt + commands = # fake version to not have to install the package # we build the change log as news entries might break @@ -171,6 +189,7 @@ deps = pipdeptree pipforester -c https://dist.plone.org/release/6.0-dev/constraints.txt + commands = # Generate the full dependency tree sh -c 'pipdeptree -j > forest.json' From 451cc2c934e2705414dbe78f32e3cb7374046f17 Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Mon, 11 Sep 2023 11:18:38 +0200 Subject: [PATCH 3/5] CI setup updates --- .github/workflows/tests.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5b3d08e0..06e4e6c0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,10 +19,10 @@ jobs: - "6.0-dev" steps: - uses: actions/checkout@v2 - - uses: nanasess/setup-chromedriver@v1 + - uses: nanasess/setup-chromedriver@v2 - name: Setup Plone ${{ matrix.plone }} with Python ${{ matrix.python }} - uses: plone/setup-plone@v1.0.0 + uses: plone/setup-plone@v2.0.0 with: python-version: ${{ matrix.python }} plone-version: ${{ matrix.plone }} @@ -46,11 +46,12 @@ jobs: run: | make VENV=off lint - - name: Run tests + - name: Start Browser run: | export DISPLAY=:99 chromedriver --url-base=/wd/hub & - sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & - sleep 2 - export ROBOT_BROWSER=headlesschrome & - make VENV=off test-ignore-warnings + sudo Xvfb -ac :99 -screen 0 1920x1280x24 > /dev/null 2>&1 & + + - name: Run tests + run: | + ROBOT_BROWSER=headlesschrome make VENV=off test-ignore-warnings From de2683bbd1f1a6dc8aa7efd850dc863cfb92773b Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Mon, 11 Sep 2023 11:22:23 +0200 Subject: [PATCH 4/5] remove towncrier --- .meta.toml | 2 +- pyproject.toml | 36 ------------------------------------ tox.ini | 5 ----- 3 files changed, 1 insertion(+), 42 deletions(-) diff --git a/.meta.toml b/.meta.toml index be86b0d6..860d66c0 100644 --- a/.meta.toml +++ b/.meta.toml @@ -3,7 +3,7 @@ # See the inline comments on how to expand/tweak this configuration file [meta] template = "default" -commit-id = "21759c8c" +commit-id = "ea1b238f" [pyproject] codespell_skip = "*.js,*.min.js,*.min.js.map,*.css.map,yarn.lock,robot_*,test_*" diff --git a/pyproject.toml b/pyproject.toml index 4e810fea..33bbcc26 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,42 +1,6 @@ # Generated from: # https://github.com/plone/meta/tree/master/config/default # See the inline comments on how to expand/tweak this configuration file -[tool.towncrier] -directory = "news/" -filename = "CHANGES.rst" -title_format = "{version} ({project_date})" -underlines = ["-", ""] - -[[tool.towncrier.type]] -directory = "breaking" -name = "Breaking changes:" -showcontent = true - -[[tool.towncrier.type]] -directory = "feature" -name = "New features:" -showcontent = true - -[[tool.towncrier.type]] -directory = "bugfix" -name = "Bug fixes:" -showcontent = true - -[[tool.towncrier.type]] -directory = "internal" -name = "Internal:" -showcontent = true - -[[tool.towncrier.type]] -directory = "documentation" -name = "Documentation:" -showcontent = true - -[[tool.towncrier.type]] -directory = "tests" -name = "Tests" -showcontent = true - ## # Add extra configuration options in .meta.toml: # [pyproject] diff --git a/tox.ini b/tox.ini index 3c0e18c7..663ca731 100644 --- a/tox.ini +++ b/tox.ini @@ -159,14 +159,9 @@ skip_install = true deps = twine build - towncrier -c https://dist.plone.org/release/6.0-dev/constraints.txt commands = - # fake version to not have to install the package - # we build the change log as news entries might break - # the README that is displayed on PyPI - towncrier build --version=100.0.0 --yes python -m build --sdist --no-isolation twine check dist/* From ca9286485292a5a2c3a8b87fe5e4d82da20e8dfc Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Mon, 11 Sep 2023 11:24:17 +0200 Subject: [PATCH 5/5] remove some unneeded meta jobs --- .github/workflows/meta.yml | 4 ---- .meta.toml | 8 ++++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/meta.yml b/.github/workflows/meta.yml index 39a164d7..cbfcc225 100644 --- a/.github/workflows/meta.yml +++ b/.github/workflows/meta.yml @@ -26,16 +26,12 @@ on: jobs: qa: uses: plone/meta/.github/workflows/qa.yml@main - test: - uses: plone/meta/.github/workflows/test.yml@main coverage: uses: plone/meta/.github/workflows/coverage.yml@main dependencies: uses: plone/meta/.github/workflows/dependencies.yml@main release_ready: uses: plone/meta/.github/workflows/release_ready.yml@main - circular: - uses: plone/meta/.github/workflows/circular.yml@main ## # To modify the list of default jobs being created add in .meta.toml: diff --git a/.meta.toml b/.meta.toml index 860d66c0..baea29aa 100644 --- a/.meta.toml +++ b/.meta.toml @@ -17,3 +17,11 @@ test_* robot_* forest.* """ + +[github] +jobs = [ + "qa", + "coverage", + "dependencies", + "release_ready", + ]