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

New command-line interface (options) #181

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
111 changes: 74 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,102 @@
# spec-parser

Automagically process the model of the SPDXv3 specification to validate input
or to generate stuff.
and/or generate stuff.

## Usage
## Functionality

```shell
python3 ./main.py -h
usage: main.py [-h] [-d] [-f] [-n] [-q] [-v] [-V] input_dir [output_dir]
The software always reads and validates the complete model (given as input).

It then optionally generates one or more of the following outputs:

1. JSON dump of the parsed model, to load all data without parsing
2. MkDocs files, to be used by mkdocs to generate a website
3. PlantUML file, to be used by plantuml to generate a diagram
4. RDF files (ontology and context), for any need
5. TeX files, to be used by LaTeX to generate a printable version
6. Web page files, to provide information on the RDF URIs

If no generation is specified in the command line,
the default functionality is to generate everything.

## Usage

Generate documentation from an SPDX 3.0 model
```
usage: main.py [-h] [-V] [-d] [-v] [-f] [-n]
[-o OUTPUT]
[-j] [-J dir]
[-m] [-M dir]
[-p] [-P dir]
[-r] [-R dir]
[-t] [-T dir]
[-w] [-W dir]
input_dir

Generate documentation from an SPDXv3 model.

positional arguments:
input_dir Directory containing the input specification files
output_dir Directory to write the output files to
input_dir Path to the input 'model' directory.

options:
-h, --help show this help message and exit
-d, --debug Print debug output
-f, --force Overwrite existing generated files
-n, --nooutput Do not generate anything, only check input
-q, --quiet Print no output
-v, --verbose Print verbose output
-V, --version show program's version number and exit
```
-h, --help Show this help message and exit
-d, --debug Print debug output
Comment on lines +41 to +42
Copy link
Contributor

@bact bact Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-h, --help Show this help message and exit
-d, --debug Print debug output
-h, --help Show this help message and exit.
-d, --debug Print spec-parser debug information.

Keep consistent with other descriptions that have a fullstop.

-f, --force Force overwrite of existing output directories.
-j, --generate-jsondump Generate a dump of the model in JSON format.
-J, --output-jsondump OUTPUT_JSONDUMP Output directory for JSON dump file.
-m, --generate-mkdocs Generate mkdocs output.
-M, --output-mkdocs OUTPUT_MKDOCS Output directory for mkdocs files.
Comment on lines +46 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-m, --generate-mkdocs Generate mkdocs output.
-M, --output-mkdocs OUTPUT_MKDOCS Output directory for mkdocs files.
-m, --generate-mkdocs Generate MkDocs output.
-M, --output-mkdocs OUTPUT_MKDOCS Output directory for MkDocs files.

Keep the original casing. Similar to PlantUML and TeX.

-n, --no-output Perform no output generation, only input validation.
-o, --output OUTPUT Single output directory for all output types.
-p, --generate-plantuml Generate PlantUML output.
-P, --output-plantuml OUTPUT_PLANTUML Output directory for PlantUML files.
-r, --generate-rdf Generate RDF output.
-R, --output-rdf OUTPUT_RDF Output directory for RDF files.
-t, --generate-tex Generate TeX output.
-T, --output-tex OUTPUT_TEX Output directory for TeX files.
-v, --verbose Print verbose output
Copy link
Contributor

@bact bact Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-v, --verbose Print verbose output
-v, --verbose Print verbose information.

Keep consistent with other descriptions that have a fullstop.

-V, --version Show program version number and exit
-w, --generate-webpages Generate web pages output.
-W, --output-webpages OUTPUT_WEBPAGES Output directory for web pages.

Note that not all flags are functional yet.
```

### Checking input

If no generation is needed and only input validation is required:

```shell
python3 main.py -n some/where/.../model
```

Note that no dependencies are needed.

### Generate output

```shell
python3 -m pip install -r requirements.txt
python3 main.py some/where/.../model some/where/else/.../output_dir
```
## Prerequisites

