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

Convert to build as a module using hatchling #104

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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ docs/_build
# Virtual Env #
######################
venv
.venv

# Wheel build output #
######################
dist/
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
# spec-parser
# md-spec-parser

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


## Installation

```
# Create virtual environment
python3 -m venv venv

# Activate virtual environment
. ./venv/bin/activate

# Install module and dependencies in editable mode
pip install -e .
```

## Usage

```
python3 ./main.py -h
usage: main.py [-h] [-d] [-f] [-n] [-q] [-v] [-V] input_dir [output_dir]
$ md-spec-parser -h
usage: md-spec-parser [-h] [-d] [-f] [-n] [-q] [-v] [-V] input_dir [output_dir]

Generate documentation from an SPDX 3.0 model

Expand All @@ -30,15 +43,12 @@ Note that not all flags are functional yet.
### Checking input

```
python3 main.py -n some/where/.../model
md-spec-parser -n some/where/.../model
```

Note that no dependencies are needed.

### Generate output
```
python3 -m pip install -r requirements.txt
python3 main.py some/where/.../model some/where/else/.../output_dir
md-spec-parser some/where/.../model some/where/else/.../output_dir
```


Expand Down
41 changes: 41 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[project]
name = "md-spec-parser"
description = "Parse SPDX Spec Markdown Files"
dynamic = ["version"]
dependencies = [
"Jinja2 == 3.1.2",
"jsonpickle == 3.0.2",
"rdflib == 7.0.0",
]
required-python = ">= 3.8"
authors = [
{name = "Alexios Zavras", email = "[email protected]"},
]
readme = "README.md"
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Topic :: Software Development :: Build Tools",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

[project.urls]
Homepage = "https://github.com/spdx/spec-parser"
Repository = "https://github.com/spdx/spec-parser.git"
Issues = "https://github.com/spdx/spec-parser/issues"

[project.scripts]
md-spec-parser = "md_spec_parser.main:main"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.version]
path = "src/md_spec_parser/__init__.py"
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

File renamed without changes.
12 changes: 12 additions & 0 deletions src/md_spec_parser/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /usr/bin/env python3
#
# Copyright (c) 2024 Joshua Watt
#
# SPDX-License-Identifier: MIT

import sys

from .main import main

if __name__ == "__main__":
sys.exit(main())
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions main.py → src/md_spec_parser/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

# SPDX-License-Identifier: Apache-2.0

from spec_parser import Model
from runparams import RunParams
from . import Model
from .runparams import RunParams

if __name__ == "__main__":
def main():
cfg = RunParams()

m = Model(cfg.input_dir)
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions spec_parser/mkdocs.py → src/md_spec_parser/mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def gen_mkdocs(model, dir, cfg):
if not cfg.opt_force:
logging.error(f"Destination for mkdocs {dir} already exists, will not overwrite")
return

jinja = Environment(
loader=PackageLoader("spec_parser", package_path="templates/mkdocs"),
loader=PackageLoader("md_spec_parser", package_path="templates/mkdocs"),
autoescape=select_autoescape(),
trim_blocks=True, lstrip_blocks=True
)
Expand Down Expand Up @@ -60,7 +60,7 @@ def class_link(name):
_, other_ns, name = name.split("/")
return f"[/{other_ns}/{name}](../../{other_ns}/Classes/{name}.md)"
else:
return f"[{name}](../Classes/{name}.md)"
return f"[{name}](../Classes/{name}.md)"


def property_link(name):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 9 additions & 8 deletions runparams.py → src/md_spec_parser/runparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ def __init__(self):
self._ts = datetime.now(timezone.utc)
self.process_args()


@property
def autogen_header(self):
return f"Automatically generated by spec-parser v{self.parser_version} on {self._ts.isoformat()}"

@property
def input_dir(self):
return self.args.input_dir

@property
def output_dir(self):
return self.args.output_dir

@property
def opt_debug(self):
return self.args.debug
Expand All @@ -36,7 +36,7 @@ def opt_force(self):
@property
def opt_nooutput(self):
return self.args.nooutput

@property
def opt_quiet(self):
return self.args.quiet
Expand All @@ -47,8 +47,9 @@ def opt_verbose(self):

@property
def parser_version(self):
return sys.modules['spec_parser'].__version__

import md_spec_parser
return md_spec_parser.__version__

@property
def all_as_dict(self):
return { k: getattr(self, k) for k in (
Expand All @@ -66,7 +67,7 @@ def all_as_dict(self):
# - separate output dirs for mkdocs / RDF /JSON-LD / ...
# - maybe flags whether something might not be generated?
# - etc.

def process_args(self, args=sys.argv[1:]):
parser = argparse.ArgumentParser(description="Generate documentation from an SPDX 3.0 model")
parser.add_argument("input_dir", help="Directory containing the input specification files")
Expand All @@ -76,7 +77,7 @@ def process_args(self, args=sys.argv[1:]):
parser.add_argument("-n", "--nooutput", action="store_true", help="Do not generate anything, only check input")
parser.add_argument("-q", "--quiet", action="store_true", help="Print no output")
parser.add_argument("-v", "--verbose", action="store_true", help="Print verbose output")
parser.add_argument("-V", "--version", action="version", version=f"%(prog)s {RunParams.parser_version}")
parser.add_argument("-V", "--version", action="version", version=f"%(prog)s {self.parser_version}")
self.args = parser.parse_args(args)

if self.opt_nooutput:
Expand Down