Skip to content

Commit

Permalink
check_yaml: Use instructlab-schema package instead of git submodule
Browse files Browse the repository at this point in the history
Signed-off-by: BJ Hargrave <hargrave@us.ibm.com>
  • Loading branch information
bjhargrave committed Jun 7, 2024
1 parent 29b8ad2 commit 88a95e2
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 55 deletions.
1 change: 0 additions & 1 deletion .github/workflows/actionlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ jobs:
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
fetch-depth: 0
submodules: true

- name: "Download actionlint"
run: |
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
fetch-depth: 0
submodules: true
- name: "Check Markdown documents"
uses: DavidAnson/markdownlint-cli2-action@b4c9feab76d8025d1e83c653fa3990936df0e6c8 # v16.0.0
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/insight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ run-name: ${{ github.event.workflow_run.display_title || github.workflow }}
on:
workflow_run:
workflows:
- Lint
- "Lint compositional_skills and knowledge"
types:
- completed

Expand Down
23 changes: 17 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0

name: Lint
name: Lint compositional_skills and knowledge

on:
workflow_dispatch:
Expand Down Expand Up @@ -35,7 +35,7 @@ permissions:
contents: read

jobs:
lint:
yamllint:
runs-on: ubuntu-latest
steps:
- name: "Harden Runner"
Expand All @@ -47,7 +47,6 @@ jobs:
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
fetch-depth: 0
submodules: true

- name: "Setup Python"
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
Expand All @@ -69,22 +68,34 @@ jobs:
knowledge/**/*.yml
- name: "Check changed YAML file contents"
if: ${{ steps.changed-files.outputs.any_changed == 'true' }}
if: ${{ fromJSON(steps.changed-files.outputs.any_changed) }}
run: |
scripts/check-yaml.py ${{ steps.changed-files.outputs.all_changed_files }}
env:
SCHEMA_BASE: schema
YAMLLINT_CONFIG: "{extends: relaxed, rules: {line-length: {max: 120}}}"
TAXONOMY_FOLDERS: >-
compositional_skills
knowledge
- name: "Check all YAML file contents"
if: ${{ !fromJSON(steps.changed-files.outputs.any_changed) }}
run: |
read -ra folders <<< "${TAXONOMY_FOLDERS}"
# shellcheck disable=SC2046
scripts/check-yaml.py $(find "${folders[@]}" -name "qna.yaml")
env:
YAMLLINT_CONFIG: "{}" # No lint rules
SCHEMA_VERSION: 0 # use the schema version specified in the "version" key
TAXONOMY_FOLDERS: >-
compositional_skills
knowledge
- name: "Save Pull Request number"
if: ${{ (github.event_name == 'pull_request') && (github.repository == 'instructlab/taxonomy') }}
run: |
echo "${PULL_REQUEST_NUMBER}" > pull_request_number.txt
env:
PULL_REQUEST_NUMBER: ${{ steps.changed-files.outputs.any_changed == 'true' && github.event.number || '0' }}
PULL_REQUEST_NUMBER: ${{ fromJSON(steps.changed-files.outputs.any_changed) && github.event.number || '0' }}

- name: "Upload Pull Request number"
if: ${{ (github.event_name == 'pull_request') && (github.repository == 'instructlab/taxonomy') }}
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

