Skip to content

Pre commit additions - #5

Open
iwanicki92 wants to merge 8 commits into
Dasharo:mainfrom
iwanicki92:pre-commit-additions
Open

Pre commit additions#5
iwanicki92 wants to merge 8 commits into
Dasharo:mainfrom
iwanicki92:pre-commit-additions

Conversation

@iwanicki92

@iwanicki92 iwanicki92 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Most of changes are in .lock files (uv/poetry), around 2.2k

Some changes

  • Bump minimum poetry version to 2.0.0 and migrate pyproject.toml config.
  • Replace blake/isort with ruff. It combines those 2 tools and extends them with other checks
  • add ty type checker hook
  • Some small fixes, refactoring, missing documentation in README about model YAML fields

And probably biggest changes:

  • add YAML model schema with pre-commit validation - create YAML schema, based of Python schema that was already defined. Add # $schema: ./schema/model_schema.yml to every model, thanks to that your IDE of choice should hint you about possible fields and their values and also immediately show you if you made an mistake.
    While this schema is way more complicated than the minimalistic voluptuous it offers much more in other ways. The same commit added pre-commit which validates models on each change and also validates every model in case schema changes. This is also expanded in next commit

  • Generate Python pydantic model from the YAML schema. Use datamodel-code-generator for the conversion and wire it up into pre-commit, so it never is out of sync with schema. This is autogenerated Python file and shouldn't be modified manually.

  • Migrate current voluptuous config, which loads data into untyped dict to newly generated Python model. This allows much easier reasoning about what each value in the model is or can be and also increases ty pre-commit usability with better type hint coverage (which previously was I think dict[Any, Any] for model data). Also much better hinting in your IDE of choice:

    image

What's left:

  • PR is more or less ready for review, only a little more testing remains to make sure there are no regressions

What's next:

  • Maybe doc or at least README section generated from YAML schema as it keeps getting out of sync.
  • Schema/model for SnipeIT or RTE API JSON responses since currently it's really not obvious what might be returned. It would also allow for validating the responses before using any data.

Signed-off-by: iwanicki92 <iwanicki92@gmail.com>
- Ruff combines and extends capabilities of both of those tools,
- add `ty` type checker hook - would likely work even better if the
  type hinting improved in the codebase, currently there are too many
  Any/Unknowns detected. Maybe consider using MonkeyType to generate
  stub files from types detected at runtime.

Signed-off-by: iwanicki92 <iwanicki92@gmail.com>
@iwanicki92
iwanicki92 force-pushed the pre-commit-additions branch from 6fc657f to b57d963 Compare July 31, 2026 17:51
Signed-off-by: iwanicki92 <iwanicki92@gmail.com>
Signed-off-by: iwanicki92 <iwanicki92@gmail.com>
Signed-off-by: iwanicki92 <iwanicki92@gmail.com>
Pre-commit validates every changed model using new YAML schema.
In case schema itself changes, additional pre-commit validates all
models to make sure they still conform to the schema.

Add `# $schema: ./schema/model_schema.yml` to every model. It is used
by various IDE to give you hints or show errors if YAML doesn't conform
to the schema.

Signed-off-by: iwanicki92 <iwanicki92@gmail.com>
Add pre-commit that keeps Python model in sync with schema changes

Signed-off-by: iwanicki92 <iwanicki92@gmail.com>
Signed-off-by: iwanicki92 <iwanicki92@gmail.com>
@iwanicki92
iwanicki92 force-pushed the pre-commit-additions branch from b5e55ab to 4f92bda Compare August 1, 2026 22:17
@iwanicki92
iwanicki92 marked this pull request as ready for review August 11, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant