From e3adac7c0cd92ed24186a525f441c955ba405167 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Tue, 10 Dec 2024 21:42:08 +0100 Subject: [PATCH] Add mini-migrator for xz->liblzma-devel --- conda_forge_tick/make_migrators.py | 3 + conda_forge_tick/migrators/__init__.py | 1 + .../migrators/xz_to_liblzma_devel.py | 31 +++++++ tests/test_xz_liblzma_devel.py | 47 +++++++++++ .../test_yaml/libtiff_with_liblzma_devel.yaml | 82 +++++++++++++++++++ tests/test_yaml/libtiff_with_xz.yaml | 82 +++++++++++++++++++ 6 files changed, 246 insertions(+) create mode 100644 conda_forge_tick/migrators/xz_to_liblzma_devel.py create mode 100644 tests/test_xz_liblzma_devel.py create mode 100644 tests/test_yaml/libtiff_with_liblzma_devel.yaml create mode 100644 tests/test_yaml/libtiff_with_xz.yaml diff --git a/conda_forge_tick/make_migrators.py b/conda_forge_tick/make_migrators.py index 5b9f5dfa9e..5ab32c8492 100644 --- a/conda_forge_tick/make_migrators.py +++ b/conda_forge_tick/make_migrators.py @@ -73,6 +73,7 @@ UpdateCMakeArgsMigrator, UpdateConfigSubGuessMigrator, Version, + XzLibLzmaDevelMigrator, make_from_lazy_json_data, skip_migrator_due_to_schema, ) @@ -385,6 +386,8 @@ def add_rebuild_migration_yaml( piggy_back_migrations.append(RUCRTCleanup()) if migration_name.startswith("flang19"): piggy_back_migrations.append(FlangMigrator()) + if migration_name.startswith("xz_to_liblzma_devel"): + piggy_back_migrations.append(XzLibLzmaDevelMigrator()) piggy_back_migrations = _make_mini_migrators_with_defaults( extra_mini_migrators=piggy_back_migrations ) diff --git a/conda_forge_tick/migrators/__init__.py b/conda_forge_tick/migrators/__init__.py index 488948d2db..13dd0adf4c 100644 --- a/conda_forge_tick/migrators/__init__.py +++ b/conda_forge_tick/migrators/__init__.py @@ -41,4 +41,5 @@ from .replacement import Replacement from .use_pip import PipMigrator from .version import Version +from .xz_to_liblzma_devel import XzLibLzmaDevelMigrator from .noarch_python_min import NoarchPythonMinMigrator diff --git a/conda_forge_tick/migrators/xz_to_liblzma_devel.py b/conda_forge_tick/migrators/xz_to_liblzma_devel.py new file mode 100644 index 0000000000..393bfa8392 --- /dev/null +++ b/conda_forge_tick/migrators/xz_to_liblzma_devel.py @@ -0,0 +1,31 @@ +import os + +from conda_forge_tick.migrators.core import MiniMigrator, skip_migrator_due_to_schema + + +def _parse_xz(lines): + new_lines = [] + for line in lines: + if line.endswith(" xz\n"): + line = line.replace(" xz", " liblzma-devel") + line = line.replace(" xz ", " liblzma-devel ") + new_lines.append(line) + return new_lines + + +class XzLibLzmaDevelMigrator(MiniMigrator): + def filter(self, attrs, not_bad_str_start=""): + host_req = (attrs.get("requirements", {}) or {}).get("host", set()) or set() + return "xz" not in host_req or skip_migrator_due_to_schema( + attrs, self.allowed_schema_versions + ) + + def migrate(self, recipe_dir, attrs, **kwargs): + fname = os.path.join(recipe_dir, "meta.yaml") + if os.path.exists(fname): + with open(fname) as fp: + lines = fp.readlines() + + new_lines = _parse_xz(lines) + with open(fname, "w") as fp: + fp.write("".join(new_lines)) diff --git a/tests/test_xz_liblzma_devel.py b/tests/test_xz_liblzma_devel.py new file mode 100644 index 0000000000..e1c84dd11e --- /dev/null +++ b/tests/test_xz_liblzma_devel.py @@ -0,0 +1,47 @@ +import os + +import pytest +from test_migrators import run_test_migration + +from conda_forge_tick.migrators import Version, XzLibLzmaDevelMigrator + +XZLIBLZMADEVEL = XzLibLzmaDevelMigrator() +VERSION_WITH_XZLIBLZMADEVEL = Version( + set(), + piggy_back_migrations=[XZLIBLZMADEVEL], +) + +YAML_PATH = os.path.join(os.path.dirname(__file__), "test_yaml") + + +@pytest.mark.parametrize( + "old_meta,new_meta,new_ver", + [ + ( + "libtiff_with_xz.yaml", + "libtiff_with_liblzma_devel.yaml", + "4.7.0", + ), + ], +) +def test_liblzma_devel(old_meta, new_meta, new_ver, tmpdir): + with open(os.path.join(YAML_PATH, old_meta)) as fp: + in_yaml = fp.read() + + with open(os.path.join(YAML_PATH, new_meta)) as fp: + out_yaml = fp.read() + + run_test_migration( + m=VERSION_WITH_XZLIBLZMADEVEL, + inp=in_yaml, + output=out_yaml, + kwargs={"new_version": new_ver}, + prb="Dependencies have been updated if changed", + mr_out={ + "migrator_name": Version.name, + "migrator_version": VERSION_WITH_XZLIBLZMADEVEL.migrator_version, + "version": new_ver, + }, + tmpdir=tmpdir, + should_filter=False, + ) diff --git a/tests/test_yaml/libtiff_with_liblzma_devel.yaml b/tests/test_yaml/libtiff_with_liblzma_devel.yaml new file mode 100644 index 0000000000..c0e41b543c --- /dev/null +++ b/tests/test_yaml/libtiff_with_liblzma_devel.yaml @@ -0,0 +1,82 @@ +{% set version = "4.7.0" %} + +package: + name: libtiff + version: {{ version }} + +source: + url: https://download.osgeo.org/libtiff/tiff-{{ version }}.tar.gz + sha256: 67160e3457365ab96c5b3286a0903aa6e78bdc44c4bc737d2e486bcecb6ba976 + patches: + # It seems that a recent patch in tifffile 4.1 may have broken + # binary compatibility on windows. + # https://gitlab.com/libtiff/libtiff/issues/173 + # https://github.com/python-pillow/Pillow/issues/4237 + - patches/use_unix_io.patch + +build: + number: 2 + # Does a very good job of maintaining compatibility. + # Except broke abi between 4.4 and 4.5.0 + # https://github.com/conda-forge/libtiff-feedstock/issues/77 + # https://abi-laboratory.pro/tracker/timeline/libtiff/ + run_exports: + - {{ pin_subpackage('libtiff', max_pin='x.x') }} + missing_dso_whitelist: + # Only used by libtiff,bin/tiffgt (a viewer), which is ok. + - /opt/X11/lib/libGL.1.dylib + - /opt/X11/lib/libglut.3.dylib + +requirements: + build: + - libtool # [unix] + - {{ compiler('c') }} + - {{ stdlib("c") }} + - {{ compiler('cxx') }} + - cmake # [win] + - ninja # [win] + - make # [unix] + host: + - zlib + - libjpeg-turbo + - liblzma-devel + - zstd + - lerc + - libdeflate + - libwebp-base # [linux or osx] + +test: + # TODO: enable this after the release. The ABI broke + # downstreams: + # - pillow >=8 + # - py-opencv >=4 + # - tifffile + commands: + - test ! -f ${PREFIX}/lib/libtiff.a # [not win] + - test ! -f ${PREFIX}/lib/libtiffxx.a # [not win] + - test -f ${PREFIX}/lib/libtiff{{ SHLIB_EXT }} # [not win] + - test -f ${PREFIX}/lib/libtiffxx{{ SHLIB_EXT }} # [not win] + - if not exist %PREFIX%\\Library\\bin\\tiff.dll exit 1 # [win] + - if not exist %PREFIX%\\Library\\bin\\libtiff.dll exit 1 # [win] + # It seems that libtiffxx does not have a dll on windows + # https://gitlab.com/libtiff/libtiff/-/merge_requests/338 + - if not exist %PREFIX%\\Library\\lib\\tiffxx.lib exit 1 # [win] + +about: + home: http://www.libtiff.org/ + license: HPND + license_file: LICENSE.md + summary: Support for the Tag Image File Format (TIFF). + description: | + This software provides support for the Tag Image File Format (TIFF), a + widely used format for storing image data. + doc_url: http://www.libtiff.org/document.html + +extra: + recipe-maintainers: + - jakirkham + - mingwandroid + - msarahan + - ocefpaf + - stuarteberg + - hmaarrfk diff --git a/tests/test_yaml/libtiff_with_xz.yaml b/tests/test_yaml/libtiff_with_xz.yaml new file mode 100644 index 0000000000..40e1fb3c65 --- /dev/null +++ b/tests/test_yaml/libtiff_with_xz.yaml @@ -0,0 +1,82 @@ +{% set version = "4.7.0" %} + +package: + name: libtiff + version: {{ version }} + +source: + url: https://download.osgeo.org/libtiff/tiff-{{ version }}.tar.gz + sha256: 67160e3457365ab96c5b3286a0903aa6e78bdc44c4bc737d2e486bcecb6ba976 + patches: + # It seems that a recent patch in tifffile 4.1 may have broken + # binary compatibility on windows. + # https://gitlab.com/libtiff/libtiff/issues/173 + # https://github.com/python-pillow/Pillow/issues/4237 + - patches/use_unix_io.patch + +build: + number: 2 + # Does a very good job of maintaining compatibility. + # Except broke abi between 4.4 and 4.5.0 + # https://github.com/conda-forge/libtiff-feedstock/issues/77 + # https://abi-laboratory.pro/tracker/timeline/libtiff/ + run_exports: + - {{ pin_subpackage('libtiff', max_pin='x.x') }} + missing_dso_whitelist: + # Only used by libtiff,bin/tiffgt (a viewer), which is ok. + - /opt/X11/lib/libGL.1.dylib + - /opt/X11/lib/libglut.3.dylib + +requirements: + build: + - libtool # [unix] + - {{ compiler('c') }} + - {{ stdlib("c") }} + - {{ compiler('cxx') }} + - cmake # [win] + - ninja # [win] + - make # [unix] + host: + - zlib + - libjpeg-turbo + - xz + - zstd + - lerc + - libdeflate + - libwebp-base # [linux or osx] + +test: + # TODO: enable this after the release. The ABI broke + # downstreams: + # - pillow >=8 + # - py-opencv >=4 + # - tifffile + commands: + - test ! -f ${PREFIX}/lib/libtiff.a # [not win] + - test ! -f ${PREFIX}/lib/libtiffxx.a # [not win] + - test -f ${PREFIX}/lib/libtiff{{ SHLIB_EXT }} # [not win] + - test -f ${PREFIX}/lib/libtiffxx{{ SHLIB_EXT }} # [not win] + - if not exist %PREFIX%\\Library\\bin\\tiff.dll exit 1 # [win] + - if not exist %PREFIX%\\Library\\bin\\libtiff.dll exit 1 # [win] + # It seems that libtiffxx does not have a dll on windows + # https://gitlab.com/libtiff/libtiff/-/merge_requests/338 + - if not exist %PREFIX%\\Library\\lib\\tiffxx.lib exit 1 # [win] + +about: + home: http://www.libtiff.org/ + license: HPND + license_file: LICENSE.md + summary: Support for the Tag Image File Format (TIFF). + description: | + This software provides support for the Tag Image File Format (TIFF), a + widely used format for storing image data. + doc_url: http://www.libtiff.org/document.html + +extra: + recipe-maintainers: + - jakirkham + - mingwandroid + - msarahan + - ocefpaf + - stuarteberg + - hmaarrfk