## Current status (mostly complete / in progress)
| **Action** | *Prerequisites* |
|---|---|
| input validation (`-n`/`--no-output`) | None |
| JSON dump generation | [jsonpickle](https://pypi.org/project/jsonpickle/) Python module |
| MkDocs generation | [Jinja2](https://pypi.org/project/Jinja2/) Python module |
| PlantUML generation | None |
| RDF generation | [RDFlib](https://pypi.org/project/rdflib/) Python module |
| TeX generation | [Jinja2](https://pypi.org/project/Jinja2/) Python module and [pandoc](https://pandoc.org/) software |
| Web pages generation | [Jinja2](https://pypi.org/project/Jinja2/) Python module |

- [x] parse everything in model
- [x] generate mkdocs input
- [x] generate JSON dump
- [x] generate diagrams
- [x] generate RDF ontology
- [x] generate JSON-LD context
The software will check for the presence of prerequisites,
according to the calling arguments,
and exit if they are not present.

## Contributing

Contributions are always welcome!

Feel free to open issues for any behavior that is (or even simply does not
seem) correct.
Feel free to open issues for any behavior that is not
(or even simply does not seem) correct.

However, due to the pressure for releasing SPDXv3, development is happening in
fast mode, and not always refelcted in this repository. To save everyone
valuable time, if you want to contribute code: clearly indicate in the
corresponding issue your willingness to work on it, and _wait_ for the
assignment of the issue to you.
However, due to the pressure for releasing SPDXv3,
development is happening in fast mode,
and not always refelcted in this repository.
To save everyone valuable time, if you want to contribute code:
clearly indicate in the corresponding issue
your willingness to work on it,
and _wait_ for the assignment of the issue to you.
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from spec_parser import Model

if __name__ == "__main__":
cfg = RunParams()
cfg = RunParams("spec-parser")

m = Model(cfg.input_dir)
if not cfg.opt_nooutput:
m.gen_all(cfg.output_dir, cfg)
m = Model(cfg.input_path)
if not cfg.no_output:
m.generate(cfg)
31 changes: 21 additions & 10 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
fix = false
indent-width = 4
line-length = 140
line-length = 145
output-format = "full"
# output-format = "grouped"
preview = false
required-version = ">=0.4"
required-version = ">=0.9"
show-fixes = true

[format]
docstring-code-format = false
indent-style = "space"
line-ending = "native"
preview = false
quote-style = "double"
skip-magic-trailing-comma = false

[lint]
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
fixable = ["ALL"]
ignore = [ "C408", "C901", "COM812", "G004", "ISC001", "RET505", "S101", ]
ignore-init-module-imports = true
ignore = [ "C408", "C901", "COM812", "EM102", "G004", "ISC001", "RET505", "S101", ]
logger-objects = ["cfg.log"]
preview = false
# anything but "AIR", "ANN", "D", "NPY", "PD",
select = [
"A", "AIR", "ARG", "ASYNC", "B", "C", "BLE", "C4", "COM", "DJ", "DTZ",
"EM", "ERA", "E", "W", "EXE", "F", "FA", "FBT", "FIX", "FLY", "G", "I",
"ICN", "INP", "INT", "ISC", "LOG", "N", "NPY", "PD", "PERF", "PGH", "PIE",
"PL", "PT", "PTH", "PYI", "Q", "R", "RET", "RSE", "RUF", "S", "SIM",
"SLF", "SLOT", "T10", "T20", "TCH", "TD", "TID", "TRIO", "TRY", "UP", "YTT",
"A", "ARG", "ASYNC", "ASYNC1", "B", "BLE", "C", "C4", "C90", "COM", "CPY",
"DJ", "DOC", "DTZ", "E", "EM", "ERA", "EXE", "F", "FA", "FAST", "FBT", "FIX",
"FLY", "FURB", "G", "I", "ICN", "INP", "INT", "ISC", "LOG", "N", "PERF",
"PGH", "PIE", "PL", "PT", "PTH", "PYI", "Q", "R", "RET", "RSE", "RUF", "S",
"SIM", "SLF", "SLOT", "T10", "T20", "TC", "TD", "TID", "TRY", "UP", "W", "YTT",

]
unfixable = []

Expand All @@ -42,7 +46,14 @@ unfixable = []
"PLR0915", # too many statements, for gen_rdf_ontology
]

[lint.isort]
case-sensitive = true
force-sort-within-sections = false
from-first = false
lines-between-types = 0
split-on-trailing-comma = false

[lint.pylint]
max-branches = 35
max-statements = 55
max-statements = 65

Loading