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

Add Python packaging infrastructure. #89

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

# Setuptools #
######################
build
dist
*.egg-info
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@

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

## Build / Install

```
python3 -m pip install build
python3 -m build
```

This creates a wheel file in `dist` that can be installed. Alternatively,
run setup.py to install:

```
python3 ./setup.py install
```

## Usage

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

Generate documentation from an SPDX 3.0 model
Expand All @@ -30,15 +43,14 @@ Note that not all flags are functional yet.
### Checking input

```
python3 main.py -n some/where/.../model
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
spec-parser some/where/.../model some/where/else/.../output_dir
```


Expand Down
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=61.0", "build", "wheel"]

[project]
name = "spec_parser"
version = "0.1.0"
dependencies = [
Copy link
Member

Choose a reason for hiding this comment

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

these dependencies are only for generating output; they are not needed when simply checking the input.

Copy link
Author

Choose a reason for hiding this comment

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

Is there value in leaving them out?

If you're wanting to avoid even hassling with installation when you just want to check, you can still run the main.py file; it's just done differently now. I can add docs to the README to mention that if we want.

"Jinja2",
"jsonpickle",
"rdflib"
]

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

[tool.setuptools.package-data]
"spec_parser.templates.mkdocs" = ["*.j2"]
Copy link
Member

Choose a reason for hiding this comment

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

is there a way to have everything under templates included? Or do we have to add new lines here for each new directory therein? FYI, different generation formats will use different directories (e.g. I already have a onefile for when a single file has to be generated, plus some others).

Copy link
Author

Choose a reason for hiding this comment

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

I can change it to look for everything under templates if we want.

3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from setuptools import setup
setup()
8 changes: 6 additions & 2 deletions main.py → spec_parser/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
# SPDX-License-Identifier: Apache-2.0

from spec_parser import Model
from runparams import RunParams
from spec_parser.runparams import RunParams
Copy link
Member

Choose a reason for hiding this comment

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

why move it? RunParams are for processing command-line options. Not really anything to do with the spec-parsing itself.

Copy link
Author

Choose a reason for hiding this comment

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

This is to avoid namespace collisions when installing the parser in a Python environment. If we're concerned about clarity surrounding purpose, we could move main.py and runparams.py into something like spec_parser.cmd. But that might make it more inconvenient to run main.py directly. Was there a reason we separated the run parameters into their own file if they have no use outside of the command line?


if __name__ == "__main__":

def main():
Copy link
Member

Choose a reason for hiding this comment

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

why create a function? Is it something setuptools require?

Copy link
Author

Choose a reason for hiding this comment

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

Yes; this is how you get a spec-parser command-line utility. You have to identify a function for Python to call when run as a command-line tool.

cfg = RunParams()

m = Model(cfg.input_dir)
if not cfg.opt_nooutput:
m.gen_all(cfg.output_dir, cfg)


if __name__ == "__main__":
main()
File renamed without changes.