Skip to content

Commit

Permalink
Merge pull request #567 from JrGoodle/single-source-default
Browse files Browse the repository at this point in the history
Infer default source when only one present
  • Loading branch information
JrGoodle committed Jun 5, 2020
2 parents 9af563b + 7b715d8 commit 18dba9a
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/issue_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

- `clowder` version: `4.0b2`
- OS: macOS
- Python version: 3.6
- Python version: 3.7
6 changes: 2 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ script/test
Run test scripts

```bash
clowder-test swift all
clowder-test cats herd
clowder-test unittests
clowder-test cats <option>
```

## Pull requests

Any new functionality or bug fixes must have associated tests, in order to prevent future regressions. There are a few Python unit tests, but the majority of the tests are located in bash scripts in [test/scripts](test/scripts)
Any new functionality or bug fixes must have associated tests, in order to prevent future regressions. As of now, the tests are all functional tests located in bash scripts in [test/scripts](test/scripts)
5 changes: 5 additions & 0 deletions src/clowder/clowder_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ def _load_clowder_yaml(self, yaml: dict) -> None:
self.sources = tuple(sorted([Source(s, self.defaults) for s in yaml['sources']],
key=lambda source: source.name))

if len(self.sources) == 1 and self.defaults.source is None:
self.defaults.source = self.sources[0].name
elif len(self.sources) > 1 and self.defaults.source is None:
raise ClowderError(ClowderErrorType.MISSING_DEFAULT_SOURCE, fmt.error_missing_default_source())

if not any([s.name == self.defaults.source for s in self.sources]):
message = fmt.error_source_default_not_found(self.defaults.source, ENVIRONMENT.clowder_yaml)
raise ClowderError(ClowderErrorType.CLOWDER_YAML_SOURCE_NOT_FOUND, message)
Expand Down
1 change: 1 addition & 0 deletions src/clowder/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ClowderErrorType(IntEnum):
SYMLINK_SOURCE_NOT_FOUND = 39
CLOWDER_REPO_EXISTING_FILE = 70
PARSER_CREATION_FAILED = 71
MISSING_DEFAULT_SOURCE = 72

OPEN_FILE = 45

Expand Down
8 changes: 5 additions & 3 deletions src/clowder/model/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, defaults: dict):
"""

self.protocol = GitProtocol(defaults["protocol"])
self.source: str = defaults["source"]
self._source: str = defaults.get("source", None)

self._remote: Optional[str] = defaults.get("remote", None)
self._branch: Optional[str] = defaults.get("branch", None)
Expand All @@ -53,9 +53,10 @@ def get_yaml(self) -> dict:
:rtype: dict
"""

defaults = {'source': self.source,
'protocol': self.protocol.value}
defaults = {'protocol': self.protocol.value}

if self._source is not None:
defaults['source'] = self._source
if self._remote is not None:
defaults['remote'] = self._remote
if self._git_settings is not None:
Expand Down Expand Up @@ -92,6 +93,7 @@ def __init__(self, defaults: dict):

super().__init__(defaults)

self.source: str = defaults.get("source", None)
self.remote: str = defaults.get("remote", "origin")
self.git_settings = GitSettings(git_settings=defaults.get("git", None))

Expand Down
3 changes: 0 additions & 3 deletions src/clowder/util/clowder.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@
"anyOf": [
{
"required": [
"source",
"protocol"
],
"additionalProperties": false,
Expand All @@ -433,7 +432,6 @@
},
{
"required": [
"source",
"protocol"
],
"additionalProperties": false,
Expand All @@ -457,7 +455,6 @@
},
{
"required": [
"source",
"protocol"
],
"additionalProperties": false,
Expand Down
10 changes: 10 additions & 0 deletions src/clowder/util/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,16 @@ def error_missing_clowder_yaml() -> str:
return error_missing_file(clowder_file)


def error_missing_default_source() -> str:
"""Format error message for missing default source
:return: Formatted error message for missing default source
:rtype: str
"""

return f"{ERROR} Default 'source' is required when multiple sources are specified"


def error_missing_file(yaml_file: str) -> str:
"""Format error message for missing linked clowder yaml file
Expand Down
18 changes: 17 additions & 1 deletion test/scripts/cats/herd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ test_herd_sha() {
popd || exit 1
pushd black-cats/june || exit 1
test_head_detached
test_commit '7b725e4953281347594585b8d1d02a3561201f72'
test_commit 'b6e1316cc62cb2ba18fa982fc3d67ef4408c8bfd'
popd || exit 1
pushd black-cats/sasha || exit 1
test_head_detached
Expand Down Expand Up @@ -616,6 +616,22 @@ test_herd_rebase() {
}
test_herd_rebase

test_herd_infer_default_source() {
print_single_separator
echo "TEST: clowder herd infer default source"
./clean.sh
./init.sh || exit 1
begin_command
$COMMAND link infer-default-source || exit 1
end_command
test_symlink_path 'clowder.yaml' "$(pwd)/.clowder/versions/infer-default-source.clowder.yaml"
begin_command
$COMMAND herd $PARALLEL || exit 1
end_command
test_cats_default_herd_branches
}
test_herd_infer_default_source

if [ "$ACCESS_LEVEL" == "write" ]; then
"$TEST_SCRIPT_DIR/cats/write_herd.sh" $1
fi
1 change: 1 addition & 0 deletions test/scripts/cats/yaml_validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ test_invalid_yaml() {
_test_invalid_yaml 'ls -d test-duplicate-fork-project-remote*' '47'
_test_invalid_yaml 'ls -d test-source-not-found*' '48'
_test_invalid_yaml 'ls -d test-duplicate-project-directories*' '49'
_test_invalid_yaml 'ls -d test-multiple-sources-missing-default' '72'

begin_command
$COMMAND repo checkout master || exit 1
Expand Down

0 comments on commit 18dba9a

Please sign in to comment.