From 964200133a1959c2cb5f1e29bac08d481e53c64a Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 12:04:59 +0100 Subject: [PATCH 01/36] add show_anim() function with usage example notebook --- examples/show_anim_example.ipynb | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 examples/show_anim_example.ipynb diff --git a/examples/show_anim_example.ipynb b/examples/show_anim_example.ipynb new file mode 100644 index 0000000..5149395 --- /dev/null +++ b/examples/show_anim_example.ipynb @@ -0,0 +1,46 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "51913260-f89a-4237-bc7b-af5a0b1785f9", + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "def anim_func(frame):\n", + " fig = plt.figure(figsize=(9,6))\n", + " ax = fig.add_subplot(111)\n", + " x = np.linspace(0,2,1000)\n", + " y = np.sin(2*np.pi*(x+0.01*frame))\n", + " ax.plot(x,y) \n", + " return fig" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4778deb3-b660-4c3d-a0bf-700ba7d9b93f", + "metadata": {}, + "outputs": [], + "source": [ + "from open_atmos_jupyter_utils.show_anim import show_anim \n", + "\n", + "frame_range = range(0,50,1)\n", + "show_anim(anim_func, frame_range)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "", + "name": "" + }, + "language_info": { + "name": "" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 6aa36829d79b4fa0fe1509b26170f00bb38d5477 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 12:05:23 +0100 Subject: [PATCH 02/36] add show_anim() implementation --- open_atmos_jupyter_utils/show_anim.py | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 open_atmos_jupyter_utils/show_anim.py diff --git a/open_atmos_jupyter_utils/show_anim.py b/open_atmos_jupyter_utils/show_anim.py new file mode 100644 index 0000000..9998b64 --- /dev/null +++ b/open_atmos_jupyter_utils/show_anim.py @@ -0,0 +1,33 @@ +"""inline animation function that allows rendering on github preview and showing click to download gif button""" + +import os +import imageio +import tempfile +import base64 +import matplotlib.pyplot as plt +from open_atmos_jupyter_utils.temporary_file import TemporaryFile +from IPython.display import HTML, display + + +def show_anim(plot_func, frame_range, duration=0.01, loop=0): + """ plot_func is called with one argument - the frame number from frame_range + and is expected to return a matplotlib figure instance (on which savefig() + and close() are subsequently called) """ + gif_file = TemporaryFile(suffix=".gif") + with tempfile.TemporaryDirectory() as tmpdirname: + for frame in frame_range: + fig = plot_func(frame) + fig.savefig(f'{tmpdirname}/{frame:05d}.png') + plt.close(fig) + __merge_images_into_gif(tmpdirname, gif_file, duration, loop) + + b64 = base64.b64encode(open(gif_file.basename,'rb').read()).decode('ascii') + display(HTML(f'')) + display(gif_file.make_link_widget()) + +def __merge_images_into_gif(image_folder, gif_name, duration, loop): + """creates a GIF file from a series of animation frames""" + with imageio.get_writer(gif_name.basename, duration=duration, loop=loop, mode="I") as writer: + for filename in sorted(os.listdir(image_folder)): + image = imageio.v3.imread(os.path.join(image_folder, filename)) + writer.append_data(image) From be990539a91555ea1953fce9cd778d448e05fc00 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 15:06:13 +0100 Subject: [PATCH 03/36] fixed formatting errors --- open_atmos_jupyter_utils/show_anim.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/open_atmos_jupyter_utils/show_anim.py b/open_atmos_jupyter_utils/show_anim.py index 9998b64..9b3f282 100644 --- a/open_atmos_jupyter_utils/show_anim.py +++ b/open_atmos_jupyter_utils/show_anim.py @@ -1,33 +1,36 @@ """inline animation function that allows rendering on github preview and showing click to download gif button""" import os -import imageio import tempfile import base64 +import imageio import matplotlib.pyplot as plt -from open_atmos_jupyter_utils.temporary_file import TemporaryFile from IPython.display import HTML, display +from open_atmos_jupyter_utils.temporary_file import TemporaryFile def show_anim(plot_func, frame_range, duration=0.01, loop=0): - """ plot_func is called with one argument - the frame number from frame_range - and is expected to return a matplotlib figure instance (on which savefig() - and close() are subsequently called) """ + """plot_func is called with one argument - the frame number from frame_range + and is expected to return a matplotlib figure instance (on which savefig() + and close() are subsequently called)""" gif_file = TemporaryFile(suffix=".gif") with tempfile.TemporaryDirectory() as tmpdirname: for frame in frame_range: fig = plot_func(frame) - fig.savefig(f'{tmpdirname}/{frame:05d}.png') + fig.savefig(f"{tmpdirname}/{frame:05d}.png") plt.close(fig) __merge_images_into_gif(tmpdirname, gif_file, duration, loop) - - b64 = base64.b64encode(open(gif_file.basename,'rb').read()).decode('ascii') - display(HTML(f'')) - display(gif_file.make_link_widget()) - + with open(gif_file.basename, "rb").read() as gifname: + b64 = base64.b64encode(gifname.decode("ascii")) + display(HTML(f'')) + display(gif_file.make_link_widget()) + + def __merge_images_into_gif(image_folder, gif_name, duration, loop): """creates a GIF file from a series of animation frames""" - with imageio.get_writer(gif_name.basename, duration=duration, loop=loop, mode="I") as writer: + with imageio.get_writer( + gif_name.basename, duration=duration, loop=loop, mode="I" + ) as writer: for filename in sorted(os.listdir(image_folder)): image = imageio.v3.imread(os.path.join(image_folder, filename)) writer.append_data(image) From bb385f14bdfbee94a7607bd53d958bf8e3eb4daa Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 15:11:29 +0100 Subject: [PATCH 04/36] bumped python version and added imageio to requirements --- .github/workflows/pylint.yml | 4 ++-- open_atmos_jupyter_utils/show_anim.py | 3 ++- setup.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 0bbc17a..3723d91 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -13,10 +13,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up Python 3.9 + - name: Set up Python 3.12 uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: 3.12 - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/open_atmos_jupyter_utils/show_anim.py b/open_atmos_jupyter_utils/show_anim.py index 9b3f282..1507170 100644 --- a/open_atmos_jupyter_utils/show_anim.py +++ b/open_atmos_jupyter_utils/show_anim.py @@ -1,4 +1,5 @@ -"""inline animation function that allows rendering on github preview and showing click to download gif button""" +"""inline animation function that allows rendering on github + preview and showing click to download gif button""" import os import tempfile diff --git a/setup.py b/setup.py index be1596e..48efa69 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ def get_long_description(): "version_scheme": "post-release" }, setup_requires=['setuptools_scm'], - install_requires=['ipywidgets', 'IPython', 'matplotlib'], + install_requires=['ipywidgets', 'IPython', 'matplotlib', 'imageio'], author='https://github.com/open-atmos/jupyter-utils/graphs/contributors', author_email='sylwester.arabas@agh.edu.pl', license="GPL-3.0", From 6e165d4ac4a078b593f7b4c6e6d1fb1adb06c744 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 15:13:29 +0100 Subject: [PATCH 05/36] reversed python version to 3.9 --- .github/workflows/pylint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 3723d91..0bbc17a 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -13,10 +13,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up Python 3.12 + - name: Set up Python 3.9 uses: actions/setup-python@v2 with: - python-version: 3.12 + python-version: 3.9 - name: Install dependencies run: | python -m pip install --upgrade pip From f23c97d02b23906065e7f835fb4e925d3dd9c631 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 15:45:57 +0100 Subject: [PATCH 06/36] fixes to pyproject.toml to help with compiling --- pyproject.toml | 8 +++++++- setup.py | 5 ----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 610b323..0d030f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,8 +2,14 @@ # TODO [build-system] -requires = ['setuptools==56.0.0', 'setuptools-scm==6.0.1'] +requires = ['setuptools', 'setuptools-scm'] +[project] +name = 'open-atmos-jupyter-utils' +description = "utility routines used in PySDM, PyMPDATA and PyPartMC examples and tests" +license = {text = "GPL-3.0"} +readme = "README.md" +dynamic = ["version"] [project.urls] "Homepage" = "https://github.com/open-atmos/jupyter-utils" "Source" = "https://github.com/open-atmos/jupyter-utils" diff --git a/setup.py b/setup.py index 48efa69..f1d05e0 100644 --- a/setup.py +++ b/setup.py @@ -12,17 +12,12 @@ def get_long_description(): setup( - name='open-atmos-jupyter-utils', - description='utility routines used in PySDM, PyMPDATA and PyPartMC examples and tests', use_scm_version={ "local_scheme": lambda _: "", "version_scheme": "post-release" }, setup_requires=['setuptools_scm'], install_requires=['ipywidgets', 'IPython', 'matplotlib', 'imageio'], - author='https://github.com/open-atmos/jupyter-utils/graphs/contributors', - author_email='sylwester.arabas@agh.edu.pl', - license="GPL-3.0", packages=find_packages(include=['open_atmos_jupyter_utils', 'open_atmos_jupyter_utils.*']), long_description=get_long_description(), long_description_content_type="text/markdown", From 177e375267c353ad83eee513dc90ecb7cbd6cb61 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 15:51:56 +0100 Subject: [PATCH 07/36] fixes to pyproject.toml to help with compiling --- pyproject.toml | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0d030f6..2345744 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,12 @@ description = "utility routines used in PySDM, PyMPDATA and PyPartMC examples an license = {text = "GPL-3.0"} readme = "README.md" dynamic = ["version"] +dependencies = [ + "ipywidgets", + "IPython", + "matplotlib", + "imageio", +] [project.urls] "Homepage" = "https://github.com/open-atmos/jupyter-utils" "Source" = "https://github.com/open-atmos/jupyter-utils" diff --git a/setup.py b/setup.py index f1d05e0..3a84370 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ def get_long_description(): "version_scheme": "post-release" }, setup_requires=['setuptools_scm'], - install_requires=['ipywidgets', 'IPython', 'matplotlib', 'imageio'], + #install_requires=['ipywidgets', 'IPython', 'matplotlib', 'imageio'], packages=find_packages(include=['open_atmos_jupyter_utils', 'open_atmos_jupyter_utils.*']), long_description=get_long_description(), long_description_content_type="text/markdown", From 69dd18706588a8c03f3ce02190084f0f9cf2a82c Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 15:54:58 +0100 Subject: [PATCH 08/36] Bump python version of pylint to 3.12 --- .github/workflows/pylint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 0bbc17a..3723d91 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -13,10 +13,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up Python 3.9 + - name: Set up Python 3.12 uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: 3.12 - name: Install dependencies run: | python -m pip install --upgrade pip From 88e0b605d2fc7dfdf23b64af0342fe94811f4634 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 16:14:27 +0100 Subject: [PATCH 09/36] Temporary edits to setup.py to test workflows interactions --- pyproject.toml | 3 +++ setup.py | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2345744..b42370b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,11 @@ +[tool.setuptools] + [tool.setuptools_scm] # TODO [build-system] requires = ['setuptools', 'setuptools-scm'] +build-backend = "setuptools.build_meta" [project] name = 'open-atmos-jupyter-utils' diff --git a/setup.py b/setup.py index 3a84370..1c209bf 100644 --- a/setup.py +++ b/setup.py @@ -4,22 +4,22 @@ from setuptools import setup, find_packages -def get_long_description(): - """returns contents of README.md file""" - with open("README.md", "r", encoding="utf8") as file: - long_description = file.read() - return long_description +#def get_long_description(): +#"""returns contents of README.md file""" + #with open("README.md", "r", encoding="utf8") as file: + # long_description = file.read() + #return long_description setup( - use_scm_version={ - "local_scheme": lambda _: "", - "version_scheme": "post-release" - }, + #use_scm_version={ + # "local_scheme": lambda _: "", + # "version_scheme": "post-release" + #}, setup_requires=['setuptools_scm'], - #install_requires=['ipywidgets', 'IPython', 'matplotlib', 'imageio'], + install_requires=['ipywidgets', 'IPython', 'matplotlib', 'imageio'], packages=find_packages(include=['open_atmos_jupyter_utils', 'open_atmos_jupyter_utils.*']), - long_description=get_long_description(), - long_description_content_type="text/markdown", + #long_description=get_long_description(), + #long_description_content_type="text/markdown", url='https://github.com/open-atmos/jupyter-utils', ) From 077bee3661eb2b102af9b9c687d0c466956482fb Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 16:16:44 +0100 Subject: [PATCH 10/36] change action tools versions --- .github/workflows/pylint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 3723d91..a63425b 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -12,9 +12,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python 3.12 - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.12 - name: Install dependencies From 215cc1834969c50f3c90eb6a5c8a4b6325df0ad6 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 16:26:38 +0100 Subject: [PATCH 11/36] change setuptools version --- pyproject.toml | 2 +- setup.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b42370b..96e71ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ # TODO [build-system] -requires = ['setuptools', 'setuptools-scm'] +requires = ['setuptools==69.1.0', 'setuptools-scm==7.1.0'] build-backend = "setuptools.build_meta" [project] diff --git a/setup.py b/setup.py index 1c209bf..163be89 100644 --- a/setup.py +++ b/setup.py @@ -12,10 +12,10 @@ setup( - #use_scm_version={ - # "local_scheme": lambda _: "", - # "version_scheme": "post-release" - #}, + use_scm_version={ + "local_scheme": lambda _: "", + "version_scheme": "post-release" + }, setup_requires=['setuptools_scm'], install_requires=['ipywidgets', 'IPython', 'matplotlib', 'imageio'], packages=find_packages(include=['open_atmos_jupyter_utils', 'open_atmos_jupyter_utils.*']), From 6c3c2513cae979bc5c13e8a678bf2582339aa87f Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 16:29:51 +0100 Subject: [PATCH 12/36] changes to pylint.yml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 96e71ad..156469a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ # TODO [build-system] -requires = ['setuptools==69.1.0', 'setuptools-scm==7.1.0'] +requires = ['setuptools==75.3.0', 'setuptools-scm==8.1.0'] build-backend = "setuptools.build_meta" [project] From 02191bc4185daa3aa94eab5d9a36a87559c1f7c3 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 16:37:19 +0100 Subject: [PATCH 13/36] more temp changes, to be cleaned up --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 163be89..8304f4d 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ "local_scheme": lambda _: "", "version_scheme": "post-release" }, - setup_requires=['setuptools_scm'], + setup_requires=['setuptools_scm','setuptools'], install_requires=['ipywidgets', 'IPython', 'matplotlib', 'imageio'], packages=find_packages(include=['open_atmos_jupyter_utils', 'open_atmos_jupyter_utils.*']), #long_description=get_long_description(), From 4dbf906cc9fee0835a5d92d2cb80eabd5d008a8a Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 16:39:59 +0100 Subject: [PATCH 14/36] emptied setup.py --- setup.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/setup.py b/setup.py index 8304f4d..942bf24 100644 --- a/setup.py +++ b/setup.py @@ -12,14 +12,14 @@ setup( - use_scm_version={ - "local_scheme": lambda _: "", - "version_scheme": "post-release" - }, - setup_requires=['setuptools_scm','setuptools'], - install_requires=['ipywidgets', 'IPython', 'matplotlib', 'imageio'], - packages=find_packages(include=['open_atmos_jupyter_utils', 'open_atmos_jupyter_utils.*']), - #long_description=get_long_description(), - #long_description_content_type="text/markdown", - url='https://github.com/open-atmos/jupyter-utils', + # use_scm_version={ + # "local_scheme": lambda _: "", + # "version_scheme": "post-release" + # }, + # setup_requires=['setuptools_scm','setuptools'], + # install_requires=['ipywidgets', 'IPython', 'matplotlib', 'imageio'], + # packages=find_packages(include=['open_atmos_jupyter_utils', 'open_atmos_jupyter_utils.*']), + # #long_description=get_long_description(), + # #long_description_content_type="text/markdown", + #url='https://github.com/open-atmos/jupyter-utils', ) From a48012299e13e7411e0f5cf679ed22916bc1597b Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 16:42:11 +0100 Subject: [PATCH 15/36] force installation of setuptools --- .github/workflows/pylint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index a63425b..2e531b7 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -19,7 +19,7 @@ jobs: python-version: 3.12 - name: Install dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip setuptools pip install pylint python setup.py egg_info pip install -r *.egg-info/requires.txt From ff41ab57ce4abf560d7b424679601b16a80b6d89 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 16:44:07 +0100 Subject: [PATCH 16/36] reverse temp changes to setup.py --- setup.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index 942bf24..59c8880 100644 --- a/setup.py +++ b/setup.py @@ -4,22 +4,22 @@ from setuptools import setup, find_packages -#def get_long_description(): -#"""returns contents of README.md file""" - #with open("README.md", "r", encoding="utf8") as file: - # long_description = file.read() - #return long_description +def get_long_description(): + """returns contents of README.md file""" + with open("README.md", "r", encoding="utf8") as file: + long_description = file.read() + return long_description setup( - # use_scm_version={ - # "local_scheme": lambda _: "", - # "version_scheme": "post-release" - # }, - # setup_requires=['setuptools_scm','setuptools'], - # install_requires=['ipywidgets', 'IPython', 'matplotlib', 'imageio'], - # packages=find_packages(include=['open_atmos_jupyter_utils', 'open_atmos_jupyter_utils.*']), - # #long_description=get_long_description(), - # #long_description_content_type="text/markdown", - #url='https://github.com/open-atmos/jupyter-utils', + use_scm_version={ + "local_scheme": lambda _: "", + "version_scheme": "post-release" + }, + setup_requires=['setuptools_scm','setuptools'], + install_requires=['ipywidgets', 'IPython', 'matplotlib', 'imageio'], + packages=find_packages(include=['open_atmos_jupyter_utils', 'open_atmos_jupyter_utils.*']), + long_description=get_long_description(), + long_description_content_type="text/markdown", + url='https://github.com/open-atmos/jupyter-utils', ) From 3ee435c35215dc777a575b1e601d78cd62742564 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 16:45:06 +0100 Subject: [PATCH 17/36] fix setup.py formatting --- setup.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index 59c8880..40edc88 100644 --- a/setup.py +++ b/setup.py @@ -1,25 +1,25 @@ """ the magick behind ``pip install ...`` """ + from setuptools import setup, find_packages def get_long_description(): """returns contents of README.md file""" with open("README.md", "r", encoding="utf8") as file: - long_description = file.read() + long_description = file.read() return long_description setup( - use_scm_version={ - "local_scheme": lambda _: "", - "version_scheme": "post-release" - }, - setup_requires=['setuptools_scm','setuptools'], - install_requires=['ipywidgets', 'IPython', 'matplotlib', 'imageio'], - packages=find_packages(include=['open_atmos_jupyter_utils', 'open_atmos_jupyter_utils.*']), + use_scm_version={"local_scheme": lambda _: "", "version_scheme": "post-release"}, + setup_requires=["setuptools_scm", "setuptools"], + install_requires=["ipywidgets", "IPython", "matplotlib", "imageio"], + packages=find_packages( + include=["open_atmos_jupyter_utils", "open_atmos_jupyter_utils.*"] + ), long_description=get_long_description(), long_description_content_type="text/markdown", - url='https://github.com/open-atmos/jupyter-utils', + url="https://github.com/open-atmos/jupyter-utils", ) From 3fe610431dd19532be96af16cb68a78e72a23eb8 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 20:49:34 +0100 Subject: [PATCH 18/36] add show_anim() to README.md with a short description --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a2251e4..148ecf2 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Utility routines used in Jupyter notebooks in [PySDM](https://github.com/open-atmos/PySDM), [PyMPDATA](https://github.com/open-atmos/PyMPDATA) and [PyPartMC](https://github.com/open-atmos/PyPartMC) projects: - [``show_plot()``](https://open-atmos.github.io/jupyter-utils/open_atmos_jupyter_utils/show_plot.html) - a drop-in replacement for matplotlib's show() displaying the figure inline using vector graphics (svg) by default and offering a download-as-pdf-or-svg widget just below (on Colab the widget triggers Google Drive download) +- [``show_anim()``](https://open-atmos.github.io/jupyter-utils/open_atmos_jupyter_utils/show_anim.html) - a replacement for matplotlib's FuncAnimate() that displays animations in gif format inline based on given plotting function and by default and offers a way to download the file from inside notebooks (github renderer included) - [``TemporaryFile``](https://open-atmos.github.io/jupyter-utils/open_atmos_jupyter_utils/temporary_file.html) - a class equipped with ``make_link_widget()`` method returning a click-to-download Colab-compatible widget to be display()-ed in a Jupyter notebook - [``pip_install_on_colab('package_a', 'package_b', ...)``](https://open-atmos.github.io/jupyter-utils/open_atmos_jupyter_utils/pip_install_on_colab.html) - a function handling execution of ``pip`` (and ``ldconfig``) on Colab From 2118d90f174727022ede6eb98c82b32b1a4fae8c Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 21:46:13 +0100 Subject: [PATCH 19/36] add CI wokrflow and fix notebook output --- .gitmodules | 3 +++ tests/devops_tests.git | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 tests/devops_tests.git diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..095049d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tests/devops_tests.git"] + path = tests/devops_tests.git + url = git@github.com:open-atmos/devops_tests.git diff --git a/tests/devops_tests.git b/tests/devops_tests.git new file mode 160000 index 0000000..8eb4d96 --- /dev/null +++ b/tests/devops_tests.git @@ -0,0 +1 @@ +Subproject commit 8eb4d96a1ea8afa09a409a99dccbd0ddd48f80a7 From 778f03b14e7375c72e2bcd7dbb2342a01ac5db70 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:05:50 +0100 Subject: [PATCH 20/36] fixes to notebook output --- .github/workflows/tests.yml | 21 ++++++++++++ examples/show_anim_example.ipynb | 49 +++++++++++++++++++++++---- open_atmos_jupyter_utils/show_anim.py | 8 ++--- 3 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..7810a65 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,21 @@ +name: tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.12 + uses: actions/setup-python@v5 + with: + python-version: 3.12 + run: | + pip install -r tests/devops_tests/requirements.txt + pytest -vv -rP -We tests/devops_tests/test_notebooks.py::test_run_notebook diff --git a/examples/show_anim_example.ipynb b/examples/show_anim_example.ipynb index 5149395..188cf4a 100644 --- a/examples/show_anim_example.ipynb +++ b/examples/show_anim_example.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "51913260-f89a-4237-bc7b-af5a0b1785f9", "metadata": {}, "outputs": [], @@ -20,10 +20,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "4778deb3-b660-4c3d-a0bf-700ba7d9b93f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "65553060ba724a29b2e26b02a545ab80", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HTML(value=\"./tmp0tr4ge2e.gif
\")" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "from open_atmos_jupyter_utils.show_anim import show_anim \n", "\n", @@ -34,11 +61,21 @@ ], "metadata": { "kernelspec": { - "display_name": "", - "name": "" + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" }, "language_info": { - "name": "" + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.7" } }, "nbformat": 4, diff --git a/open_atmos_jupyter_utils/show_anim.py b/open_atmos_jupyter_utils/show_anim.py index 1507170..6531052 100644 --- a/open_atmos_jupyter_utils/show_anim.py +++ b/open_atmos_jupyter_utils/show_anim.py @@ -21,10 +21,10 @@ def show_anim(plot_func, frame_range, duration=0.01, loop=0): fig.savefig(f"{tmpdirname}/{frame:05d}.png") plt.close(fig) __merge_images_into_gif(tmpdirname, gif_file, duration, loop) - with open(gif_file.basename, "rb").read() as gifname: - b64 = base64.b64encode(gifname.decode("ascii")) - display(HTML(f'')) - display(gif_file.make_link_widget()) + + b64 = base64.b64encode(open(gif_file.basename,'rb').read()).decode("ascii") + display(HTML(f'')) + display(gif_file.make_link_widget()) def __merge_images_into_gif(image_folder, gif_name, duration, loop): From 83e9b77672c39a61c8aa8fe49fcf104ea17717a1 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:09:10 +0100 Subject: [PATCH 21/36] added line so pylint ignores a warning --- open_atmos_jupyter_utils/show_anim.py | 1 + 1 file changed, 1 insertion(+) diff --git a/open_atmos_jupyter_utils/show_anim.py b/open_atmos_jupyter_utils/show_anim.py index 6531052..6d7cafd 100644 --- a/open_atmos_jupyter_utils/show_anim.py +++ b/open_atmos_jupyter_utils/show_anim.py @@ -1,6 +1,7 @@ """inline animation function that allows rendering on github preview and showing click to download gif button""" +#pylint: disable=consider-using-wtih import os import tempfile import base64 From 74f68cdd650835d31248a28b8aa881b70695bfe9 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:10:42 +0100 Subject: [PATCH 22/36] fixed a typo in pylint disable --- open_atmos_jupyter_utils/show_anim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/open_atmos_jupyter_utils/show_anim.py b/open_atmos_jupyter_utils/show_anim.py index 6d7cafd..02462b9 100644 --- a/open_atmos_jupyter_utils/show_anim.py +++ b/open_atmos_jupyter_utils/show_anim.py @@ -1,7 +1,7 @@ """inline animation function that allows rendering on github preview and showing click to download gif button""" -#pylint: disable=consider-using-wtih +#pylint: disable=consider-using-with import os import tempfile import base64 From 175b677174593823f40b05ce4387b239f3922d0e Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:15:58 +0100 Subject: [PATCH 23/36] fix yml formatting --- .github/workflows/tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7810a65..68b461f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,4 +1,4 @@ -name: tests +fname: tests on: push: @@ -16,6 +16,7 @@ jobs: uses: actions/setup-python@v5 with: python-version: 3.12 + - name: Run tests run: | pip install -r tests/devops_tests/requirements.txt pytest -vv -rP -We tests/devops_tests/test_notebooks.py::test_run_notebook From 5d18a9c8099a10e9ae0c78ce79e048e13a392ae4 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:16:53 +0100 Subject: [PATCH 24/36] fixed typo in tests.yml --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 68b461f..2939157 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,4 +1,4 @@ -fname: tests +name: tests on: push: From 4697a351b6d553f8d8801358861c167558848233 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:19:51 +0100 Subject: [PATCH 25/36] changed submodule name --- .gitmodules | 2 +- tests/{devops_tests.git => devops_tests} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/{devops_tests.git => devops_tests} (100%) diff --git a/.gitmodules b/.gitmodules index 095049d..7dea030 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "tests/devops_tests.git"] - path = tests/devops_tests.git + path = tests/devops_tests url = git@github.com:open-atmos/devops_tests.git diff --git a/tests/devops_tests.git b/tests/devops_tests similarity index 100% rename from tests/devops_tests.git rename to tests/devops_tests From 9d0c042200dc5451736ff940a3cb4291755f3d2f Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:31:43 +0100 Subject: [PATCH 26/36] add ls to tests.yml for debuging purposes --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2939157..ecb0e70 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,5 +18,6 @@ jobs: python-version: 3.12 - name: Run tests run: | + ls pip install -r tests/devops_tests/requirements.txt pytest -vv -rP -We tests/devops_tests/test_notebooks.py::test_run_notebook From aab1de0143eb285d56ee9f0bf17ddc767138bcd5 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:32:28 +0100 Subject: [PATCH 27/36] add ls to tests.yml for debuging purposes --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ecb0e70..7b2679e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,6 +18,6 @@ jobs: python-version: 3.12 - name: Run tests run: | - ls + ls tests pip install -r tests/devops_tests/requirements.txt pytest -vv -rP -We tests/devops_tests/test_notebooks.py::test_run_notebook From c7f43140421d8ac9c25a35718d001d6ab7b0dc90 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:33:14 +0100 Subject: [PATCH 28/36] add ls to tests.yml for debuging purposes --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7b2679e..aa92626 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,6 +18,6 @@ jobs: python-version: 3.12 - name: Run tests run: | - ls tests + ls tests/devops_tests pip install -r tests/devops_tests/requirements.txt pytest -vv -rP -We tests/devops_tests/test_notebooks.py::test_run_notebook From 8006c96180fe7c72fba39d9b2b75576ad3c5dbf1 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:35:20 +0100 Subject: [PATCH 29/36] add submodules to checkout in tests.yml --- .github/workflows/tests.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index aa92626..3d6def9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,13 +11,15 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: true - name: Set up Python 3.12 uses: actions/setup-python@v5 with: python-version: 3.12 - name: Run tests run: | - ls tests/devops_tests pip install -r tests/devops_tests/requirements.txt pytest -vv -rP -We tests/devops_tests/test_notebooks.py::test_run_notebook From 54e999fc7c4034296c3f58159b992abbfe39eb16 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:36:57 +0100 Subject: [PATCH 30/36] fixed typo in tests.yml test section --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3d6def9..0c014c2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,4 +22,4 @@ jobs: - name: Run tests run: | pip install -r tests/devops_tests/requirements.txt - pytest -vv -rP -We tests/devops_tests/test_notebooks.py::test_run_notebook + pytest -vv -rP -We tests/devops_tests/test_notebooks.py::test_run_notebooks From 5d2ea5c8e64f7d45f095816044d05b72e370d2bc Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:42:15 +0100 Subject: [PATCH 31/36] added requirements.txt to jupyter-utils for workflows usage --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0c014c2..a825cc3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,5 +21,6 @@ jobs: python-version: 3.12 - name: Run tests run: | + pip install -r requirements.txt pip install -r tests/devops_tests/requirements.txt pytest -vv -rP -We tests/devops_tests/test_notebooks.py::test_run_notebooks From 3b354865a2d0e7184b033502ec0657df3ef923ea Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:43:18 +0100 Subject: [PATCH 32/36] actually upload the file this time --- requirements.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..eb82013 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +matplotlib +ipywidgets +IPython +imageio \ No newline at end of file From 0fae733cdfafdc87143e1f8d5b5a131641ee2e6a Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 22:44:52 +0100 Subject: [PATCH 33/36] added open_atmos_jupyter_utils to modules in tests.yml --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a825cc3..84c5ffa 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,6 +21,7 @@ jobs: python-version: 3.12 - name: Run tests run: | + pip install -e . pip install -r requirements.txt pip install -r tests/devops_tests/requirements.txt pytest -vv -rP -We tests/devops_tests/test_notebooks.py::test_run_notebooks From db4bdc5aaae3670fd992e93573a91fe7b76b89f8 Mon Sep 17 00:00:00 2001 From: Sylwester Arabas Date: Fri, 29 Nov 2024 00:03:27 +0100 Subject: [PATCH 34/36] cleanup README text --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 148ecf2..d81a03d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Utility routines used in Jupyter notebooks in [PySDM](https://github.com/open-atmos/PySDM), [PyMPDATA](https://github.com/open-atmos/PyMPDATA) and [PyPartMC](https://github.com/open-atmos/PyPartMC) projects: - [``show_plot()``](https://open-atmos.github.io/jupyter-utils/open_atmos_jupyter_utils/show_plot.html) - a drop-in replacement for matplotlib's show() displaying the figure inline using vector graphics (svg) by default and offering a download-as-pdf-or-svg widget just below (on Colab the widget triggers Google Drive download) -- [``show_anim()``](https://open-atmos.github.io/jupyter-utils/open_atmos_jupyter_utils/show_anim.html) - a replacement for matplotlib's FuncAnimate() that displays animations in gif format inline based on given plotting function and by default and offers a way to download the file from inside notebooks (github renderer included) +- [``show_anim()``](https://open-atmos.github.io/jupyter-utils/open_atmos_jupyter_utils/show_anim.html) - a replacement for matplotlib's FuncAnimate() that inline-displays animations in gif format (thus github renderer compatible) and offers a way to download the .gif file (on Colab the widget triggers Google Drive download) - [``TemporaryFile``](https://open-atmos.github.io/jupyter-utils/open_atmos_jupyter_utils/temporary_file.html) - a class equipped with ``make_link_widget()`` method returning a click-to-download Colab-compatible widget to be display()-ed in a Jupyter notebook - [``pip_install_on_colab('package_a', 'package_b', ...)``](https://open-atmos.github.io/jupyter-utils/open_atmos_jupyter_utils/pip_install_on_colab.html) - a function handling execution of ``pip`` (and ``ldconfig``) on Colab From d9a564f0f28a78ca2df8459965d433af7e401691 Mon Sep 17 00:00:00 2001 From: Sylwester Arabas Date: Fri, 29 Nov 2024 00:04:24 +0100 Subject: [PATCH 35/36] delete requirements.txt since we have this information in the package metadata --- requirements.txt | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index eb82013..0000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -matplotlib -ipywidgets -IPython -imageio \ No newline at end of file From 7f470b76826182d4d81cb0685063dd13ae9db901 Mon Sep 17 00:00:00 2001 From: Sylwester Arabas Date: Fri, 29 Nov 2024 00:05:10 +0100 Subject: [PATCH 36/36] do not do pip install -r requirements.txt (pip install should do it) --- .github/workflows/tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 84c5ffa..52f5c36 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,6 +22,5 @@ jobs: - name: Run tests run: | pip install -e . - pip install -r requirements.txt pip install -r tests/devops_tests/requirements.txt pytest -vv -rP -We tests/devops_tests/test_notebooks.py::test_run_notebooks