Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# only for testing
[build-system]
requires = []
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# only for testing
[build-system]
requires = []
16 changes: 16 additions & 0 deletions test_build_requirements.py
Original file line number Diff line number Diff line change
@@ -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"]
)
35 changes: 8 additions & 27 deletions test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@

import gc
import os
import pathlib
import warnings

import nbformat
import pint
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")
Expand All @@ -28,28 +26,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(
Expand Down Expand Up @@ -119,26 +100,26 @@ 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})"


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})"


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})"

Expand Down
18 changes: 18 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading