Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__/
/.vscode/
.venv
schema.pyi
*.lock
3 changes: 3 additions & 0 deletions hatch.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[envs.default]
# this allows to e.g. `hatch run validate-registry` in the root directory
workspace.members = ["scripts"]
10 changes: 8 additions & 2 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Scripts

To hack on the scripts, `cd` to this directory, then
To hack on the scripts:

- Use `prek/pre-commit run -a jsonschema-gentypes` to generate types from schema initially
- Use `prek/pre-commit install` to so checks are automatically run on commit
- Use `prek/pre-commit install` so checks are automatically run on commit

To e.g. run registry validation locally, call `validate-registry`, e.g. like this:

```shell
env "GITHUB_TOKEN=$(gh auth token)" hatch run validate-registry
```
15 changes: 7 additions & 8 deletions scripts/src/ecosystem_scripts/validate_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def __post_init__(self) -> None:
async def validate_packages(self) -> tuple[Mapping[str, Sequence[Exception]], Sequence[ScverseEcosystemPackages]]:
"""Find all package `meta.yaml` files in the registry dir and yield package records."""

errors: dict[str, list[ValidationError | jsonschema.ValidationError]] = {}
errors: dict[str, list[ValidationError]] = {}
package_metadata: list[ScverseEcosystemPackages] = []

async with self.client:
Expand All @@ -374,19 +374,18 @@ async def validate_packages(self) -> tuple[Mapping[str, Sequence[Exception]], Se

return errors, package_metadata

async def check_package(
self, meta_file: Path
) -> tuple[str, ScverseEcosystemPackages, list[ValidationError | jsonschema.ValidationError]]:
async def check_package(self, meta_file: Path) -> tuple[str, ScverseEcosystemPackages, list[ValidationError]]:
pkg_id = meta_file.parent.name
with meta_file.open() as f:
tmp_meta = cast("ScverseEcosystemPackages", yaml.load(f, yaml.SafeLoader))

pkg_errors: list[ValidationError | jsonschema.ValidationError] = []
pkg_errors: list[ValidationError] = []
try:
jsonschema.validate(tmp_meta, self.schema)
except jsonschema.ValidationError as e:
log.error(f"{pkg_id}: Failed to validate meta.yaml: {e}")
pkg_errors.append(e)
msg = f"{pkg_id}: Failed to validate meta.yaml: {e}"
log.error(msg)
pkg_errors.append(ValidationError(msg))

# Check logo (if available) and make path relative to root of registry
if "logo" in tmp_meta:
Expand All @@ -408,7 +407,7 @@ async def check_package(

return pkg_id, tmp_meta, pkg_errors

def http_checks(self, pkg_id: str, tmp_meta: ScverseEcosystemPackages) -> Generator[Awaitable[Exception | None]]:
def http_checks(self, pkg_id: str, tmp_meta: ScverseEcosystemPackages) -> Generator[Awaitable[None]]:
# Check and register all links
yield self.check_home(tmp_meta["project_home"], pkg_id)
yield self.check_docs(tmp_meta["documentation_home"], pkg_id)
Expand Down
Loading
Loading