From 3ff718e71c92b2e4d47c2f8d2a9a5fa74094db94 Mon Sep 17 00:00:00 2001 From: ale-rt Date: Fri, 25 Jun 2021 09:38:48 +0200 Subject: [PATCH] Allow to register upgrade steps in multiple directories Fixes #217 --- docs/HISTORY.txt | 6 ++++-- ftw/upgrade/directory/zcml.py | 33 +++++++++++++++++++++++++++++---- setup.py | 2 +- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index 091c669..bb975b7 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -2,10 +2,12 @@ Changelog ========= -3.3.1 (unreleased) +3.4.0 (unreleased) ------------------ -- Nothing changed yet. +- Added the possibility to group upgrade steps in subdirectories. + Fixes `issue 217 `. + [ale-rt] 3.3.0 (2022-03-28) diff --git a/ftw/upgrade/directory/zcml.py b/ftw/upgrade/directory/zcml.py index 2aca76c..32f0818 100644 --- a/ftw/upgrade/directory/zcml.py +++ b/ftw/upgrade/directory/zcml.py @@ -18,6 +18,9 @@ import zope.schema +MIN_VERSION = str(10 ** 13) + + class IUpgradeStepDirectoryDirective(Interface): profile = zope.schema.TextLine( @@ -45,7 +48,7 @@ def upgrade_step_directory_handler(context, profile, directory, .split(os.sep)) context.action( - discriminator=('upgrade-step:directory', profile), + discriminator=('upgrade-step:directory', profile, directory), callable=upgrade_step_directory_action, args=(profile, dottedname, context.path(directory), soft_dependencies)) @@ -62,7 +65,14 @@ def upgrade_step_directory_action(profile, dottedname, path, ' upgrade step directory.'.format(profile)) profileinfo = _profile_registry.getProfileInfo(profile) - if profileinfo.get('version', None) is not None: + + # Check that no version is set for the profile in the metadata.xml + # The profile can still have a version set by ftw.upgrade in a previous run + # of this action + if ( + "ftw.upgrade:dependencies" not in profileinfo + and profileinfo.get("version", None) is not None + ): raise UpgradeStepConfigurationError( 'Registering an upgrades directory for "{0}" requires this profile' ' to not define a version in its metadata.xml.' @@ -105,7 +115,22 @@ def upgrade_step_directory_action(profile, dottedname, path, last_version = upgrade_info['target-version'] profile = GlobalRegistryStorage(IProfile).get(profile) - profile['version'] = last_version + profile['version'] = max(last_version, profile.get('version', MIN_VERSION)) + + # Combine the soft dependencies with the one we might have already + # due to this action setting them in a previous run + existing_soft_dependencies = profile.get('ftw.upgrade:dependencies') + if existing_soft_dependencies: + if soft_dependencies: + soft_dependencies = ( + [ + dependency for dependency in soft_dependencies + if dependency not in existing_soft_dependencies + ] + existing_soft_dependencies + ) + else: + soft_dependencies = existing_soft_dependencies + profile['ftw.upgrade:dependencies'] = soft_dependencies @@ -126,4 +151,4 @@ def find_start_version(profile): if dests: return max(dests) else: - return str(10 ** 13) + return MIN_VERSION diff --git a/setup.py b/setup.py index 11898ad..bb33ddc 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages import os -version = '3.3.1.dev0' +version = '3.4.0.dev0' tests_require = [ 'ftw.testing >= 2.0.0.dev0',