Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions .actions/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
_PATH_HERE = os.path.dirname(__file__)
_PATH_ROOT = os.path.dirname(_PATH_HERE)
PATH_SCRIPT_RENDER = os.path.join(_PATH_HERE, "_ipynb-render.sh")
PATH_SCRIPT_TEST = os.path.join(_PATH_HERE, "_ipynb-test.sh")
PATH_SCRIPT_TEST = os.path.join(_PATH_HERE, "_ipynb-validate.sh")
# https://askubuntu.com/questions/909918/how-to-show-unzip-progress
UNZIP_PROGRESS_BAR = ' | awk \'BEGIN {ORS=" "} {if(NR%10==0)print "."}\''
REPO_NAME = "lightning-tutorials"
Expand Down Expand Up @@ -393,7 +393,7 @@ def bash_render(folder: str, output_file: str = PATH_SCRIPT_RENDER) -> Optional[
fopen.write(os.linesep.join(cmd))

@staticmethod
def bash_test(folder: str, output_file: str = PATH_SCRIPT_TEST, virtualenv: bool = False) -> Optional[str]:
def bash_validate(folder: str, output_file: str = PATH_SCRIPT_TEST, virtualenv: bool = False) -> Optional[str]:
"""Prepare bash script for running tests of a particular notebook.

Args:
Expand Down Expand Up @@ -551,7 +551,7 @@ def group_folders(
fpath_drop_folders: output file with deleted folders
fpath_actual_dirs: files with listed all folder in particular stat
strict: raise error if some folder outside skipped does not have valid meta file
root_path: path to the root tobe added for all local folder paths in files
root_path: path to the root to be added for all local folder paths in files

Example:
$ python assistant.py group-folders ../target-diff.txt \
Expand All @@ -571,12 +571,26 @@ def group_folders(
# not empty paths
dirs = [ln for ln in dirs if ln]

if root_path:
dirs = [os.path.join(root_path, d) for d in dirs]
# unique folders
dirs = set(dirs)
# drop folder that start with . or _ as they are meant to be internal use only
dirs = [pdir for pdir in dirs if not any(ndir[0] in (".", "_") for ndir in pdir.split(os.path.sep))]
# append a path to root in case you call this from other path then root
if root_path:
dirs = [os.path.join(root_path, d) for d in dirs]
# append all subfolders in case of parent requirements has been changed all related notebooks shall be updated
dirs_expanded = []
for dir in dirs:
# in case that the diff item comes from removed folder
if not os.path.isdir(dir):
dirs_expanded += [dir]
continue
# list folder and skip all internal files, starting with . or _
sub_dirs = [os.path.join(dir, it) for it in os.listdir(dir) if it[0] not in (".", "_")]
# filter only folders
sub_dirs = [it for it in sub_dirs if os.path.isdir(it)]
# if the dir has sub-folder append then otherwise append the dir itself
dirs_expanded += sub_dirs if sub_dirs else [dir]
# unique folders only, drop duplicates
dirs = set(dirs_expanded)
# valid folder has meta
dirs_exist = [d for d in dirs if os.path.isdir(d)]
dirs_invalid = [d for d in dirs_exist if not AssistantCLI._find_meta(d)]
Expand Down
30 changes: 19 additions & 11 deletions .actions/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,25 @@ def _path_in_dir(fname: str, folder: str = _PATH_ROOT) -> str:


@pytest.mark.parametrize(
"cmd,args",
"cmd,kwargs",
[
("list_dirs", []),
("list_dirs", [".", ".ipynb"]),
("bash_render", [_PATH_DIR_SIMPLE]),
("bash_test", [_PATH_DIR_SIMPLE]),
("group_folders", [_path_in_dir("master-diff.txt"), _path_in_dir("dirs-b1.txt"), _path_in_dir("dirs-b2.txt")]),
("convert_ipynb", [_PATH_DIR_SIMPLE]),
("copy_notebooks", [_PATH_ROOT]),
("update_env_details", [_PATH_DIR_SIMPLE]),
("list_dirs", {}),
("list_dirs", dict(folder=".", include_file_ext=".ipynb")),
("bash_render", dict(folder=_PATH_DIR_SIMPLE)),
("bash_validate", dict(folder=_PATH_DIR_SIMPLE)),
(
"group_folders",
dict(
fpath_gitdiff=_path_in_dir("master-diff.txt"),
fpath_change_folders=_path_in_dir("dirs-b1.txt"),
fpath_drop_folders=_path_in_dir("dirs-b2.txt"),
root_path=_PATH_ROOT,
),
),
("convert_ipynb", dict(folder=_PATH_DIR_SIMPLE)),
("copy_notebooks", dict(path_root=_PATH_ROOT)),
("update_env_details", dict(folder=_PATH_DIR_SIMPLE)),
],
)
def test_assistant_commands(cmd: str, args: list):
AssistantCLI().__getattribute__(cmd)(*args)
def test_assistant_commands(cmd: str, kwargs: dict):
AssistantCLI().__getattribute__(cmd)(**kwargs)
7 changes: 4 additions & 3 deletions .azure/ipynb-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
# printf "Head: $head\n" # this shall be commit hash
# git diff --name-only $head --output=target-diff.txt
git diff --name-only origin/main HEAD --output=target-diff.txt
printf "Diff to target:\n"
cat target-diff.txt
python .actions/assistant.py group-folders --fpath_gitdiff=target-diff.txt
printf "Changed folders:\n"
Expand Down Expand Up @@ -97,9 +98,9 @@ jobs:
- bash: |
set -e
mkdir $(PATH_DATASETS)
python .actions/assistant.py bash-test $(notebook)
cat .actions/_ipynb-test.sh
bash .actions/_ipynb-test.sh
python .actions/assistant.py bash-validate $(notebook)
cat .actions/_ipynb-validate.sh
bash .actions/_ipynb-validate.sh
env:
KAGGLE_USERNAME: $(KAGGLE_USERNAME)
KAGGLE_KEY: $(KAGGLE_KEY)
Expand Down
2 changes: 1 addition & 1 deletion course_UvA-DL/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy <2.0 # needed for older Torch
torch>=1.8.1, <2.1.0
pytorch-lightning>=2.0, <2.1.0
torchmetrics>=0.7, <1.3
torchmetrics>=1.0, <1.3