Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taxonomy reading API #33

Merged
merged 3 commits into from
Jul 30, 2024
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
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ updates:
directory: "/.github/workflows"
schedule:
interval: "daily"

# Maintain dependencies for Python code
- package-ecosystem: "pip"
directory: "/"
versioning-strategy: "increase-if-necessary"
schedule:
interval: "daily"
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
tox -e jsonschema
- name: "ruff"
commands: |
tox -e ruff -- check
tox -e ruffcheck
- name: "pylint"
commands: |
echo "::add-matcher::.github/workflows/matchers/pylint.json"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ jobs:
strategy:
matrix:
python:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Taxonomy Schema

This Python package defines the JSON schema for the InstructLab [Taxonomy](https://github.com/instructlab/taxonomy) YAML.
This Python package defines the JSON schema and a parser for the InstructLab [Taxonomy](https://github.com/instructlab/taxonomy) YAML.

Consumers of this schema can `pip install instructlab-schema`, and access the schema files using `importlib.resources` on the `instructlab.schema` package.
Consumers of this schema can `pip install instructlab-schema`, and use the `instructlab.schema.taxonomy.TaxonomyParser` class to parse and validate `qna.yaml` taxonomy files.
Schema files can be directly accessed using the `instructlab.schema.schema_base()` method to get access the base of the schema resources.
34 changes: 27 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0

[build-system]
requires = ["setuptools>=64", "setuptools_scm>=8"]
requires = ["setuptools>=70.1.0", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[project]
Expand All @@ -10,19 +10,26 @@ authors = [{ name = "InstructLab", email = "[email protected]" }]
description = "InstructLab Taxonomy Schema"
readme = "README.md"
license = { text = "Apache-2.0" }
requires-python = ">=3.9"
requires-python = ">=3.10"
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dynamic = ["dependencies", "optional-dependencies", "version"]
dependencies = [
"typing_extensions",
"jsonschema>=4.22.0",
"PyYAML>=6.0.0",
# The below library should NOT be imported into any python files
# We only use the command via subprocess
"yamllint>=1.35.1",
]
dynamic = ["version"]

[project.urls]
homepage = "https://instructlab.ai"
Expand All @@ -34,13 +41,14 @@ version_file = "src/instructlab/schema/_version.py"
local_scheme = "no-local-version" # do not include +gREV local version, required for Test PyPI upload

[tool.mypy]
python_version = "3.9"
python_version = "3.10"
exclude = ["^src/instructlab/schema/_version\\.py$"]

[tool.ruff]
target-version = "py39"
target-version = "py310"
src = ["src", "tests"]
extend-exclude = ["src/instructlab/schema/_version.py"]
line-length = 180

[tool.ruff.lint]
select = [
Expand All @@ -54,11 +62,23 @@ select = [
"TID", # flake8-tidy-imports
]

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"yamllint".msg = "yamllint is for use as a command via subprocess."

[tool.pylint.main]
py-version = "3.9"
py-version = "3.10"
source-roots = ["src", "tests"]
ignore = ["_version.py"]

[tool.pylint.design]
max-branches = 20
max-line-length = 180
max-locals = 20
min-public-methods = 1

[tool.pylint.format]
max-args = 8

[tool.pylint."messages control"]
disable = [
"missing-class-docstring",
Expand Down
50 changes: 0 additions & 50 deletions scripts/ruff.sh

This file was deleted.

23 changes: 15 additions & 8 deletions src/instructlab/schema/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# SPDX-License-Identifier: Apache-2.0

"""InstructLab Taxonomy Schema"""

# Standard
from importlib import resources
import importlib.resources
from importlib.abc import Traversable

__all__ = ["schema_base", "schema_versions"]


try:
from importlib.resources.abc import Traversable # type: ignore[import-not-found]
except ImportError: # python>=3.9,<3.11
from importlib.abc import Traversable
def schema_base() -> Traversable:
"""Return the schema base.

__all__ = ["schema_versions"]
Returns:
Traversable: The base for the schema versions.
"""
base = importlib.resources.files(__name__)
return base


def schema_versions() -> list[Traversable]:
Expand All @@ -17,9 +25,8 @@ def schema_versions() -> list[Traversable]:
Returns:
list[Traversable]: A sorted list of schema versions.
"""
schema_base = resources.files(__package__)
versions = sorted(
(v for v in schema_base.iterdir() if v.name[0] == "v" and v.name[1:].isdigit()),
(v for v in schema_base().iterdir() if v.name[0] == "v" and v.name[1:].isdigit()),
key=lambda k: int(k.name[1:]),
)
return versions
Loading