From b988aa25cd648e5dac02dae78cc52cb09253635b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agnieszka=20=C5=BBaba?= Date: Mon, 19 May 2025 22:54:37 +0200 Subject: [PATCH 1/3] add test that checks build req. with examples --- test_build_requirements.py | 16 ++++++++++++++++ test_notebooks.py | 34 ++++++++-------------------------- utils.py | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 test_build_requirements.py diff --git a/test_build_requirements.py b/test_build_requirements.py new file mode 100644 index 0000000..0ba0454 --- /dev/null +++ b/test_build_requirements.py @@ -0,0 +1,16 @@ +"""checks requirements consistency between PySDM and PySDM examples""" + +import tomllib +from pathlib import Path + +from .utils import repo_path + + +def test_build_requirements_with_examples(): + """tests if build requirements in PySDM and PySDM examples matches""" + with open(Path(repo_path(), "pyproject.toml"), "rb") as proj_f: + with open(Path(repo_path(), "examples/pyproject.toml"), "rb") as examples_f: + assert ( + tomllib.load(proj_f)["build-system"]["requires"] + == tomllib.load(examples_f)["build-system"]["requires"] + ) diff --git a/test_notebooks.py b/test_notebooks.py index ba28eb4..4e2f948 100644 --- a/test_notebooks.py +++ b/test_notebooks.py @@ -11,7 +11,6 @@ import gc import os -import pathlib import warnings import nbformat @@ -19,7 +18,7 @@ import pytest from git.cmd import Git -from .utils import find_files +from .utils import find_files, relative_path, repo_path with warnings.catch_warnings(): warnings.filterwarnings("ignore") @@ -28,28 +27,11 @@ SI = pint.UnitRegistry() -def _relative_path(absolute_path): - """returns a path relative to the repo base (converting backslashes to slashes on Windows)""" - relpath = os.path.relpath(absolute_path, _repo_path().absolute()) - posixpath_to_make_it_usable_in_urls_even_on_windows = pathlib.Path( - relpath - ).as_posix() - return posixpath_to_make_it_usable_in_urls_even_on_windows - - -def _repo_path(): - """returns absolute path to the repo base (ignoring .git location if in a submodule)""" - path = pathlib.Path(__file__) - while not (path.is_dir() and Git(path).rev_parse("--git-dir") == ".git"): - path = path.parent - return path - - COLAB_HEADER = f"""import sys if 'google.colab' in sys.modules: !pip --quiet install open-atmos-jupyter-utils from open_atmos_jupyter_utils import pip_install_on_colab - pip_install_on_colab('{_repo_path().name}-examples')""" + pip_install_on_colab('{repo_path().name}-examples')""" @pytest.fixture( @@ -119,8 +101,8 @@ def _preview_badge_markdown(absolute_path): + "label=render%20on&logo=github&color=87ce3e&message=GitHub" ) link = ( - f"https://github.com/open-atmos/{_repo_path().name}/blob/main/" - + f"{_relative_path(absolute_path)}" + f"https://github.com/open-atmos/{repo_path().name}/blob/main/" + + f"{relative_path(absolute_path)}" ) return f"[![preview notebook]({svg_badge_url})]({link})" @@ -128,8 +110,8 @@ def _preview_badge_markdown(absolute_path): def _mybinder_badge_markdown(abslute_path): svg_badge_url = "https://mybinder.org/badge_logo.svg" link = ( - f"https://mybinder.org/v2/gh/open-atmos/{_repo_path().name}.git/main?urlpath=lab/tree/" - + f"{_relative_path(abslute_path)}" + f"https://mybinder.org/v2/gh/open-atmos/{repo_path().name}.git/main?urlpath=lab/tree/" + + f"{relative_path(abslute_path)}" ) return f"[![launch on mybinder.org]({svg_badge_url})]({link})" @@ -137,8 +119,8 @@ def _mybinder_badge_markdown(abslute_path): def _colab_badge_markdown(absolute_path): svg_badge_url = "https://colab.research.google.com/assets/colab-badge.svg" link = ( - f"https://colab.research.google.com/github/open-atmos/{_repo_path().name}/blob/main/" - + f"{_relative_path(absolute_path)}" + f"https://colab.research.google.com/github/open-atmos/{repo_path().name}/blob/main/" + + f"{relative_path(absolute_path)}" ) return f"[![launch on Colab]({svg_badge_url})]({link})" diff --git a/utils.py b/utils.py index 50e0cf6..376b2d5 100644 --- a/utils.py +++ b/utils.py @@ -3,10 +3,28 @@ """ import os +import pathlib from git.cmd import Git +def relative_path(absolute_path): + """returns a path relative to the repo base (converting backslashes to slashes on Windows)""" + relpath = os.path.relpath(absolute_path, _repo_path().absolute()) + posixpath_to_make_it_usable_in_urls_even_on_windows = pathlib.Path( + relpath + ).as_posix() + return posixpath_to_make_it_usable_in_urls_even_on_windows + + +def repo_path(): + """returns absolute path to the repo base (ignoring .git location if in a submodule)""" + path = pathlib.Path(__file__) + while not (path.is_dir() and Git(path).rev_parse("--git-dir") == ".git"): + path = path.parent + return path + + def find_files(path_to_folder_from_project_root=".", file_extension=None): """ Returns all files in a current git repo. From 7d618e833881a0ed69de1804048781ffe6c7153d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agnieszka=20=C5=BBaba?= Date: Tue, 20 May 2025 00:15:48 +0200 Subject: [PATCH 2/3] remove unused import; update function name --- test_notebooks.py | 1 - utils.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test_notebooks.py b/test_notebooks.py index 4e2f948..c42f0da 100644 --- a/test_notebooks.py +++ b/test_notebooks.py @@ -16,7 +16,6 @@ import nbformat import pint import pytest -from git.cmd import Git from .utils import find_files, relative_path, repo_path diff --git a/utils.py b/utils.py index 376b2d5..98eaa51 100644 --- a/utils.py +++ b/utils.py @@ -10,7 +10,7 @@ def relative_path(absolute_path): """returns a path relative to the repo base (converting backslashes to slashes on Windows)""" - relpath = os.path.relpath(absolute_path, _repo_path().absolute()) + relpath = os.path.relpath(absolute_path, repo_path().absolute()) posixpath_to_make_it_usable_in_urls_even_on_windows = pathlib.Path( relpath ).as_posix() From 31a81a24788fc56e7bb331d2b53bf1e649620344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agnieszka=20=C5=BBaba?= Date: Tue, 20 May 2025 13:33:41 +0200 Subject: [PATCH 3/3] add pyproject.toml files for testing --- examples/pyproject.toml | 3 +++ pyproject.toml | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 examples/pyproject.toml create mode 100644 pyproject.toml diff --git a/examples/pyproject.toml b/examples/pyproject.toml new file mode 100644 index 0000000..9b6e7fd --- /dev/null +++ b/examples/pyproject.toml @@ -0,0 +1,3 @@ +# only for testing +[build-system] +requires = [] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9b6e7fd --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +# only for testing +[build-system] +requires = []