Skip to content
Open
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
2 changes: 1 addition & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[codespell]
exclude-file = .codespellx
ignore-words-list = "FPT,FTP,fpt,ftp,checkin"
ignore-words-list = FPT,FTP,fpt,ftp,checkin
66 changes: 56 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,12 @@ repos:
- id: shellcheck
args: ["--severity=warning"]

- repo: https://github.com/pycqa/isort
rev: 9.0.0b1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.16.0
hooks:
- id: isort
name: isort (python)

- repo: https://github.com/psf/black
rev: 26.5.1
hooks:
- id: black
args: ["--line-length", "79"]
- id: ruff-check
args: [--fix]
- id: ruff-format

- repo: https://github.com/MarketSquare/robotframework-robocop
rev: v8.4.1
Expand All @@ -70,3 +65,54 @@ repos:
- id: robocop-format
additional_dependencies:
- typing_extensions

- repo: https://github.com/astral-sh/ty-pre-commit
rev: v0.0.65
hooks:
- id: ty
args: [--isolated, --group, test, --project, osfv_cli]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.37.4
hooks:
- id: check-jsonschema
args: [
"--verbose",
"--schemafile",
"osfv_cli/src/osfv/models/schema/model_schema.yml",
]
files: ^osfv_cli/src/osfv/models/.*\.yml$
# Validate models not the schema itself.
exclude: ^osfv_cli/src/osfv/models/schema/.*$

- repo: local
hooks:
- id: check-osfv-models
name: Validate all OSFV YAML models
# Use bash to expand glob
entry: bash -c 'check-jsonschema osfv_cli/src/osfv/models/*yml "$@"'
args: [
"--verbose",
"--schemafile",
"osfv_cli/src/osfv/models/schema/model_schema.yml"
]
language: python
additional_dependencies:
- check-jsonschema
# Run only if schema changed. 'check-jsonschema' verifies singular
# model changes.
files: ^osfv_cli/src/osfv/models/schema/.*\.yml$
pass_filenames: false

- repo: https://github.com/koxudaxi/datamodel-code-generator
# Keep in sync with pyproject.toml otherwise manually generated model might
# differ
rev: 0.71.0
hooks:
- id: datamodel-code-generator
entry: "bash -c 'cd osfv_cli && datamodel-codegen'"
files: |
(?x)^(
osfv_cli/src/osfv/models/schema/.*\.yaml|
osfv_cli/src/osfv/libs/models_gen.py
)$
8 changes: 8 additions & 0 deletions osfv_cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ clean:

all: build install

generate-schema:
poetry run datamodel-codegen

validate-schema:
poetry run check-jsonschema \
--schemafile "$(REPO_ROOT)/src/osfv/models/schema/model_schema.yml" \
"$(REPO_ROOT)"/src/osfv/models/*.yml

.PHONY: install uninstall build clean
64 changes: 55 additions & 9 deletions osfv_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,14 @@ follows:
flashrom.
+ `voltage` - required; chip supply voltage - most often "3.3V" or "1.8V";
should be discovered in appropriate datasheet.
+ `layout` - optional. Layout entries
- `name` - required, name of the layout entry
- `range` - required, range of this entry

- `programmer`:

+ `name`- required; name of the programmer connected to the platform; supported
values: `rte_1_0`, `rte_1_1`, `ch341a`
values: `rte_1_0`, `rte_1_1`, `ch341a`, `dediprog`

- `pwr_ctrl`:

Expand All @@ -245,6 +248,12 @@ follows:
power control.
+ `flashing_power_state` - required; defines a power state the platform
needs to be in for SPI flashing; supported values: `"S5"`, `"G3"`
+ `discharge_psu` - optional; true or false (true by default), whether to
discharge PSU after powering it off.

- `pwr_led`, optional:

+ `polarity` - required, power LED GPIO polarity, default: active high.

- `reset_cmos`: - optional; true or false (false by default), whether CMOS reset
is required after flashing.
Expand Down Expand Up @@ -273,23 +282,60 @@ unset SSH_AUTH_SOCK

## Development

You can test local changes by running `poetry shell` first. Then, all
`osfv_cli` calls will use the local files in repository, not installed package.
Make sure to install `pre-commit` before committing any changes

```sh
pre-commit install
```

### Dependencies

All commands except `pre-commit` should be run in activated virtual environment
created in [Installation](#installation) step.

Before starting development make sure to install `dev` and `test` dependencies

```shell
poetry install --all-groups
```

## Tests
### Tests

OSFV CLI tests can be found in the `test` directory.
The tests are written in [Robot Framework](https://robotframework.org/),

### Dependencies
### Model schema

Enter development shell with test dependencies:
We are using
[model_schema.yml](./src/osfv/models/schema/model_schema.yml) as our
main YAML schema for flashing configuration. From this schema
a [Python datamodel](./src/osfv/libs/models_gen.py) is generated and used
in Python code and by type checker.

```shell
poetry install --with test
poetry shell
After modifying the schema, regenerate the Python one via:

```sh
make generate-schema
```

and make sure all checks still pass after schema change:

- Validate models with new schema

```sh
make validate-schema
```

- Python linters and type checkers

```sh
poetry ruff check
poetry ruff format
poetry ty
```

You can also run `pre-commit run -a` to run all checks (and more) automatically.

### Required configs

To test some functionalities related to SnipeIT, it is required to
Expand Down
Loading