Skip to content

Commit

Permalink
Merge pull request #33 from neuro-ml/dev
Browse files Browse the repository at this point in the history
add defaults to cli functions
  • Loading branch information
STNLd2 committed Aug 22, 2023
2 parents 2e35005 + 9194471 commit 0e6b7f5
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 54 deletions.
2 changes: 1 addition & 1 deletion bev/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.10.1'
__version__ = '0.10.2'
23 changes: 12 additions & 11 deletions bev/cli/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import typer
from rich.progress import track
from tqdm.auto import tqdm
from typing_extensions import Annotated

from ..exceptions import HashError
from ..hash import is_hash, to_hash
Expand All @@ -20,20 +21,20 @@

@app_command
def add(
sources: List[Path] = typer.Argument(..., help='The source paths to add', show_default=False),
destination: Optional[Path] = typer.Option(
None, '--destination', '--dst',
sources: Annotated[List[Path], typer.Argument(help='The source paths to add', show_default=False)],
destination: Annotated[Optional[Path], typer.Option(
'--destination', '--dst',
help='The destination at which the hashes will be stored. '
'If none - the hashes will be stored alongside the source'
),
keep: bool = typer.Option(False, help='Whether to keep the sources after hashing'),
conflict: Conflict = typer.Option(
'error', case_sensitive=False, help=Conflict.__doc__.replace('\n\n', '\n').replace('\n', '\n\n')
),
repository: Path = typer.Option(
None, '--repository', '--repo', help='The bev repository. It is usually detected automatically',
)] = None,
keep: Annotated[bool, typer.Option(help='Whether to keep the sources after hashing')] = False,
conflict: Annotated[Conflict, typer.Option(
case_sensitive=False, help=Conflict.__doc__.replace('\n\n', '\n').replace('\n', '\n\n')
)] = 'error',
repository: Annotated[Path, typer.Option(
'--repository', '--repo', help='The bev repository. It is usually detected automatically',
show_default=False,
)
)] = None
):
"""Add files and/or folders to a bev repository"""
pairs, repo = normalize_sources_and_destination(sources, destination, repository)
Expand Down
5 changes: 3 additions & 2 deletions bev/cli/blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import typer
from tqdm.auto import tqdm
from typing_extensions import Annotated

from ..hash import from_hash, is_hash
from ..shortcuts import get_current_repo
Expand All @@ -12,8 +13,8 @@

@app_command
def blame(
path: Path = typer.Argument(..., help='Path to the hash'),
relative: str = typer.Argument(..., help='The relative path inside the hashed folder')
path: Annotated[Path, typer.Argument(help='Path to the hash')],
relative: Annotated[str, typer.Argument(help='The relative path inside the hashed folder')]
):
"""Find the closest version which introduced a change to a value RELATIVE to the PATH"""

Expand Down
11 changes: 7 additions & 4 deletions bev/cli/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import typer
from rich.progress import track
from typing_extensions import Annotated

from ..exceptions import HashError
from ..hash import from_hash, is_hash, is_tree, load_key, load_tree, strip_tree, to_hash
Expand Down Expand Up @@ -31,11 +32,13 @@ def _fetch(repo: Repository, path: Path):

@app_command
def fetch(
paths: List[Path] = typer.Argument(None, help='The paths to fetch', show_default='The current directory'),
repository: Path = typer.Option(
None, '--repository', '--repo', help='The bev repository. It is usually detected automatically',
paths: Annotated[List[Path], typer.Argument(
help='The paths to fetch', show_default='The current directory'
)] = None,
repository: Annotated[Path, typer.Option(
'--repository', '--repo', help='The bev repository. It is usually detected automatically',
show_default=False,
)
)] = None
):
"""Fetch the missing values from remote, if possible"""
paths = paths or [Path('.')]
Expand Down
19 changes: 10 additions & 9 deletions bev/cli/init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

import typer
from typing_extensions import Annotated

from ..config import CONFIG, load_config
from ..shortcuts import get_consistent_repo_root
Expand All @@ -9,16 +10,16 @@

@app_command
def init(
repository: Path = typer.Option(
None, '--repository', '--repo', help='The bev repository. It is usually detected automatically',
repository: Annotated[Path, typer.Option(
'--repository', '--repo', help='The bev repository. It is usually detected automatically',
show_default=False,
),
permissions: str = typer.Option(
None, '--permissions', '-p', help='The permissions mask used to create the storage, e.g. 770',
),
group: str = typer.Option(
None, '--group', '-g', help='The group used to create the storage',
),
)] = None,
permissions: Annotated[str, typer.Option(
'--permissions', '-p', help='The permissions mask used to create the storage, e.g. 770',
)] = None,
group: Annotated[str, typer.Option(
'--group', '-g', help='The group used to create the storage',
)] = None,
):
"""Initialize a bev repository by creating the storage locations specified in its config"""
if repository is None:
Expand Down
25 changes: 15 additions & 10 deletions bev/cli/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import typer
from rich.progress import track
from typing_extensions import Annotated

