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

[nrfconnect] Fix for jsonschema documentation and factory data script #23966

Merged
merged 2 commits into from
Dec 8, 2022
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
24 changes: 21 additions & 3 deletions docs/guides/nrfconnect_factory_data_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,27 @@ window indicates the validation status.
#### Option 3: Using the nRF Connect Python script

You can have the JSON file checked automatically by the Python script during the
file generation. For this to happen, provide the path to the JSON schema file as
an additional argument, which should replace the _<path_to_schema>_ variable in
the following command:
file generation. For this to happen, you must install the `jsonschema` Python
module in your Python environment and provide the path to the JSON schema file
as an additional argument. To do this, complete the following steps:

1. Install the `jsonschema` Python module by invoking one of the following
commands from the Matter root directory:

- Install only the `jsonschema` module:

```
$ python -m pip install jsonschema
```

- Install the `jsonschema` module together with all dependencies for Matter:

```
$ python -m pip install -r ./scripts/requirements.nrfconnect.txt
```

2. Run the following command (remember to replace the _<path_to_schema>_
variable):

```
$ python generate_nrfconnect_chip_factory_data.py --schema <path_to_schema>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import os
import sys
import json
import jsonschema
import secrets
import argparse
import subprocess
Expand All @@ -29,6 +28,13 @@
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.serialization import load_der_private_key

try:
import jsonschema
except ImportError:
no_jsonschema_module = True
else:
no_jsonschema_module = False

# A user can not change the factory data version and must be coherent with
# the factory data version set in the nRF Connect platform Kconfig file (CHIP_FACTORY_DATA_VERSION).
FACTORY_DATA_VERSION = 1
Expand Down Expand Up @@ -485,6 +491,12 @@ def base64_str(s): return base64.b64decode(s)
log.error("Output file: {} already exist, to create a new one add argument '--overwrite'. By default overwriting is disabled".format(args.output))
return

if args.schema and no_jsonschema_module:
log.error("Requested verification of the JSON file using jsonschema, but the module is not installed. \n \
Install only the module by invoking: pip3 install jsonschema \n \
Alternatively, install it with all dependencies for Matter by invoking: pip3 install -r ./scripts/requirements.nrfconnect.txt from the Matter root directory.")
return

generator = FactoryDataGenerator(args)
generator.generate_json()

Expand Down