diff --git a/outpostcli/constants.py b/outpostcli/constants.py index 3cfb50e..bcbe7e6 100644 --- a/outpostcli/constants.py +++ b/outpostcli/constants.py @@ -1,2 +1,2 @@ -cli_version = "0.0.24" +cli_version = "0.0.25" CLI_BINARY_NAME = "outpostcli" diff --git a/outpostcli/lfs/commands.py b/outpostcli/lfs/commands.py index da27887..1bf095a 100644 --- a/outpostcli/lfs/commands.py +++ b/outpostcli/lfs/commands.py @@ -1,4 +1,5 @@ # ref: https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/commands/lfs.py +from functools import partial import json import logging import os @@ -73,12 +74,11 @@ def write_msg(msg: Dict): def read_msg() -> Optional[Dict]: """Read Line delimited JSON from stdin.""" msg = json.loads(sys.stdin.readline().strip()) - + _log.info(msg) if "terminate" in (msg.get("type"), msg.get("event")): # terminate message received return None - if msg.get("event") not in ("download", "upload"): # logger.critical("Received unexpected message") sys.exit(1) @@ -91,6 +91,7 @@ def multipart_upload(): """Command called by git lfs directly and is not meant to be called by the user""" # ... (rest of the existing code) init_msg = json.loads(sys.stdin.readline().strip()) + if not (init_msg.get("event") == "init" and init_msg.get("operation") == "upload"): write_msg({"error": {"code": 32, "message": "Wrong lfs init operation"}}) sys.exit(1) @@ -101,14 +102,14 @@ def multipart_upload(): # needs to do. It should then respond on stdout with a simple empty # confirmation structure, as follows: write_msg({}) - _bytes_so_far = 0 + bytes_so_far = 0 - def on_progress(uploaded_bytes: int): + def on_progress(oid: str, uploaded_bytes: int): write_msg( { "event": "progress", "oid": oid, - "bytesSoFar": _bytes_so_far + uploaded_bytes, + "bytesSoFar": bytes_so_far + uploaded_bytes, "bytesSinceLast": uploaded_bytes, } ) @@ -116,7 +117,9 @@ def on_progress(uploaded_bytes: int): # After the initiation exchange, git-lfs will send any number of # transfer requests to the stdin of the transfer process, in a serial sequence. while True: + _log.info("h") msg = read_msg() + _log.info("new message: ", msg) if msg is None: # When all transfers have been processed, git-lfs will send # a terminate event to the stdin of the transfer process. @@ -126,18 +129,11 @@ def on_progress(uploaded_bytes: int): oid = msg["oid"] filepath = msg["path"] - write_msg( - { - "event": "progress", - "oid": oid, - "bytesSoFar": 1, - "bytesSinceLast": 0, - } - ) - _log.info(msg) with open(filepath, "rb") as file_obj: - MultipartTransferAdapter().upload(file_obj, msg["action"], on_progress) + MultipartTransferAdapter().upload( + file_obj, msg["action"], partial(on_progress, oid) + ) write_msg({"event": "complete", "oid": oid}) except HTTPException as e: _log.error(e, exc_info=True) diff --git a/pyproject.toml b/pyproject.toml index 9c57d77..10fa2b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "outpostcli" -version = "0.0.24" +version = "0.0.25" description = "CLI for Outpost" readme = "README.md" license = { file = "LICENSE" } diff --git a/setup.py b/setup.py index 759a445..8c46760 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="outpostcli", - version="0.0.24", + version="0.0.25", py_modules=["outpostcli"], install_requires=["Click", "outpostkit"], entry_points={