Skip to main content

Validate and create MicroPython package JSON file

Project description

MicroPython Package Validation

Downloads Release Python License: MIT codecov CI

Validate and create MicroPython package JSON file


General

MicroPython Package Validation for mip package.json files

📚 The latest documentation is available at MicroPython Package Validation ReadTheDocs 📚

Installation

Install required tools

Python3 must be installed on your system. Check the current Python version with the following command

python --version
python3 --version

Depending on which command Python 3.x.y (with x.y as some numbers) is returned, use that command to proceed.

python3 -m venv .venv
source .venv/bin/activate

pip install -r requirements.txt

Installation

pip install setup2upypackage

Usage

Validate

The optional arg --pretty can be used to output human readable content instead of JSON data in case of a failure.

The machine readable JSON output might look like and can directly be processed with e.g. jq using upy-package ... --validate 2> >(jq -r '.'):

{
    "values_changed":
    {
        "root['urls'][1][0]":
        {
            "new_value": "be_upy_blink/blink2.py",
            "old_value": "be_upy_blink/blink.py"
        }
    }
}

The human readable output using --pretty might look like:

Mismatch between "setup.py" and "package.json"
Diff: Value of root['urls'][1][0] changed from "be_upy_blink/blink.py" to "be_upy_blink/blink2.py".

Validate package JSON file

The following command will exit with a non-zero code in case of a difference between the generated (based on setup.py) and existing package (package.json) content.

upy-package \
    --setup_file tests/data/setup.py \
    --package_changelog_file tests/data/sample_changelog.md \
    --package_file tests/data/package.json \
    --validate

Validate package JSON file from changelog

In case the package version is defined by a changelog and the version entry of the setup.py file is filled on demand by e.g. changelog2version, the semantic version changelog can be specified explicitly to use its latest entry for the version value.

upy-package \
    --setup_file tests/data/setup.py \
    --package_changelog_file tests/data/sample_changelog.md \
    --package_file tests/data/package.json \
    --validate

Options

To not take the version or the dependencies specified in the package.json file during a validation run, use the --ignore-version or --ignore-deps argument. Additionally added boot.py and main.py files in package.json can be ignored using --ignore-boot-main during a validation run.

Create

Using the optional --pretty argument will pretty format all JSON output in the generated output file and on the optional console output.

Create package JSON file

The following command creates a package.json file in the same directory as the specified setup.py file. The content of the package.json file is additionally printed to stdout (--print) with an indentation of 4 (due to the --pretty option)

upy-package \
    --setup_file tests/data/setup.py \
    --create \
    --print \
    --pretty
Create specific package JSON file

A specific package JSON file can be specified with the --package_file parameter. The file has to exist before running the command.

upy-package \
    --setup_file tests/data/setup.py \
    --package_file tests/data/custom-package.json \
    --create \
    --print \
    --pretty

Create package JSON file from changelog

In case the package version is defined by a changelog and the version entry of the setup.py file is filled on demand by e.g. changelog2version, the semantic version changelog can be specified explicitly to use its latest entry for the version value.

upy-package \
    --setup_file tests/data/setup.py \
    --package_changelog_file tests/data/sample_changelog.md \
    --create \
    --print \
    --pretty

Create package JSON file with files other than Python

By default all *.py files of the packages defined by the setup.py file are used to create the list of URLs in the package.json file. For a cross compiled MicroPython package the generated *.mpy files would not be picked up and added to the package.json file. The CLI arg --package_file_glob allows setting a different pattern than *.py to include different types of files. The specified pattern is not extending the default pattern, but replacing it. In order to include *.py and *.mpy files may use the pattern *.*py

upy-package \
    --setup_file tests/data/setup.py \
    --package_file_glob "*.mpy" \
    --create \
    --print \
    --pretty

Contributing

Unittests

Run the unittests locally with the following command after installing this package in a virtual environment

# run all tests
nose2 --config tests/unittest.cfg

# run only one specific tests
nose2 tests.test_setup2upypackage.TestSetup2uPyPackage.test_package_version

Generate the coverage files with

python create_report_dirs.py
coverage html

The coverage report is placed at reports/coverage/html/index.html

Precommit hooks

This repo is equipped with a .pre-commit-hooks.yaml file to be usable in other repos.

In order to run this repo's pre commit hooks, perform the following steps

pip install pre-commit
# for older systems without colored output support, last supported version is
# 1.18.3 (7c3404ef1f7593094c854f99bcd3b3eec75fbb2f, 1.19.0 broke it)
# test it with:
# from os import openpty
# r,w = openpty()

pre-commit run --all-files

Credits

Based on the PyPa sample project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

setup2upypackage-0.9.0.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

setup2upypackage-0.9.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file setup2upypackage-0.9.0.tar.gz.

File metadata

  • Download URL: setup2upypackage-0.9.0.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for setup2upypackage-0.9.0.tar.gz
Algorithm Hash digest
SHA256 4e418279e97b40c9f570d07a99175255a5b804fe01682a25f1bebd1e3f6660e4
MD5 0ba901617438a1b3c7d86536211f9dbd
BLAKE2b-256 7c4e68965ef31dcd8c3c23cae7e8ef470cbbcca5af7c8d6cae43c7492438e573

See more details on using hashes here.

File details

Details for the file setup2upypackage-0.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for setup2upypackage-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35678052652aace086b74c87d58eef253ed7b0e2ec80bb35387f9cddf96c598c
MD5 27c306880977df5e4dbac56faf39eada
BLAKE2b-256 236767c74ad56dae1d814c1f3c32c199f9755234723b6e5da49498ce541f19cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page