9 changes: 0 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,6 @@ To contribute to this repo, you'll use the *Fork and Pull* model common in many
- For details on the local process, check out the [GitHub flow](https://docs.github.com/en/get-started/using-github/github-flow) documentation from GitHub and [The GitHub Workflow Guide](https://github.com/kubernetes/community/blob/master/contributors/guide/github-workflow.md) documentation from Kubernetes.
- For details on contributing using the GitHub webpage UI, see [Contributing using the GH UI](docs/contributing_via_GH_UI.md).

This repository uses [submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to incorporate the [taxonomy schema](https://github.com/instructlab/schema.git).
So, when using a local clone of this Git repository, be sure to use the [`--recurse-submodules`](https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---recurse-submodulesltpathspecgt) option on the `git clone` command and the `git pull` command when pulling updates from the remote repository.
For example:

```shell
git clone --recurse-submodules https://github.com/instructlab/taxonomy.git
git pull --recurse-submodules
```

> [!IMPORTANT]
> For all contributions to InstructLab 🐶, you want to become familiar with the workflow described in the [InstructLab 🐶 CLI
> `ilab`](https://github.com/instructlab/instructlab) documentation. It would be best to understand how to test
Expand Down
1 change: 0 additions & 1 deletion schema
Submodule schema deleted from cf56c4
41 changes: 8 additions & 33 deletions scripts/check-yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import subprocess
import sys
from functools import cache, partial
from importlib import resources
from importlib.resources.abc import Traversable
from pathlib import Path
from typing import List, Mapping, Optional, Union

# Third Party
import yaml
from instructlab.schema import schema_versions
from jsonschema.protocols import Validator
from jsonschema.validators import validator_for
from referencing import Registry, Resource
Expand All @@ -29,24 +31,19 @@ def __init__(
self,
*,
yaml_files: List[Path],
schema_base: Path,
taxonomy_folders: List[str],
yamllint_config: YamlLintConfig,
schema_version: Optional[int] = None,
message_format: Optional[str] = None,
) -> None:
self.yaml_files = yaml_files
self.schema_base = schema_base
self.taxonomy_folders = taxonomy_folders
self.yamllint_config = yamllint_config
self.schema_base = resources.files("instructlab.schema")
if schema_version is None:
schema_versions = sorted(
int(v.name[1:])
for v in self.schema_base.glob("v*")
if v.name[1:].isdigit()
)
if schema_versions:
schema_version = schema_versions[-1]
versions = schema_versions()
if versions:
schema_version = int(versions[-1].name[1:])
self.schema_version = schema_version
if message_format is None or message_format == "auto":
message_format = (
Expand All @@ -58,7 +55,7 @@ def __init__(
self.exit_code: int = 0

@cache
def _load_schema(self, path: Union[Path, Traversable]) -> Resource:
def _load_schema(self, path: Traversable) -> Resource:
try:
contents = json.loads(path.read_text(encoding="utf-8"))
resource = Resource.from_contents(
Expand All @@ -68,7 +65,7 @@ def _load_schema(self, path: Union[Path, Traversable]) -> Resource:
raise NoSuchResource(ref=str(path)) from e
return resource

def _retrieve(self, schemas_path: Union[Path, Traversable], uri: URI) -> Resource:
def _retrieve(self, schemas_path: Traversable, uri: URI) -> Resource:
path = schemas_path.joinpath(uri)
return self._load_schema(path)

Expand Down Expand Up @@ -279,17 +276,6 @@ def cli() -> int:
"TAXONOMY_FOLDERS", "compositional_skills knowledge"
).split(),
)
parser.add_argument(
"-s",
"--schema-base",
help="""
The base directory of the Taxonomy schema files.
Alternately, the SCHEMA_BASE environment variable can be used
to specify the base directory.
""",
default=os.environ.get("SCHEMA_BASE", _find_schema_base()),
type=Path,
)
parser.add_argument(
"-v",
"--schema-version",
Expand Down Expand Up @@ -337,23 +323,12 @@ def cli() -> int:
yaml_files=args.yaml_file,
taxonomy_folders=args.taxonomy_folders,
yamllint_config=args.yamllint_config,
schema_base=args.schema_base,
schema_version=args.schema_version,
message_format=args.message_format,
)
exit_code = check_yaml.check()
return exit_code


def _find_schema_base() -> Path:
for parent in Path(sys.argv[0]).parents:
candidate = parent.joinpath("schema")
if os.path.isdir(candidate):
return candidate
if os.path.exists(parent.joinpath(".git")):
break
return Path.cwd().joinpath("schema")


if __name__ == "__main__":
sys.exit(cli())
1 change: 1 addition & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: Apache-2.0

instructlab-schema @ git+https://github.com/bjhargrave/instructlab_schema@python-package
jsonschema>=4.21.1,<5.0.0
PyYAML>=6.0.1,<7.0.0
yamllint>=1.35.1,<2.0.0

0 comments on commit 88a95e2

Please sign in to comment.