From 13ab5635b4a6794c41c5451f2b70a686c9d9d904 Mon Sep 17 00:00:00 2001 From: Jason Gross Date: Mon, 15 Jul 2024 15:03:44 -0700 Subject: [PATCH 1/2] Compat with webcolors v24.6.0 Work around https://github.com/ubernostrum/webcolors/commit/68ba427417b6065684a162f1484c45886a401a85 / https://github.com/ubernostrum/webcolors/issues/20 --- src/tikzplotlib/_color.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tikzplotlib/_color.py b/src/tikzplotlib/_color.py index 7a00a905..2e7bfa53 100644 --- a/src/tikzplotlib/_color.py +++ b/src/tikzplotlib/_color.py @@ -29,7 +29,12 @@ def _get_closest_colour_name(rgb): match = None mindiff = 1.0e15 - for h, name in webcolors.CSS3_HEX_TO_NAMES.items(): + hex_names_dict = ( + webcolors.CSS3_HEX_TO_NAMES + if hasattr(webcolors, "CSS3_HEX_TO_NAMES") + else webcolors._definitions._CSS3_HEX_TO_NAMES + ) + for h, name in hex_names_dict.items(): r = int(h[1:3], 16) g = int(h[3:5], 16) b = int(h[5:7], 16) From fedd580d57d3ab9c164c1a701e1e4ec6d52088bd Mon Sep 17 00:00:00 2001 From: Jason Gross Date: Thu, 8 Aug 2024 10:56:18 -0700 Subject: [PATCH 2/2] Use the actual interface for color names cf https://github.com/ubernostrum/webcolors/commit/dee9d4668976805427bd23dd1f5ddbec52cf547f and https://github.com/ubernostrum/webcolors/issues/20#issuecomment-2272787470 --- src/tikzplotlib/_color.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/tikzplotlib/_color.py b/src/tikzplotlib/_color.py index 2e7bfa53..6e446096 100644 --- a/src/tikzplotlib/_color.py +++ b/src/tikzplotlib/_color.py @@ -29,11 +29,15 @@ def _get_closest_colour_name(rgb): match = None mindiff = 1.0e15 - hex_names_dict = ( - webcolors.CSS3_HEX_TO_NAMES - if hasattr(webcolors, "CSS3_HEX_TO_NAMES") - else webcolors._definitions._CSS3_HEX_TO_NAMES - ) + if hasattr(webcolors, "names"): + hex_names_dict = { + webcolors.name_to_hex(name, spec=webcolors.CSS3): name + for name in webcolors.names(spec=webcolors.CSS3) + } + elif hasattr(webcolors, "CSS3_HEX_TO_NAMES"): + hex_names_dict = webcolors.CSS3_HEX_TO_NAMES + else: + hex_names_dict = webcolors._definitions._CSS3_HEX_TO_NAMES for h, name in hex_names_dict.items(): r = int(h[1:3], 16) g = int(h[3:5], 16)