Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to register upgrade steps in multiple directories #226

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ Changelog
=========


3.3.2 (unreleased)
3.4.0 (unreleased)
------------------

- Nothing changed yet.
- Added the possibility to group upgrade steps in subdirectories.
Fixes `issue 217 <https://github.com/4teamwork/ftw.upgrade/issues/217>`.
[ale-rt]


3.3.1 (2022-07-08)
Expand Down
33 changes: 29 additions & 4 deletions ftw/upgrade/directory/zcml.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import zope.schema


MIN_VERSION = str(10 ** 13)


class IUpgradeStepDirectoryDirective(Interface):

profile = zope.schema.TextLine(
Expand Down Expand Up @@ -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))
Expand All @@ -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.'
Expand Down Expand Up @@ -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


Expand All @@ -126,4 +151,4 @@ def find_start_version(profile):
if dests:
return max(dests)
else:
return str(10 ** 13)
return MIN_VERSION
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os

version = '3.3.2.dev0'
version = '3.4.0.dev0'

tests_require = [
'ftw.testing >= 2.0.0.dev0',
Expand Down