Skip to content

Commit

Permalink
Merge pull request #459 from JrGoodle/versions
Browse files Browse the repository at this point in the history
Update versions configuration for flat directory structure
  • Loading branch information
JrGoodle committed May 2, 2020
2 parents 9e1adce + 7922706 commit a590aaa
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 51 deletions.
14 changes: 6 additions & 8 deletions src/clowder/cli/save_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,17 @@ def _save(self) -> None:
:raise ClowderExit:
"""

if self.app.pargs.version.lower() == 'default':
print(fmt.save_default_error(self.app.pargs.version))
raise ClowderExit(1)

CLOWDER_REPO.print_status()
CLOWDER_CONTROLLER.validate_projects_exist()
validate_groups(CLOWDER_CONTROLLER.groups)

version_name = self.app.pargs.version.replace('/', '-') # Replace path separators with dashes
version_dir = os.path.join(ROOT_DIR, '.clowder', 'versions', version_name)
_make_dir(version_dir)
# Replace path separators with dashes to avoid creating directories
version_name = self.app.pargs.version.replace('/', '-')

versions_dir = os.path.join(ROOT_DIR, '.clowder', 'versions')
_make_dir(versions_dir)

yaml_file = os.path.join(version_dir, 'clowder.yaml')
yaml_file = os.path.join(versions_dir, f'{version_name}.yaml')
if os.path.exists(yaml_file):
print(fmt.save_version_exists_error(version_name, yaml_file) + '\n')
raise ClowderExit(1)
Expand Down
4 changes: 2 additions & 2 deletions src/clowder/util/clowder_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_saved_version_names() -> Optional[List[str]]:
versions_dir = os.path.join(os.getcwd(), '.clowder', 'versions')
if not os.path.exists(versions_dir):
return None
return [v for v in os.listdir(versions_dir) if not v.startswith('.') if v.lower() != 'default']
return [v[:-5] for v in os.listdir(versions_dir) if v.endswith('.yaml')]


def link_clowder_yaml(version: Optional[str] = None) -> None:
Expand All @@ -98,7 +98,7 @@ def link_clowder_yaml(version: Optional[str] = None) -> None:
yaml_file = os.path.join(ROOT_DIR, '.clowder', 'clowder.yaml')
path_output = fmt.get_path('.clowder/clowder.yaml')
else:
relative_path = os.path.join('.clowder', 'versions', version, 'clowder.yaml')
relative_path = os.path.join('.clowder', 'versions', f'{version}.yaml')
path_output = fmt.get_path(relative_path)
yaml_file = os.path.join(ROOT_DIR, relative_path)

Expand Down
2 changes: 2 additions & 0 deletions test/scripts/cats/link.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ test_no_versions() {
popd || exit 1
}
test_no_versions

# TODO: Add test where linking version succeeds and check symlink
6 changes: 3 additions & 3 deletions test/scripts/cats/save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ test_save() {
$COMMAND link -v v100 && exit 1
echo "TEST: Fail saving a previously saved version"
$COMMAND save v0.1 && exit 1
echo "TEST: Fail saving a saved version named 'default'"
$COMMAND save default && exit 1
$COMMAND save DEFAULT && exit 1
echo "TEST: Successfully save a new version"
$COMMAND save v0.11 || exit 1
$COMMAND link -v v0.11 || exit 1
# TODO: Check whether symlink is correct
echo "TEST: Successfully save version with path separator in input name"
$COMMAND save path/separator || exit 1
$COMMAND link -v path-separator || exit 1
# TODO: Check whether symlink is correct
$COMMAND herd $PARALLEL || exit 1
$COMMAND status || exit 1
}
Expand Down
10 changes: 0 additions & 10 deletions test/scripts/cats/write_herd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ if [ "$ACCESS_LEVEL" == "write" ]; then
./clean.sh
./init.sh || exit 1

$COMMAND repo checkout repo-test || exit 1
pushd .clowder || exit 1
test_branch repo-test
popd || exit 1
clowder link -v ssh || exit 1

$COMMAND herd $PARALLEL || exit 1
Expand Down Expand Up @@ -53,10 +49,4 @@ if [ "$ACCESS_LEVEL" == "write" ]; then
popd || exit 1
}
test_herd_rebase_conflict

$COMMAND repo checkout master || exit 1
pushd .clowder || exit 1
test_branch master
popd || exit 1
clowder link || exit 1
fi
10 changes: 0 additions & 10 deletions test/scripts/cats/write_prune.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ if [ "$ACCESS_LEVEL" == "write" ]; then
./clean.sh
./init.sh || exit 1

$COMMAND repo checkout repo-test || exit 1
pushd .clowder || exit 1
test_branch repo-test
popd || exit 1
clowder link -v ssh || exit 1

$COMMAND herd $PARALLEL || exit 1
Expand Down Expand Up @@ -74,10 +70,4 @@ if [ "$ACCESS_LEVEL" == "write" ]; then
done
}
test_prune_all

$COMMAND repo checkout master || exit 1
pushd .clowder || exit 1
test_branch master
popd || exit 1
clowder link || exit 1
fi
6 changes: 0 additions & 6 deletions test/scripts/cats/write_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,4 @@ if [ "$ACCESS_LEVEL" == "write" ]; then
popd || exit 1
}
test_clowder_repo_commit_pull_push

$COMMAND repo checkout master || exit 1
pushd .clowder || exit 1
test_branch master
popd || exit 1
clowder link || exit 1
fi
10 changes: 0 additions & 10 deletions test/scripts/cats/write_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ if [ "$ACCESS_LEVEL" == "write" ]; then
./clean.sh
./init.sh || exit 1

$COMMAND repo checkout repo-test || exit 1
pushd .clowder || exit 1
test_branch repo-test
popd || exit 1
clowder link -v ssh || exit 1

$COMMAND herd $PARALLEL || exit 1
Expand Down Expand Up @@ -230,10 +226,4 @@ if [ "$ACCESS_LEVEL" == "write" ]; then
done
}
test_start_tracking

$COMMAND repo checkout master || exit 1
pushd .clowder || exit 1
test_branch master
popd || exit 1
clowder link || exit 1
fi
3 changes: 2 additions & 1 deletion test/scripts/cats/yaml_validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ _test_invalid_yaml() {

for test in "${test_cases[@]}"
do
$COMMAND link -v $test || exit 1
version=${test%.yaml}
$COMMAND link -v $version || exit 1
print_single_separator
$COMMAND herd
exit_code=$?
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/test_clowder_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_link_version(self):
"""Test link() method"""

self.clowder_repo.link('v0.1')
version_path = os.path.join('.clowder', 'versions', 'v0.1', 'clowder.yaml')
version_path = os.path.join('.clowder', 'versions', 'v0.1.yaml')
self.assertEqual(os.readlink(self.clowder_yaml_path), os.path.join(self.cats_example_path, version_path))


Expand Down

0 comments on commit a590aaa

Please sign in to comment.