Skip to content

Commit

Permalink
chore: Update leap-catalog command in catalog-ci.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
andersy005 committed Apr 16, 2024
1 parent d163caa commit ea528f5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/catalog-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
- name: Validate Feedstocks and Generate Catalog
run: |
leap-catalog --help
leap-catalog validate --single https://github.com/leap-stc/proto_feedstock/blob/main/feedstock/catalog.yaml
leap-catalog generate --path https://github.com/leap-stc/data-management/staging/catalog/input.yaml --output catalog/
cat catalog/output/consolidated-web-catalog.json | jq
Expand Down
52 changes: 37 additions & 15 deletions leap_data_management_utils/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,19 @@ def collect_feedstocks(path: upath.UPath) -> list[upath.UPath]:
return feedstocks


def validate_feedstocks(*, feedstocks: list[upath.UPath]) -> list[Feedstock]:
def format_report(title: str, feedstocks: list[dict], include_traceback: bool = False) -> str:
report = f'{title} ({len(feedstocks)})\n'
if not feedstocks:
report += ' πŸš€ None found\n'
else:
for entry in feedstocks:
report += f" πŸ“‚ {entry['feedstock']}\n"
if include_traceback:
report += f" πŸ”Ž {entry['traceback']}\n"
return report
def format_report(title: str, feedstocks: list[dict], include_traceback: bool = False) -> str:
report = f'{title} ({len(feedstocks)})\n'
if not feedstocks:
report += ' πŸš€ None found\n'
else:
for entry in feedstocks:
report += f" πŸ“‚ {entry['feedstock']}\n"
if include_traceback:
report += f" πŸ”Ž {entry['traceback']}\n"
return report


def validate_feedstocks(*, feedstocks: list[upath.UPath]) -> list[Feedstock]:
errors = []
valid = []
catalog = []
Expand All @@ -137,8 +138,27 @@ def format_report(title: str, feedstocks: list[dict], include_traceback: bool =


def validate(args):
feedstocks = collect_feedstocks(args.path)
validate_feedstocks(feedstocks=feedstocks)
if args.single:
# If single file path is provided, validate just this one feedstock
try:
_ = Feedstock.from_yaml(convert_to_raw_github_url(args.single))
print(
format_report(
'βœ… Valid feedstock:', [{'feedstock': str(args.single), 'status': 'valid'}]
)
)
except Exception:
print(
format_report(
'❌ Invalid feedstock:',
[{'feedstock': str(args.single), 'traceback': traceback.format_exc()}],
include_traceback=True,
)
)
else:
# Default behavior, processing all feedstocks from directory
feedstocks = collect_feedstocks(args.path)
validate_feedstocks(feedstocks=feedstocks)


def generate(args):
Expand All @@ -157,8 +177,10 @@ def main():

# Subparser for the "validate" command
parser_validate = subparsers.add_parser('validate', help='Validate the feedstocks')
parser_validate.add_argument(
'--path', type=str, required=True, help='Path to the feedstocks input YAML file'
group = parser_validate.add_mutually_exclusive_group(required=True)
group.add_argument('--path', type=str, help='Path to the feedstocks input YAML file')
group.add_argument(
'--single', type=str, help='Path to a single feedstock YAML file to validate'
)
parser_validate.set_defaults(func=validate)

Expand Down

0 comments on commit ea528f5

Please sign in to comment.