From 8317c8d8798b6057518bba3a29f8419e73e2a29c Mon Sep 17 00:00:00 2001 From: Khoroshevskyi Date: Tue, 16 Apr 2024 14:28:03 -0400 Subject: [PATCH] updated view creation --- docs/changelog.md | 5 +++ docs/templates/usage.template | 6 +++ docs/usage.md | 65 ++++++++++++++++++++++++++++++ pephubclient/__init__.py | 2 +- pephubclient/helpers.py | 2 +- pephubclient/modules/view.py | 9 +++++ requirements/requirements-test.txt | 2 +- scripts/update_usage_docs.sh | 21 ++++++++++ 8 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 docs/templates/usage.template create mode 100644 docs/usage.md create mode 100755 scripts/update_usage_docs.sh diff --git a/docs/changelog.md b/docs/changelog.md index 71bbe7e..6d63f1d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format. +## [0.4.2] - 2024-04-16 +### Updated +- View creation, by adding description and no_fail flag + + ## [0.4.1] - 2024-03-07 ### Fixed - Expired token error handling ([#17](https://github.com/pepkit/pephubclient/issues/17)) diff --git a/docs/templates/usage.template b/docs/templates/usage.template new file mode 100644 index 0000000..c7211be --- /dev/null +++ b/docs/templates/usage.template @@ -0,0 +1,6 @@ +# Usage reference + +pephubclient is a command line tool that can be used to interact with the PEPhub API. +It can be used to create, update, delete PEPs in the PEPhub database. + +Below are usage examples for the different commands that can be used with pephubclient. \ No newline at end of file diff --git a/docs/usage.md b/docs/usage.md new file mode 100644 index 0000000..6fd05bd --- /dev/null +++ b/docs/usage.md @@ -0,0 +1,65 @@ +# Usage reference + +pephubclient is a command line tool that can be used to interact with the PEPhub API. +It can be used to create, update, delete PEPs in the PEPhub database. + +Below are usage examples for the different commands that can be used with pephubclient.## `phc --help` +```console + + Usage: pephubclient [OPTIONS] COMMAND [ARGS]... + +╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ --version -v App version │ +│ --install-completion [bash|zsh|fish|powershell|pwsh] Install completion for the specified shell. [default: None] │ +│ --show-completion [bash|zsh|fish|powershell|pwsh] Show completion for the specified shell, to copy it or customize the installation. [default: None] │ +│ --help Show this message and exit. │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ login Login to PEPhub │ +│ logout Logout │ +│ pull Download and save project locally. │ +│ push Upload/update project in PEPhub │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ + +``` + +## `phc pull --help` +```console + + Usage: pephubclient pull [OPTIONS] PROJECT_REGISTRY_PATH + + Download and save project locally. + +╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ * project_registry_path TEXT [default: None] [required] │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ --force --no-force Overwrite project if it exists. [default: no-force] │ +│ --zip --no-zip Save project as zip file. [default: no-zip] │ +│ --output TEXT Output directory. [default: None] │ +│ --help Show this message and exit. │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ + +``` + +## `phc push --help` +```console + + Usage: pephubclient push [OPTIONS] CFG + + Upload/update project in PEPhub + +╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ * cfg TEXT Project config file (YAML) or sample table (CSV/TSV)with one row per sample to constitute project [default: None] [required] │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ * --namespace TEXT Project namespace [default: None] [required] │ +│ * --name TEXT Project name [default: None] [required] │ +│ --tag TEXT Project tag [default: None] │ +│ --force --no-force Force push to the database. Use it to update, or upload project. [default: no-force] │ +│ --is-private --no-is-private Upload project as private. [default: no-is-private] │ +│ --help Show this message and exit. │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ + +``` + diff --git a/pephubclient/__init__.py b/pephubclient/__init__.py index 0c45462..9ae0611 100644 --- a/pephubclient/__init__.py +++ b/pephubclient/__init__.py @@ -4,7 +4,7 @@ import coloredlogs __app_name__ = "pephubclient" -__version__ = "0.4.1" +__version__ = "0.4.2" __author__ = "Oleksandr Khoroshevskyi, Rafal Stepien" diff --git a/pephubclient/helpers.py b/pephubclient/helpers.py index e2f53f4..f2911ce 100644 --- a/pephubclient/helpers.py +++ b/pephubclient/helpers.py @@ -35,7 +35,7 @@ def send_request( headers: Optional[dict] = None, cookies: Optional[dict] = None, params: Optional[dict] = None, - json: Optional[dict] = None, + json: Optional[Union[dict, list]] = None, ) -> requests.Response: request_return = requests.request( method=method, diff --git a/pephubclient/modules/view.py b/pephubclient/modules/view.py index f68d36c..7c73722 100644 --- a/pephubclient/modules/view.py +++ b/pephubclient/modules/view.py @@ -71,7 +71,9 @@ def create( name: str, tag: str, view_name: str, + description: str = None, sample_list: list = None, + no_fail: bool = False, ): """ Create view in project in PEPhub. @@ -79,9 +81,15 @@ def create( :param namespace: namespace of project :param name: name of project :param tag: tag of project + :param description: description of the view :param view_name: name of the view :param sample_list: list of sample names + :param no_fail: whether to raise an error if view was not added to the project """ + + if not sample_list or not isinstance(sample_list, list): + raise ValueError("Sample list must be a list of sample names.") + url = self._build_view_request_url( namespace=namespace, name=name, view_name=view_name ) @@ -92,6 +100,7 @@ def create( method="POST", url=url, headers=self.parse_header(self.__jwt_data), + params={"description": description, "no_fail": no_fail}, json=sample_list, ) if response.status_code == ResponseStatusCodes.ACCEPTED: diff --git a/requirements/requirements-test.txt b/requirements/requirements-test.txt index ba8d468..65d4db9 100644 --- a/requirements/requirements-test.txt +++ b/requirements/requirements-test.txt @@ -8,4 +8,4 @@ coveralls pytest-cov pre-commit coverage -smokeshow +smokeshow \ No newline at end of file diff --git a/scripts/update_usage_docs.sh b/scripts/update_usage_docs.sh new file mode 100755 index 0000000..95d150e --- /dev/null +++ b/scripts/update_usage_docs.sh @@ -0,0 +1,21 @@ +#!/bin/bash +cp ../docs/templates/usage.template usage.template + +for cmd in "--help" "pull --help" "push --help"; do + echo $cmd + echo -e "## \`phc $cmd\`" > USAGE_header.temp + phc $cmd --help > USAGE.temp 2>&1 + # sed -i 's/^/\t/' USAGE.temp + sed -i.bak '1s;^;\`\`\`console\ +;' USAGE.temp +# sed -i '1s/^/\n\`\`\`console\n/' USAGE.temp + echo -e "\`\`\`\n" >> USAGE.temp + #sed -i -e "/\`looper $cmd\`/r USAGE.temp" -e '$G' usage.template # for -in place inserts + cat USAGE_header.temp USAGE.temp >> usage.template # to append to the end +done +rm USAGE.temp +rm USAGE_header.temp +rm USAGE.temp.bak +mv usage.template ../docs/usage.md +#cat usage.template +# rm USAGE.temp \ No newline at end of file