|
| 1 | +# SPDX-License-Identifier: MIT |
| 2 | +# Copyright (c) the purl authors |
| 3 | +# Visit https://github.com/package-url/purl-spec and https://packageurl.org for support |
| 4 | + |
| 5 | +PYTHON_EXE?=python3 |
| 6 | +VENV_LOCATION=venv |
| 7 | +ACTIVATE?=. ${VENV_LOCATION}/bin/activate; |
| 8 | + |
| 9 | +CODEGEN?=datamodel-codegen \ |
| 10 | + --target-python-version 3.10 \ |
| 11 | + --use-double-quotes \ |
| 12 | + --use-exact-imports \ |
| 13 | + --use-standard-collections \ |
| 14 | + --wrap-string-literal \ |
| 15 | + --enum-field-as-literal all \ |
| 16 | + --formatters ruff-format \ |
| 17 | + --field-constraints \ |
| 18 | + --disable-timestamp \ |
| 19 | + --keep-model-order \ |
| 20 | + --custom-file-header-path LICENSE \ |
| 21 | + --input-file-type jsonschema \ |
| 22 | + --output-model-type pydantic_v2.BaseModel |
| 23 | + |
| 24 | +virtualenv: |
| 25 | + @echo "-> Bootstrap the virtualenv with PYTHON_EXE=${PYTHON_EXE}" |
| 26 | + ${PYTHON_EXE} -m venv ${VENV_LOCATION} |
| 27 | + |
| 28 | +conf: virtualenv |
| 29 | + @echo "-> Install dependencies" |
| 30 | + @${ACTIVATE} pip install -r etc/scripts/requirements.txt |
| 31 | + |
| 32 | +formatcode: |
| 33 | + @echo "-> Run Ruff format" |
| 34 | + @${ACTIVATE} ruff check --select I --fix |
| 35 | + @${ACTIVATE} ruff format |
| 36 | + @echo "-> Run Ruff linter" |
| 37 | + @${ACTIVATE} ruff check --fix |
| 38 | + |
| 39 | +formatjson: |
| 40 | + @echo "-> Format JSON files" |
| 41 | + @${ACTIVATE} python etc/scripts/format_json.py schemas/ |
| 42 | + @${ACTIVATE} python etc/scripts/format_json.py types/ |
| 43 | + @${ACTIVATE} python etc/scripts/format_json.py tests/ |
| 44 | + |
| 45 | +format: formatcode formatjson |
| 46 | + @echo "-> Format all files" |
| 47 | + |
| 48 | +checkjson: |
| 49 | + @echo "-> Validate JSON schemas" |
| 50 | + @${ACTIVATE} check-jsonschema --check-metaschema --verbose schemas/*.json |
| 51 | + @echo "-> Validate JSON data files against the schemas" |
| 52 | + @${ACTIVATE} check-jsonschema --schemafile schemas/purl-types-index.schema.json --verbose purl-types-index.json |
| 53 | + @${ACTIVATE} check-jsonschema --schemafile schemas/purl-type-definition.schema.json --verbose types/*-definition.json |
| 54 | + @${ACTIVATE} check-jsonschema --schemafile schemas/purl-test.schema.json --verbose tests/*/*-test.json |
| 55 | + |
| 56 | +checkcode: |
| 57 | + @echo "-> Run Ruff linter validation (pycodestyle, bandit, isort, and more)" |
| 58 | + @${ACTIVATE} ruff --config etc/scripts/pyproject.toml check |
| 59 | + @echo "-> Run Ruff format validation" |
| 60 | + @${ACTIVATE} ruff --config etc/scripts/pyproject.toml format --check |
| 61 | + |
| 62 | +check: checkjson checkcode |
| 63 | + @echo "-> Run all checks" |
| 64 | + |
| 65 | +clean: |
| 66 | + @echo "-> Clean the Python env" |
| 67 | + rm -rf .venv/ |
| 68 | + find . -type f -name '*.py[co]' -delete |
| 69 | + |
| 70 | +gencode: |
| 71 | + @echo "-> Generate Python code from schemas" |
| 72 | + @${ACTIVATE} ${CODEGEN} \ |
| 73 | + --input schemas/purl-types-index.schema.json \ |
| 74 | + --output etc/scripts/purl_types_index.py |
| 75 | + @${ACTIVATE} ${CODEGEN} \ |
| 76 | + --input schemas/purl-type-definition.schema.json \ |
| 77 | + --output etc/scripts/purl_type_definition.py |
| 78 | + @${ACTIVATE} ${CODEGEN} \ |
| 79 | + --input schemas/purl-test.schema.json \ |
| 80 | + --output etc/scripts/purl_test.py |
| 81 | + @echo "-> Run Black format for generated code" |
| 82 | + @${ACTIVATE} black -l 100 --preview --enable-unstable-feature string_processing etc/scripts/*.py |
| 83 | + |
| 84 | +gendocs: |
| 85 | + @${ACTIVATE} python etc/scripts/generate_index_and_docs.py |
| 86 | + |
| 87 | + |
| 88 | +.PHONY: virtualenv conf formatcode formatjson format checkcode checkjson check clean gencode gendocs |
0 commit comments