-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(asset-cli): asset snapshot subcommand to capture manifests #369
feat(asset-cli): asset snapshot subcommand to capture manifests #369
Conversation
Signed-off-by: Tang <[email protected]>
Signed-off-by: Tang <[email protected]>
Signed-off-by: Tang <[email protected]>
Signed-off-by: Tang <[email protected]>
Signed-off-by: Tang <[email protected]>
Signed-off-by: Tang <[email protected]>
Signed-off-by: Tang <[email protected]>
eb1ad9a
to
3bf6fa6
Compare
Signed-off-by: Tang <[email protected]>
f299b41
to
e31c462
Compare
fbeb44e
to
5daab26
Compare
hash_callback_manager = _ProgressBarCallbackManager(length=100, label="Hashing Attachments") | ||
|
||
upload_group = asset_manager.prepare_paths_for_upload( | ||
input_paths=inputs, output_paths=[root_dir], referenced_paths=[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious - what is this referenced_paths
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some comments on this page: https://github.com/ddneilson/deadline-cloud-samples/blob/the_job_bundle/job_bundles/README.md
tldr: it's neither input nor output, but in case job references the name of the folder; in the case of snapshot + upload, the main goal is to upload files we care about, so I don't think referenced_paths are relevant here.
@@ -182,7 +179,7 @@ def upload_assets( | |||
|
|||
if manifest_write_dir: | |||
self._write_local_manifest( | |||
manifest_write_dir, manifest_name, full_manifest_key, manifest | |||
manifest_write_dir, manifest_name, full_manifest_key, manifest, None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding default to the function parameter rather than passing None
from the caller?
test/integ/cli/test_cli_asset.py
Outdated
with tempfile.TemporaryDirectory() as tmpdirname: | ||
yield tmpdirname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit - the naming is a bit confusing, I assume it's tmpdir rather than name?
test/integ/cli/test_cli_asset.py
Outdated
manifest_data = json.load(f) | ||
assert manifest_data["paths"][0]["path"] == "file.txt" | ||
assert ( | ||
manifest_data["paths"][0]["hash"] == "0741993e50c8bc250cefba3959c81eb8" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you get this hash, could it be a call with the input? i.e. we don't need to update the hash if there is any change to the input.
test/integ/cli/test_cli_asset.py
Outdated
manifest_data["paths"][0]["hash"] == "a5fc4a07191e2c90364319d2fd503cc1" | ||
) # hashed with xxh128 | ||
assert manifest_data["paths"][1]["path"] == posixpath.join( | ||
"subdir1", "subdir2", "subdir_file.txt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general for tests, the test input can be defined as a variable and pass to the call and assertion. Take a look at how it's done in other test cli implementation.
@@ -33,11 +42,61 @@ def cli_asset(): | |||
default=False, | |||
) | |||
@_handle_error | |||
def asset_snapshot(**args): | |||
def asset_snapshot(root_dir: str, manifest_out: str, recursive: bool, **args): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question for the type annotation: Is manifest_out
always a str
? Is it a different type when the user does not provide --manifest-out
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the click library doesn't allow users to specify optional in the function params, rather in the above @click.options, so I added a default=None for --manifest-out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so the typing should say it can either be None
or str
right?
This CLI implementation seems to capture the basic functionality. Were you able to call it and verify? If so, could you add to testing evidence? |
40716c2
to
eaebbe1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's still some comments I have on the tests that I think we should address, but we can do that in a future PR. Approved.
root_dir = str(tmp_path) | ||
|
||
temp_file = tmp_path / "temp_file.txt" | ||
temp_file.touch() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Ideally we shouldn't be creating files/dirs in our unit tests, but we can address this later.
def test_valid_manifest_out( | ||
self, tmp_path, mock_prepare_paths_for_upload, mock_hash_attachments, upload_group_mock | ||
): | ||
""" | ||
Tests if CLI snapshot command correctly calls with --manifest-out arguement | ||
""" | ||
root_dir = str(tmp_path) | ||
manifest_out_dir = tmp_path / "manifest_out" | ||
manifest_out_dir.mkdir() | ||
|
||
temp_file = tmp_path / "temp_file.txt" | ||
temp_file.touch() | ||
|
||
mock_prepare_paths_for_upload.return_value = upload_group_mock | ||
|
||
runner = CliRunner() | ||
result = runner.invoke( | ||
main, | ||
[ | ||
"asset", | ||
"snapshot", | ||
"--root-dir", | ||
root_dir, | ||
"--manifest-out", | ||
str(manifest_out_dir), | ||
], | ||
) | ||
|
||
assert result.exit_code == 0 | ||
mock_prepare_paths_for_upload.assert_called_once_with( | ||
input_paths=[str(temp_file)], output_paths=[root_dir], referenced_paths=[] | ||
) | ||
mock_hash_attachments.assert_called_once() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we're missing an assertion here to verify the command would have actually written the manifest file to manifest_out_dir
runner = CliRunner() | ||
result = runner.invoke(main, ["asset", "snapshot", "--root-dir", invalid_root_dir]) | ||
|
||
assert result.exit_code != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if we know what the expected exit code should be, we should assert equality on that expected value rather than checking for non-zero exit code.
Signed-off-by: Tang <[email protected]>
What was the problem/requirement? (What/Why)
Allow users to call CLI command to capture directories of assets into manifests.
What was the solution? (How)
Added deadline asset snapshot subcommand to allow capture of manifests. Includes:
What is the impact of this change?
Exposes functionality of creating manifests
How was this change tested?
test/unit/deadline_client/cli/test_cli_asset.py
, passing successfullytest/integ/cli/test_cli_asset.py
, passing successfullyWas this change documented?
N/A
Is this a breaking change?
N/A
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.