from ..exceptions import HashError
from ..hash import from_hash, is_hash, to_hash
Expand All @@ -31,19 +32,23 @@ class PullMode(Enum):

@app_command
def pull(
sources: List[Path] = typer.Argument(..., help='The source paths to add', show_default=False),
mode: PullMode = typer.Option(..., help=PullMode.__doc__, show_default=False),
destination: Optional[Path] = typer.Option(
None, '--destination', '--dst',
sources: Annotated[List[Path], typer.Argument(help='The source paths to add', show_default=False)],
mode: Annotated[PullMode, typer.Option(help=PullMode.__doc__, show_default=False)],
destination: Annotated[Optional[Path], typer.Option(
'--destination', '--dst',
help='The destination at which the results will be stored. '
'If none - the results will be stored alongside the source'
),
keep: bool = typer.Option(False, help='Whether to keep the sources after pulling the real files'),
fetch: bool = typer.Option(False, help='Whether to fetch the missing files from remote, if possible'),
repository: Path = typer.Option(
None, '--repository', '--repo', help='The bev repository. It is usually detected automatically',
)] = None,
keep: Annotated[bool, typer.Option(
help='Whether to keep the sources after pulling the real files'
)] = False,
fetch: Annotated[bool, typer.Option(
help='Whether to fetch the missing files from remote, if possible'
)] = True,
repository: Annotated[Path, typer.Option(
'--repository', '--repo', help='The bev repository. It is usually detected automatically',
show_default=False,
)
)] = None
):
"""Restore the files and folders that were added to storage"""

Expand Down
23 changes: 12 additions & 11 deletions bev/cli/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import typer
from tarn.config import StorageConfig, init_storage
from typing_extensions import Annotated

from .app import app_command, cli_error

Expand All @@ -21,17 +22,17 @@ class Hashes(Enum):

@app_command
def storage(
path: Path = typer.Argument('.', help='The path to the storage root', show_default='The current directory'),
hash: Hashes = typer.Option('sha256', help='The hashing algorithm to use'),
levels: List[int] = typer.Option(
None, help='The levels of folders nesting', show_default='1, digest_size - 1'
),
permissions: str = typer.Option(
None, '--permissions', '-p', help='The permissions mask used to create the storage, e.g. 770',
),
group: str = typer.Option(
None, '--group', '-g', help='The group used to create the storage',
),
path: Annotated[Path, typer.Argument(help='The path to the storage root', show_default='The current directory')] = '.',
hash: Annotated[Hashes, typer.Option(help='The hashing algorithm to use')] = 'sha256',
levels: Annotated[List[int], typer.Option(
help='The levels of folders nesting', show_default='1, digest_size - 1'
)] = None,
permissions: Annotated[str, typer.Option(
'--permissions', '-p', help='The permissions mask used to create the storage, e.g. 770',
)] = None,
group: Annotated[str, typer.Option(
'--group', '-g', help='The group used to create the storage',
)] = None,
):
"""Create a storage at a given path"""

Expand Down
15 changes: 9 additions & 6 deletions bev/cli/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Optional

import typer
from typing_extensions import Annotated

from ..ops import Conflict
from .add import add
Expand All @@ -11,14 +12,16 @@

@_app.command(deprecated=True)
def update(
source: Path = typer.Argument(..., help='The source path to gather', show_default=False),
destination: Optional[Path] = typer.Option(
None, '--destination', '--dst',
source: Annotated[Path, typer.Argument(help='The source path to gather', show_default=False)],
destination: Annotated[Optional[Path], typer.Option(
'--destination', '--dst',
help='The destination at which the hashes will be stored. '
'If none - the hashes will be stored alongside the source'
),
keep: bool = typer.Option(False, help='Whether to keep the sources after hashing'),
overwrite: bool = typer.Option(False, help='Whether to overwrite the existing values in case of conflict'),
)] = None,
keep: Annotated[bool, typer.Option(help='Whether to keep the sources after hashing')] = False,
overwrite: Annotated[bool, typer.Option(
help='Whether to overwrite the existing values in case of conflict'
)] = False,
): # pragma: no cover
"""Add new entries to a folder hash. Warning! this command is superseded by "add" and will be removed soon"""

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ typer
rich
jboc<1.0.0
humanfriendly
typing_extensions

0 comments on commit 0e6b7f5

Please sign in to comment.