Skip to content
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

Support local rel path as deployment pull path #662

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/ramble/ramble/cmd/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import ramble.pipeline
import ramble.filters
from ramble.main import RambleCommand
import ramble.util.path


description = "(experimental) manage workspace deployments"
Expand Down Expand Up @@ -118,8 +119,11 @@ def pull_file(src, dest):
# Fetch deployment index first:
push_cls = ramble.pipeline.PushDeploymentPipeline

# Handle local relative path
deployment_path = ramble.util.path.get_maybe_local_path(args.deployment_path)

remote_index_path = surl.join(
args.deployment_path, ramble.pipeline.PushDeploymentPipeline.index_filename
deployment_path, ramble.pipeline.PushDeploymentPipeline.index_filename
)
local_index_path = os.path.join(ws.root, push_cls.index_filename)

Expand All @@ -129,7 +133,7 @@ def pull_file(src, dest):
index_data = sjson.load(f)

for file in index_data[push_cls.index_namespace]:
src = surl.join(args.deployment_path, file)
src = surl.join(deployment_path, file)
dest = os.path.join(ws.root, file)
if os.path.exists(dest):
fs.force_remove(dest)
Expand Down
27 changes: 27 additions & 0 deletions lib/ramble/ramble/test/util/path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2022-2024 The Ramble Authors
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
"""Perform tests of the util/path functions"""

import os

import ramble.util.path

import pytest


@pytest.mark.parametrize(
"path,expect",
[
("rel/path", os.path.abspath("rel/path")),
("/abs/path", "/abs/path"),
("file:/abs/path", "file:/abs/path"),
("gs://my-bucket", "gs://my-bucket"),
],
)
def test_get_maybe_local_path(path, expect):
assert ramble.util.path.get_maybe_local_path(path) == expect
9 changes: 9 additions & 0 deletions lib/ramble/ramble/util/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import getpass
import subprocess
import tempfile
import urllib.parse

from llnl.util.lang import memoized

Expand Down Expand Up @@ -99,3 +100,11 @@ def canonicalize_path(path):
path = os.path.abspath(path)

return path


def get_maybe_local_path(path):
"""Convert a scheme-less path to absolute local path"""
parsed = urllib.parse.urlparse(path)
if not parsed.scheme:
return os.path.abspath(path)
return path