From cf4bfd1f17defd320532bc21f4538b886132b793 Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 24 Oct 2024 11:10:20 -0400 Subject: [PATCH 1/4] Replace tenacity with custom retry function --- packages/python/plotly/plotly/io/_orca.py | 34 ++++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/python/plotly/plotly/io/_orca.py b/packages/python/plotly/plotly/io/_orca.py index c72c9e4c7e3..42771060cda 100644 --- a/packages/python/plotly/plotly/io/_orca.py +++ b/packages/python/plotly/plotly/io/_orca.py @@ -1,18 +1,19 @@ import atexit +import functools import json import os +import random import socket import subprocess import sys import threading +import time import warnings -from copy import copy from contextlib import contextmanager +from copy import copy from pathlib import Path from shutil import which -import tenacity - import plotly from plotly.files import PLOTLY_DIR, ensure_writable_plotly_dir from plotly.io._utils import validate_coerce_fig_to_dict @@ -111,6 +112,28 @@ def find_open_port(): return port +def retry(min_wait=5, max_wait=10, max_delay=60000): + def decorator(func): + @functools.wraps(func) + def wrapper(*args, **kwargs): + start_time = time.time() + + while True: + try: + return func(*args, **kwargs) + except Exception as e: + elapsed_time = time.time() - start_time + if elapsed_time * 1000 >= max_delay: + raise TimeoutError(f"Retry limit of {max_delay} milliseconds reached.") from e + + wait_time = random.uniform(min_wait, max_wait) + print(f"Retrying in {wait_time:.2f} seconds due to {e}...") + time.sleep(wait_time) + + return wrapper + return decorator + + # Orca configuration class # ------------------------ class OrcaConfig(object): @@ -1357,10 +1380,7 @@ def ensure_server(): orca_state["shutdown_timer"] = t -@tenacity.retry( - wait=tenacity.wait_random(min=5, max=10), - stop=tenacity.stop_after_delay(60000), -) +@retry(min_wait=5, max_wait=10, max_delay=60000) def request_image_with_retrying(**kwargs): """ Helper method to perform an image request to a running orca server process From 5952df457662239699319edd0c8db6cba4a61af4 Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 24 Oct 2024 11:10:28 -0400 Subject: [PATCH 2/4] Remove tenacity requirement --- environment.yml | 1 - packages/python/plotly/recipe/meta.yaml | 1 - packages/python/plotly/requirements.txt | 3 --- packages/python/plotly/setup.py | 2 +- .../python/plotly/test_requirements/requirements_310_core.txt | 1 - .../plotly/test_requirements/requirements_310_optional.txt | 1 - .../python/plotly/test_requirements/requirements_311_core.txt | 1 - .../plotly/test_requirements/requirements_311_optional.txt | 1 - .../python/plotly/test_requirements/requirements_312_core.txt | 1 - .../test_requirements/requirements_312_no_numpy_optional.txt | 1 - .../plotly/test_requirements/requirements_312_optional.txt | 1 - .../python/plotly/test_requirements/requirements_38_core.txt | 1 - .../plotly/test_requirements/requirements_38_optional.txt | 1 - .../python/plotly/test_requirements/requirements_39_core.txt | 1 - .../plotly/test_requirements/requirements_39_optional.txt | 1 - .../test_requirements/requirements_39_pandas_2_optional.txt | 1 - 16 files changed, 1 insertion(+), 18 deletions(-) diff --git a/environment.yml b/environment.yml index f87fa0fa560..e22c996791f 100644 --- a/environment.yml +++ b/environment.yml @@ -10,7 +10,6 @@ dependencies: - pandas - black - pytest - - tenacity - inflect - jupyterlab - ipywidgets diff --git a/packages/python/plotly/recipe/meta.yaml b/packages/python/plotly/recipe/meta.yaml index 775d8fe1e39..992015585c4 100644 --- a/packages/python/plotly/recipe/meta.yaml +++ b/packages/python/plotly/recipe/meta.yaml @@ -25,7 +25,6 @@ requirements: - setuptools run: - python - - tenacity >=6.2.0 test: imports: diff --git a/packages/python/plotly/requirements.txt b/packages/python/plotly/requirements.txt index 2d763d4dae4..463fe1bbfbd 100644 --- a/packages/python/plotly/requirements.txt +++ b/packages/python/plotly/requirements.txt @@ -4,6 +4,3 @@ ### $ pip install -r requirements.txt ### ### ### ################################################### - -## retrying requests ## -tenacity>=6.2.0 diff --git a/packages/python/plotly/setup.py b/packages/python/plotly/setup.py index 1122ebb4cbc..2c49f298cd9 100644 --- a/packages/python/plotly/setup.py +++ b/packages/python/plotly/setup.py @@ -603,7 +603,7 @@ def run(self): data_files=[ ("etc/jupyter/nbconfig/notebook.d", ["jupyterlab-plotly.json"]), ], - install_requires=["tenacity>=6.2.0", "packaging"], + install_requires=["packaging"], zip_safe=False, cmdclass=dict( build_py=js_prerelease(versioneer_cmds["build_py"]), diff --git a/packages/python/plotly/test_requirements/requirements_310_core.txt b/packages/python/plotly/test_requirements/requirements_310_core.txt index fcacda06c79..c3af689b055 100644 --- a/packages/python/plotly/test_requirements/requirements_310_core.txt +++ b/packages/python/plotly/test_requirements/requirements_310_core.txt @@ -1,3 +1,2 @@ requests==2.25.1 -tenacity==6.2.0 pytest==7.4.4 diff --git a/packages/python/plotly/test_requirements/requirements_310_optional.txt b/packages/python/plotly/test_requirements/requirements_310_optional.txt index 4beeaa6ffc0..5494291abf1 100644 --- a/packages/python/plotly/test_requirements/requirements_310_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_310_optional.txt @@ -1,5 +1,4 @@ requests==2.25.1 -tenacity==6.2.0 pandas==1.5.3 numpy==1.23.0 xarray==0.17.0 diff --git a/packages/python/plotly/test_requirements/requirements_311_core.txt b/packages/python/plotly/test_requirements/requirements_311_core.txt index fcacda06c79..c3af689b055 100644 --- a/packages/python/plotly/test_requirements/requirements_311_core.txt +++ b/packages/python/plotly/test_requirements/requirements_311_core.txt @@ -1,3 +1,2 @@ requests==2.25.1 -tenacity==6.2.0 pytest==7.4.4 diff --git a/packages/python/plotly/test_requirements/requirements_311_optional.txt b/packages/python/plotly/test_requirements/requirements_311_optional.txt index c0e4a679d79..64392dacd60 100644 --- a/packages/python/plotly/test_requirements/requirements_311_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_311_optional.txt @@ -1,5 +1,4 @@ requests==2.25.1 -tenacity==6.2.0 pandas==1.5.3 numpy==1.23.2 xarray==0.17.0 diff --git a/packages/python/plotly/test_requirements/requirements_312_core.txt b/packages/python/plotly/test_requirements/requirements_312_core.txt index fcacda06c79..c3af689b055 100644 --- a/packages/python/plotly/test_requirements/requirements_312_core.txt +++ b/packages/python/plotly/test_requirements/requirements_312_core.txt @@ -1,3 +1,2 @@ requests==2.25.1 -tenacity==6.2.0 pytest==7.4.4 diff --git a/packages/python/plotly/test_requirements/requirements_312_no_numpy_optional.txt b/packages/python/plotly/test_requirements/requirements_312_no_numpy_optional.txt index 2fd781846e9..3ba22b59427 100644 --- a/packages/python/plotly/test_requirements/requirements_312_no_numpy_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_312_no_numpy_optional.txt @@ -1,5 +1,4 @@ requests==2.31.0 -tenacity==8.2.3 pandas xarray==2023.12.0 statsmodels diff --git a/packages/python/plotly/test_requirements/requirements_312_optional.txt b/packages/python/plotly/test_requirements/requirements_312_optional.txt index 6a5beaff57b..d1933661135 100644 --- a/packages/python/plotly/test_requirements/requirements_312_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_312_optional.txt @@ -1,5 +1,4 @@ requests==2.31.0 -tenacity==8.2.3 pandas numpy xarray==2023.12.0 diff --git a/packages/python/plotly/test_requirements/requirements_38_core.txt b/packages/python/plotly/test_requirements/requirements_38_core.txt index 61bfc653cd9..659fe1a370f 100644 --- a/packages/python/plotly/test_requirements/requirements_38_core.txt +++ b/packages/python/plotly/test_requirements/requirements_38_core.txt @@ -1,3 +1,2 @@ requests==2.25.1 -tenacity==6.2.0 pytest==8.1.1 diff --git a/packages/python/plotly/test_requirements/requirements_38_optional.txt b/packages/python/plotly/test_requirements/requirements_38_optional.txt index b77d1a0acbd..0381d36d305 100644 --- a/packages/python/plotly/test_requirements/requirements_38_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_38_optional.txt @@ -1,5 +1,4 @@ requests==2.25.1 -tenacity==6.2.0 pandas==1.2.4 numpy==1.20.2 xarray==0.17.0 diff --git a/packages/python/plotly/test_requirements/requirements_39_core.txt b/packages/python/plotly/test_requirements/requirements_39_core.txt index edb622db5c0..f4605b806c5 100644 --- a/packages/python/plotly/test_requirements/requirements_39_core.txt +++ b/packages/python/plotly/test_requirements/requirements_39_core.txt @@ -1,3 +1,2 @@ requests==2.25.1 -tenacity==6.2.0 pytest==6.2.3 diff --git a/packages/python/plotly/test_requirements/requirements_39_optional.txt b/packages/python/plotly/test_requirements/requirements_39_optional.txt index 37791cb5a60..91e3af383e3 100644 --- a/packages/python/plotly/test_requirements/requirements_39_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_39_optional.txt @@ -1,5 +1,4 @@ requests==2.25.1 -tenacity==6.2.0 pandas==1.2.4 numpy==1.21.6 xarray==0.17.0 diff --git a/packages/python/plotly/test_requirements/requirements_39_pandas_2_optional.txt b/packages/python/plotly/test_requirements/requirements_39_pandas_2_optional.txt index 06a5a61f3e2..affdb9ddfc0 100644 --- a/packages/python/plotly/test_requirements/requirements_39_pandas_2_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_39_pandas_2_optional.txt @@ -1,5 +1,4 @@ requests==2.25.1 -tenacity==6.2.0 pandas==2.2.0 numpy==1.22.4 xarray==0.17.0 From 7b6cfe8216eecd20230f6df92ada793251ae0a66 Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 24 Oct 2024 11:22:18 -0400 Subject: [PATCH 3/4] =?UTF-8?q?Apply=20formatting=20=F0=9F=92=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/python/plotly/plotly/io/_orca.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/python/plotly/plotly/io/_orca.py b/packages/python/plotly/plotly/io/_orca.py index 42771060cda..bf95123989e 100644 --- a/packages/python/plotly/plotly/io/_orca.py +++ b/packages/python/plotly/plotly/io/_orca.py @@ -124,13 +124,16 @@ def wrapper(*args, **kwargs): except Exception as e: elapsed_time = time.time() - start_time if elapsed_time * 1000 >= max_delay: - raise TimeoutError(f"Retry limit of {max_delay} milliseconds reached.") from e - + raise TimeoutError( + f"Retry limit of {max_delay} milliseconds reached." + ) from e + wait_time = random.uniform(min_wait, max_wait) print(f"Retrying in {wait_time:.2f} seconds due to {e}...") time.sleep(wait_time) - + return wrapper + return decorator From f6721690f0048430d5e97dc41c3c27d347a56659 Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 24 Oct 2024 11:41:53 -0400 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b65ef5faa41..26d6c70c8af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Removed - Drop deprecated `pointcloud` and `heatmapgl` traces from the API +- Drop `tenacity` dependency [#4831](https://github.com/plotly/plotly.js/pull/4831) ### Updated