upgrading.rst
This file
Path
docs/upgrading.rst
100 lines · 3.7 KiB
Last changed by
Merge branch '3.x-maintenance'Armin Ronacherbefore adoption733d5fa
History of this fileTake it
Updated docs for upgrade information.Armin Ronacherbefore adoptionebde9a0
lines 1–8why, one step back1Upgrading To Newer Releases2===========================34Click attempts the highest level of backwards compatibility but sometimes5this is not entirely possible. In case we need to break backwards6compatibility this document gives you information about how to upgrade or7handle backwards compatibility properly.8Merge branch '3.x-maintenance'Armin Ronacherbefore adoptiondd51a1d
lines 9–13why, one step back9.. _upgrade-to-3.2:1011Upgrading to 3.212----------------13Merge branch '3.x-maintenance'Armin Ronacherbefore adoption733d5fa
lines 14–20why, one step back14Click 3.2 had to perform two changes to multi commands which were15triggered by a change between Click 2 and Click 3 that had bigger16consequences than anticipated.1718Context Invokes19```````````````20Merge branch '3.x-maintenance'Armin Ronacherbefore adoptiondd51a1d
lines 21–42why, one step back21Click 3.2 contains a fix for the :meth:`Context.invoke` function when used22with other commands. The original intention of this function was to23invoke the other command as as if it came from the command line when it24was passed a context object instead of a function. This use was only25documented in a single place in the documentation before and there was no26proper explanation for the method in the API documentation.2728The core issue is that before 3.2 this call worked against intentions::2930 ctx.invoke(other_command, 'arg1', 'arg2')3132This was never intended to work as it does not allow Click to operate on33the parameters. Given that this pattern was never documented and ill34intended the decision was made to change this behavior in a bugfix release35before it spreads by accident and developers depend on it.3637The correct invocation for the above command is the following::3839 ctx.invoke(other_command, name_of_arg1='arg1', name_of_arg2='arg2')4041This also allowed us to fix the issue that defaults were not handled42properly by this function.Merge branch '3.x-maintenance'Armin Ronacherbefore adoption733d5fa
lines 43–63why, one step back4344Multicommand Chaining API45`````````````````````````4647Click 3 introduced multicommand chaning. This required a change in how48Click internally dispatches. Unfortunately this change was not correctly49implemented and it appeared that it was possible to provide an API that50can inform the super command about all the subcommands that will be51invoked.5253This assumption however does not work with one of the API guarantees that54have been given in the past. As such this functionality has been removed55in 3.2 as it was already broken. Instead the accidentally broken56functionality of the :attr:`Context.invoked_subcommand` attribute was57restored.5859If you do require the know which exact commands will be invoked there are60different ways to cope with this. The first one is to let the subcommands61all return functions and then to invoke the functions in a62:meth:`Context.resultcallback`.63Merge branch '3.x-maintenance'Armin Ronacherbefore adoptiondd51a1d
line 64why, one step back64Added notes on callback changes to the docsArmin Ronacherbefore adoptiond27f3a6
lines 65–66why, one step back65.. _upgrade-to-2.0:66Updated docs for upgrade information.Armin Ronacherbefore adoptionebde9a0
lines 67–70why, one step back67Upgrading to 2.068----------------6970Click 2.0 has one breaking change which is the signature for parameterDocumentation fixesKevin Yapbefore adoption67523af
line 71why, one step back71callbacks. Before 2.0, the callback was invoked with ``(ctx, value)``Merge branch 'master' of https://github.com/mitsuhiko/clickArmin Ronacherbefore adoption8bd9f7a
line 72why, one step back72whereas now it's ``(ctx, param, value)``. This change was necessary as itUpdated docs for upgrade information.Armin Ronacherbefore adoptionebde9a0
lines 73–74why, one step back73otherwise made reusing callbacks too complicated.74Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde
lines 75–76why, one step back75To ease the transition Click will still accept old callbacks. Starting76with Click 3.0 it will start to issue a warning to stderr to encourage youChanged upgrade note to be more correct.Armin Ronacherbefore adoption830ab09
line 77why, one step back77to upgrade.Updated docs for upgrade information.Armin Ronacherbefore adoptionebde9a0
line 78why, one step back78Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde
line 79why, one step back79In case you want to support both Click 1.0 and Click 2.0, you can make aUpdated docs for upgrade information.Armin Ronacherbefore adoptionebde9a0
lines 80–97why, one step back80simple decorator that adjusts the signatures::8182 import click83 from functools import update_wrapper8485 def compatcallback(f):86 # Click 1.0 does not have a version string stored, so we need to87 # use getattr here to be safe.88 if getattr(click, '__version__', '0.0') >= '2.0':89 return f90 return update_wrapper(lambda ctx, value: f(ctx, None, value), f)9192With that helper you can then write something like this::9394 @compatcallback95 def callback(ctx, param, value):96 return value.upper()97Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde
line 98why, one step back98Note that because Click 1.0 did not pass a parameter, the `param` argumentDocumentation fixesKevin Yapbefore adoption67523af
line 99why, one step back99here would be `None`, so a compatibility callback could not use thatUpdated docs for upgrade information.Armin Ronacherbefore adoptionebde9a0
line 100why, one step back100argument.