From 73498ce5b10662e637d059566c51335d5710e13b Mon Sep 17 00:00:00 2001 From: "r.jaepel" <r.jaepel@fz-juelich.de> Date: Mon, 18 Dec 2023 20:19:22 +0100 Subject: [PATCH] add "add_filetype_to_lfs" convenience function --- cadetrdm/cli_integration.py | 6 ++---- cadetrdm/repositories.py | 11 +++++++++++ docs/source/user_guide/getting-started.md | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/cadetrdm/cli_integration.py b/cadetrdm/cli_integration.py index 65990ab..d2c85b0 100644 --- a/cadetrdm/cli_integration.py +++ b/cadetrdm/cli_integration.py @@ -97,11 +97,9 @@ def add_remote_to_repo(remote_url: str, path_to_repo="."): @cli.command() @click.argument('file_type') -def add_file_type_to_lfs(file_type: str, ): - init_lfs(lfs_filetypes=[file_type], path=".") +def add_filetype_to_lfs(file_type: str, ): repo = BaseRepo(".") - repo.add_all_files() - repo.commit(f"Add {file_type} to lfs") + repo.add_filetype_to_lfs(file_type) @cli.command() diff --git a/cadetrdm/repositories.py b/cadetrdm/repositories.py index 6fc2d69..1c1d246 100644 --- a/cadetrdm/repositories.py +++ b/cadetrdm/repositories.py @@ -15,6 +15,7 @@ from ipylab import JupyterFrontEnd from tabulate import tabulate import pandas as pd +from cadetrdm.initialize_repo import init_lfs from cadetrdm.io_utils import recursive_chmod, write_lines_to_file, wait_for_user from cadetrdm.jupyter_functionality import Notebook from cadetrdm.remote_integration import create_gitlab_remote @@ -145,7 +146,17 @@ class BaseRepo: project_repo.add_list_of_remotes_in_readme_file("output_repo", self.remote_urls) project_repo.commit("Add remote for output repo") + def add_filetype_to_lfs(self, file_type): + """ + Add the filetype given in file_type to the GIT-LFS tracking + :param file_type: + Wildcard formatted string. Examples: "*.png" or "*.xlsx" + :return: + """ + init_lfs(lfs_filetypes=[file_type], path=self.working_dir) + self.add_all_files() + self.commit(f"Add {file_type} to lfs") def import_remote_repo(self, source_repo_location, source_repo_branch, target_repo_location=None): """ diff --git a/docs/source/user_guide/getting-started.md b/docs/source/user_guide/getting-started.md index fa9060b..6e0561f 100644 --- a/docs/source/user_guide/getting-started.md +++ b/docs/source/user_guide/getting-started.md @@ -35,3 +35,20 @@ repo.create_gitlab_remotes( name="e.g. API_test_project" ) ``` + +## Extending GIT-LFS scope + +Several common datatypes are included in GIT-LFS by default. These currently are +`"*.jpg", "*.png", "*.xlsx", "*.h5", "*.ipynb", "*.pdf", "*.docx", "*.zip", "*.html"` + +You can add datatypes you require by running: + +````python +repo.add_filetype_to_lfs("*.npy") +```` + +or + +````commandline +cadet-rdm add_filetype_to_lfs *.npy +```` -- GitLab