Skip to content

Commit

Permalink
Sync only offline runs (#894)
Browse files Browse the repository at this point in the history
* add sync all offline containers arg and logic

* add method to sync all offline containers

* text formatting

* add offline-only arg docstring

* remove default false

* adding default value back

* remove email policy

* remove metavar

* add exception for use of object_names and offline

* black format

* refactor sync_all_containers

* Update changelog for upcoming release

* add unreleased tag
  • Loading branch information
Blaizzy authored May 11, 2022
1 parent bd66c94 commit 806d76d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [UNRELEASED] neptune-client 0.16.2

## Features
- Sync only offline runs inside '.neptune' directory CLI flag ([#894](https://github.com/neptune-ai/neptune-client/pull/894))

## neptune-client 0.16.1

## Features
Expand Down
26 changes: 25 additions & 1 deletion neptune/new/sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,19 @@ def status(path: Path) -> None:
metavar="project-name",
help="project name (workspace/project) where offline runs will be sent",
)
@click.option(
"--offline-only",
"offline_only",
is_flag=True,
default=False,
help="synchronize only the offline runs inside '.neptune' directory",
)
def sync(
path: Path,
runs_names: List[str],
object_names: List[str],
project_name: Optional[str],
offline_only: Optional[bool],
):
"""Synchronizes objects with unsent data with the server.
Expand Down Expand Up @@ -153,6 +161,14 @@ def sync(
# Synchronize only the offline run with UUID offline/a1561719-b425-4000-a65a-b5efb044d6bb
# to project "workspace/project"
neptune sync --project workspace/project --object offline/a1561719-b425-4000-a65a-b5efb044d6bb
\b
# Synchronize only the offline runs
neptune sync --offline-only
\b
# Synchronize only the offline runs to project "workspace/project"
neptune sync --project workspace/project --offline-only
"""

sync_runner = SyncRunner(backend=HostedNeptuneBackend(Credentials.from_token()))
Expand All @@ -165,7 +181,15 @@ def sync(
object_names = set(object_names)
object_names.update(runs_names)

if object_names:
if offline_only:
if object_names:
raise click.BadParameter(
"--object and --offline-only are mutually exclusive"
)

sync_runner.sync_all_offline_containers(path, project_name)

elif object_names:
sync_runner.sync_selected_containers(path, project_name, object_names)
else:
sync_runner.sync_all_containers(path, project_name)
11 changes: 8 additions & 3 deletions neptune/new/sync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ def sync_offline_runs(
offline_runs_names = [get_qualified_name(exp) for exp in registered_runs]
self.sync_selected_registered_containers(base_path, offline_runs_names)

def sync_all_offline_containers(
self, base_path: Path, project_name: QualifiedName
) -> None:

offline_dirs = get_offline_dirs(base_path)
self.sync_offline_runs(base_path, project_name, offline_dirs)

def sync_selected_containers(
self,
base_path: Path,
Expand All @@ -246,6 +253,4 @@ def sync_selected_containers(

def sync_all_containers(self, base_path: Path, project_name: Optional[str]) -> None:
self.sync_all_registered_containers(base_path)

offline_dirs = get_offline_dirs(base_path)
self.sync_offline_runs(base_path, project_name, offline_dirs)
self.sync_all_offline_containers(base_path, project_name)

0 comments on commit 806d76d

Please sign in to comment.