From 9e6a9a47edd40f900628d51ae1b2669d95976465 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Thu, 26 May 2022 12:22:14 -0400 Subject: [PATCH 1/4] allow non-string extras in flaglist attributes --- .../plotly/_plotly_utils/basevalidators.py | 21 +++++------ .../validators/test_flaglist_validator.py | 35 ++++++++----------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/packages/python/plotly/_plotly_utils/basevalidators.py b/packages/python/plotly/_plotly_utils/basevalidators.py index 98b9df2e5ae..f68bc63f761 100644 --- a/packages/python/plotly/_plotly_utils/basevalidators.py +++ b/packages/python/plotly/_plotly_utils/basevalidators.py @@ -1795,8 +1795,6 @@ def __init__( self.extras = extras if extras is not None else [] self.array_ok = array_ok - self.all_flags = self.flags + self.extras - def description(self): desc = ( @@ -1835,24 +1833,21 @@ def description(self): return desc def vc_scalar(self, v): + if isinstance(v, str): + v = v.strip() + + if v in self.extras: + return v + if not isinstance(v, str): return None # To be generous we accept flags separated on plus ('+'), - # or comma (',') + # or comma (',') and we accept whitespace around the flags split_vals = [e.strip() for e in re.split("[,+]", v)] # Are all flags valid names? - all_flags_valid = all([f in self.all_flags for f in split_vals]) - - # Are any 'extras' flags present? - has_extras = any([f in self.extras for f in split_vals]) - - # For flaglist to be valid all flags must be valid, and if we have - # any extras present, there must be only one flag (the single extras - # flag) - is_valid = all_flags_valid and (not has_extras or len(split_vals) == 1) - if is_valid: + if all(f in self.flags for f in split_vals): return "+".join(split_vals) else: return None diff --git a/packages/python/plotly/_plotly_utils/tests/validators/test_flaglist_validator.py b/packages/python/plotly/_plotly_utils/tests/validators/test_flaglist_validator.py index 157b98d9754..695b8a90998 100644 --- a/packages/python/plotly/_plotly_utils/tests/validators/test_flaglist_validator.py +++ b/packages/python/plotly/_plotly_utils/tests/validators/test_flaglist_validator.py @@ -4,46 +4,41 @@ import numpy as np +EXTRAS = ["none", "all", True, False, 3] +FLAGS = ["lines", "markers", "text"] + # Fixtures # -------- -@pytest.fixture(params=[None, ["none", "all"]]) +@pytest.fixture(params=[None, EXTRAS]) def validator(request): # Validator with or without extras - return FlaglistValidator( - "prop", "parent", flags=["lines", "markers", "text"], extras=request.param - ) + return FlaglistValidator("prop", "parent", flags=FLAGS, extras=request.param) @pytest.fixture() def validator_extra(): - return FlaglistValidator( - "prop", "parent", flags=["lines", "markers", "text"], extras=["none", "all"] - ) + return FlaglistValidator("prop", "parent", flags=FLAGS, extras=EXTRAS) @pytest.fixture() def validator_extra_aok(): return FlaglistValidator( - "prop", - "parent", - flags=["lines", "markers", "text"], - extras=["none", "all"], - array_ok=True, + "prop", "parent", flags=FLAGS, extras=EXTRAS, array_ok=True, ) @pytest.fixture( params=[ "+".join(p) - for i in range(1, 4) - for p in itertools.permutations(["lines", "markers", "text"], i) + for i in range(1, len(FLAGS) + 1) + for p in itertools.permutations(FLAGS, i) ] ) def flaglist(request): return request.param -@pytest.fixture(params=["none", "all"]) +@pytest.fixture(params=EXTRAS) def extra(request): return request.param @@ -69,7 +64,7 @@ def test_coercion(in_val, coerce_val, validator): # ### Rejection by type ### -@pytest.mark.parametrize("val", [21, (), ["lines"], set(), {}]) +@pytest.mark.parametrize("val", [(), ["lines"], set(), {}]) def test_rejection_type(val, validator): with pytest.raises(ValueError) as validation_failure: validator.validate_coerce(val) @@ -79,7 +74,7 @@ def test_rejection_type(val, validator): # ### Rejection by value ### @pytest.mark.parametrize( - "val", ["", "line", "markers+line", "lin es", "lin es+markers"] + "val", ["", "line", "markers+line", "lin es", "lin es+markers", 21] ) def test_rejection_val(val, validator): with pytest.raises(ValueError) as validation_failure: @@ -144,7 +139,7 @@ def test_acceptance_aok_scalarlist_flaglist(flaglist, validator_extra_aok): [ ["all", "markers", "text+markers"], ["lines", "lines+markers", "markers+lines+text"], - ["all", "all", "lines+text", "none"], + ["all", "all", "lines+text"] + EXTRAS, ], ) def test_acceptance_aok_list_flaglist(val, validator_extra_aok): @@ -158,8 +153,8 @@ def test_acceptance_aok_list_flaglist(val, validator_extra_aok): "in_val,expected", [ ( - [" lines ", " lines + markers ", "lines ,markers"], - ["lines", "lines+markers", "lines+markers"], + [" lines ", " lines + markers ", "lines ,markers", " all "], + ["lines", "lines+markers", "lines+markers", "all"], ), (np.array(["text +lines"]), np.array(["text+lines"], dtype="unicode")), ], From c4031df37a456386a2e82f55b6e8bf86fcc78865 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Thu, 26 May 2022 12:28:47 -0400 Subject: [PATCH 2/4] lint --- .../tests/validators/test_flaglist_validator.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/python/plotly/_plotly_utils/tests/validators/test_flaglist_validator.py b/packages/python/plotly/_plotly_utils/tests/validators/test_flaglist_validator.py index 695b8a90998..4ce30022dac 100644 --- a/packages/python/plotly/_plotly_utils/tests/validators/test_flaglist_validator.py +++ b/packages/python/plotly/_plotly_utils/tests/validators/test_flaglist_validator.py @@ -23,7 +23,11 @@ def validator_extra(): @pytest.fixture() def validator_extra_aok(): return FlaglistValidator( - "prop", "parent", flags=FLAGS, extras=EXTRAS, array_ok=True, + "prop", + "parent", + flags=FLAGS, + extras=EXTRAS, + array_ok=True, ) From 6d2fb4dca0564bb7b304289115d8f0bd3666b2b9 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Thu, 26 May 2022 12:33:21 -0400 Subject: [PATCH 3/4] changelog for non-string flaglist extras --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49170a32a0d..e806423b0ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [UNRELEASED] + +### Updated + + - Allow non-string extras in `flaglist` attributes, to support upcoming changes to `ax.automargin` in plotly.js [plotly.js#6193](https://github.com/plotly/plotly.js/pull/6193), [#3749](https://github.com/plotly/plotly.py/pull/3749) + ## [5.8.0] - 2022-05-09 ### Fixed From ef3a3eb40817498798d7430a81199c9a60e7b120 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Thu, 26 May 2022 13:36:20 -0400 Subject: [PATCH 4/4] fix circleci url in get_latest_publish_build_info --- packages/python/plotly/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/setup.py b/packages/python/plotly/setup.py index 7ce054aab89..7567cf81569 100644 --- a/packages/python/plotly/setup.py +++ b/packages/python/plotly/setup.py @@ -286,7 +286,7 @@ def get_latest_publish_build_info(repo, branch): url = ( r"https://circleci.com/api/v1.1/project/github/" - r"{repo}/tree/{branch}?limit=10000\&filter=completed" + r"{repo}/tree/{branch}?limit=100&filter=completed" ).format(repo=repo, branch=branch) branch_jobs = request_json(url)