Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 5cae326 point at it.

Merge pull request #110 from krockode/patch-1Armin Ronacherbefore adoption5cae326

lines 1–8why, one step back
1Upgrading To Newer Releases
2===========================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.8

Merge branch '3.x-maintenance'Armin Ronacherbefore adoptiondd51a1d

lines 9–13why, one step back
9.. _upgrade-to-3.2:
1011Upgrading to 3.212----------------13

Merge branch '3.x-maintenance'Armin Ronacherbefore adoption733d5fa

lines 14–20why, one step back
14Click 3.2 had to perform two changes to multi commands which were
15triggered by a change between Click 2 and Click 3 that had bigger16consequences than anticipated.1718Context Invokes19```````````````20

Merge branch '3.x-maintenance'Armin Ronacherbefore adoptiondd51a1d

lines 21–42why, one step back
21Click 3.2 contains a fix for the :meth:`Context.invoke` function when used
22with 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 back
43
44Multicommand 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`.63

Merge branch '3.x-maintenance'Armin Ronacherbefore adoptiondd51a1d

line 64why, one step back
64

Merge pull request #110 from krockode/patch-1Armin Ronacherbefore adoption5cae326

lines 65–70why, one step back
65.. _upgrade-to-2.0:
6667Upgrading to 2.068----------------6970Click 2.0 has one breaking change which is the signature for parameter

Documentation fixesKevin Yapbefore adoption67523af

line 71why, one step back
71callbacks. Before 2.0, the callback was invoked with ``(ctx, value)``

Merge pull request #110 from krockode/patch-1Armin Ronacherbefore adoption5cae326

lines 72–74why, one step back
72whereas now it's ``(ctx, param, value)``. This change was necessary as it
73otherwise made reusing callbacks too complicated.74

Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde

lines 75–76why, one step back
75To ease the transition Click will still accept old callbacks. Starting
76with Click 3.0 it will start to issue a warning to stderr to encourage you

Changed upgrade note to be more correct.Armin Ronacherbefore adoption830ab09

line 77why, one step back
77to upgrade.

Merge pull request #110 from krockode/patch-1Armin Ronacherbefore adoption5cae326

line 78why, one step back
78

Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde

line 79why, one step back
79In case you want to support both Click 1.0 and Click 2.0, you can make a

Merge pull request #110 from krockode/patch-1Armin Ronacherbefore adoption5cae326

lines 80–97why, one step back
80simple 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()97

Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde

line 98why, one step back
98Note that because Click 1.0 did not pass a parameter, the `param` argument

Documentation fixesKevin Yapbefore adoption67523af

line 99why, one step back
99here would be `None`, so a compatibility callback could not use that

Merge pull request #110 from krockode/patch-1Armin Ronacherbefore adoption5cae326

line 100why, one step back
100argument.