From 34e179a29685bfa0f70992ae2469e7739c5fefe9 Mon Sep 17 00:00:00 2001
From: Amir MOHAMMADI <amir.mohammadi@idiap.ch>
Date: Thu, 9 Sep 2021 16:15:59 +0200
Subject: [PATCH] [click] update to click 8 API

---
 bob/extension/scripts/click_helper.py | 19 ++++++++++++++++---
 conda/meta.yaml                       |  1 +
 setup.py                              |  2 +-
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/bob/extension/scripts/click_helper.py b/bob/extension/scripts/click_helper.py
index b0a4c69..3513954 100644
--- a/bob/extension/scripts/click_helper.py
+++ b/bob/extension/scripts/click_helper.py
@@ -1,5 +1,6 @@
 from ..log import set_verbosity_level
 from ..config import load, mod_to_context, resource_keys
+from click.core import ParameterSource
 import time
 import click
 import logging
@@ -388,6 +389,9 @@ class ResourceOption(click.Option):
             )
         logger.debug("consuming resource option for %s", self.name)
         value = opts.get(self.name)
+
+        source = ParameterSource.COMMANDLINE
+
         # if value is not given from command line, lookup the config files given as
         # arguments (not options).
         if value is None:
@@ -399,13 +403,21 @@ class ResourceOption(click.Option):
         # if not from config files, lookup the environment variables
         if value is None:
             value = self.value_from_envvar(ctx)
+            source = ParameterSource.ENVIRONMENT
+
         # if not from environment variables, lookup the default value
         if value is None:
             value = ctx.lookup_default(self.name)
-        return value
+            source = ParameterSource.DEFAULT_MAP
 
-    def full_process_value(self, ctx, value):
-        value = super().full_process_value(ctx, value)
+        if value is None:
+            value = self.get_default(ctx)
+            source = ParameterSource.DEFAULT
+
+        return value, source
+
+    def type_cast_value(self, ctx, value):
+        value = super().type_cast_value(ctx, value)
 
         # if the value is a string and an entry_point_group is provided, load it
         if self.entry_point_group is not None:
@@ -415,6 +427,7 @@ class ResourceOption(click.Option):
                     entry_point_group=self.entry_point_group,
                     attribute_name=self.name,
                 )
+
         return value
 
 
diff --git a/conda/meta.yaml b/conda/meta.yaml
index efffeb8..be3d13c 100644
--- a/conda/meta.yaml
+++ b/conda/meta.yaml
@@ -20,6 +20,7 @@ requirements:
   host:
     - python {{ python }}
     - setuptools {{ setuptools }}
+    - click >=8
     - click {{ click }}
     - click-plugins {{ click_plugins }}
   run:
diff --git a/setup.py b/setup.py
index b20fb58..d2c8869 100644
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ setup(
     include_package_data=True,
     zip_safe=False,
 
-    install_requires=['setuptools', 'click', 'click-plugins'],
+    install_requires=['setuptools', 'click >= 8', 'click-plugins'],
 
     entry_points={
         'console_scripts': [
-- 
GitLab