spdx-python-model 0.0.4__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. spdx_python_model-0.0.6/.github/workflows/docs.yaml +160 -0
  2. {spdx_python_model-0.0.4 → spdx_python_model-0.0.6}/.github/workflows/test.yaml +4 -2
  3. {spdx_python_model-0.0.4 → spdx_python_model-0.0.6}/.gitignore +2 -1
  4. spdx_python_model-0.0.6/PKG-INFO +202 -0
  5. spdx_python_model-0.0.6/README.md +172 -0
  6. spdx_python_model-0.0.6/gen/generate-bindings +85 -0
  7. {spdx_python_model-0.0.4 → spdx_python_model-0.0.6}/pyproject.toml +45 -16
  8. spdx_python_model-0.0.6/src/spdx_python_model/__init__.py +114 -0
  9. spdx_python_model-0.0.6/src/spdx_python_model/bindings/__init__.py +13 -0
  10. spdx_python_model-0.0.6/src/spdx_python_model/bindings/_reexport.pyi +14 -0
  11. spdx_python_model-0.0.6/src/spdx_python_model/bindings/v3_0_1/__init__.py +13 -0
  12. spdx_python_model-0.0.6/src/spdx_python_model/bindings/v3_0_1/__main__.py +12 -0
  13. spdx_python_model-0.0.6/src/spdx_python_model/bindings/v3_0_1/cmd.py +75 -0
  14. spdx_python_model-0.0.4/src/spdx_python_model/bindings/v3_0_1.py → spdx_python_model-0.0.6/src/spdx_python_model/bindings/v3_0_1/model.py +3160 -2669
  15. spdx_python_model-0.0.6/src/spdx_python_model/bindings/v3_0_1/model.pyi +3058 -0
  16. spdx_python_model-0.0.6/src/spdx_python_model/py.typed +0 -0
  17. spdx_python_model-0.0.6/src/spdx_python_model/version.py +6 -0
  18. spdx_python_model-0.0.6/tests/data/3.0.1/example.spdx3.json +238 -0
  19. {spdx_python_model-0.0.4 → spdx_python_model-0.0.6}/tests/test_import.py +34 -0
  20. spdx_python_model-0.0.6/tests/test_load.py +30 -0
  21. spdx_python_model-0.0.6/tutorial/using-spdx3.ipynb +1438 -0
  22. spdx_python_model-0.0.6/www/404.html +40 -0
  23. spdx_python_model-0.0.6/www/index.html +83 -0
  24. spdx_python_model-0.0.4/PKG-INFO +0 -104
  25. spdx_python_model-0.0.4/README.md +0 -81
  26. spdx_python_model-0.0.4/gen/generate-bindings +0 -25
  27. spdx_python_model-0.0.4/src/spdx_python_model/__init__.py +0 -6
  28. spdx_python_model-0.0.4/src/spdx_python_model/bindings/__init__.py +0 -2
  29. spdx_python_model-0.0.4/src/spdx_python_model/version.py +0 -5
  30. {spdx_python_model-0.0.4 → spdx_python_model-0.0.6}/.github/workflows/publish.yaml +0 -0
  31. {spdx_python_model-0.0.4 → spdx_python_model-0.0.6}/LICENSE +0 -0
@@ -0,0 +1,160 @@
1
+ ---
2
+ # Publish library landing page to
3
+ # https://spdx.github.io/spdx-python-model/
4
+ #
5
+ # Publish API docs to
6
+ # https://spdx.github.io/spdx-python-model/doc/stable/ -- latest release
7
+ # https://spdx.github.io/spdx-python-model/doc/dev/ -- from main branch (unreleased)
8
+ # https://spdx.github.io/spdx-python-model/doc/1.0/ -- for specific version (all 1.0.x will all published to this URL)
9
+ #
10
+ # Publish tutorials to
11
+ # https://spdx.github.io/spdx-python-model/tutorial/
12
+
13
+ name: Publish docs
14
+
15
+ on:
16
+ push:
17
+ branches:
18
+ - main
19
+ paths:
20
+ - '.github/workflows/docs.yaml'
21
+ - 'gen/**'
22
+ - 'src/**'
23
+ - 'tutorial/**'
24
+ - 'www/**'
25
+ - 'README.md'
26
+ - 'pyproject.toml'
27
+ release:
28
+ types: [published]
29
+ workflow_dispatch:
30
+
31
+ jobs:
32
+ deploy-docs:
33
+ permissions:
34
+ contents: read
35
+ pages: write
36
+ id-token: write
37
+ environment:
38
+ name: github-pages
39
+ url: ${{ steps.deployment.outputs.page_url }}
40
+ runs-on: ubuntu-latest
41
+ steps:
42
+ - name: Checkout
43
+ uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
44
+ with:
45
+ fetch-depth: 0
46
+
47
+ - name: Keep previously published versions
48
+ run: |
49
+ mkdir -p pages
50
+ if git fetch origin gh-pages 2>/dev/null; then
51
+ git archive origin/gh-pages | tar -x -C pages/
52
+ fi
53
+
54
+ - name: Set up Python
55
+ uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
56
+ with:
57
+ python-version: "3.14"
58
+
59
+ - name: Install dependencies
60
+ run: pip install -e .
61
+ # Use editable install (-e) to include the generated binding submodules
62
+ # into the source tree so pdoc can see them.
63
+
64
+ - name: Install pdoc
65
+ run: pip install pdoc
66
+
67
+ - name: Install nbconvert
68
+ run: pip install nbconvert
69
+
70
+ - name: Get version
71
+ run: |
72
+ if [[ "${{ github.event_name }}" == "release" ]]; then
73
+ VERSION_RAW="${{ github.event.release.tag_name }}"
74
+ VERSION="${VERSION_RAW#v}"
75
+ echo "VERSION=$VERSION" >> $GITHUB_ENV
76
+ echo "MAJOR_MINOR=$(echo "$VERSION" | cut -d. -f1-2)" >> $GITHUB_ENV
77
+ echo "IS_RELEASE=true" >> $GITHUB_ENV
78
+ else
79
+ echo "VERSION=dev" >> $GITHUB_ENV
80
+ echo "MAJOR_MINOR=dev" >> $GITHUB_ENV
81
+ echo "IS_RELEASE=false" >> $GITHUB_ENV
82
+ fi
83
+
84
+ - name: Build landing page
85
+ run: |
86
+ if [[ -f www/index.html ]]; then
87
+ cp www/index.html pages/index.html
88
+ else
89
+ echo '<meta http-equiv="refresh" content="0; url=doc/stable/" />' > pages/index.html
90
+ fi
91
+
92
+ - name: Build API docs
93
+ run: |
94
+ OUT="pages/doc/$MAJOR_MINOR"
95
+
96
+ mkdir -p "$OUT"
97
+
98
+ pdoc spdx_python_model \
99
+ --logo "https://raw.githubusercontent.com/spdx/outreach/main/assets/SPDX_Logo/svg/SPDX%20logo%20color.svg" \
100
+ --logo-link "/spdx-python-model/doc/$MAJOR_MINOR/" \
101
+ --footer-text "spdx-python-model $VERSION" \
102
+ -o "$OUT"
103
+
104
+ # On release: update stable/ to match this major.minor.
105
+ if [[ "$IS_RELEASE" == "true" ]]; then
106
+ rm -rf pages/doc/stable
107
+ cp -r "pages/doc/$MAJOR_MINOR" pages/doc/stable
108
+ fi
109
+
110
+ # /doc/ redirects to site root.
111
+ mkdir -p pages/doc
112
+ echo '<meta http-equiv="refresh" content="0; url=../" />' > pages/doc/index.html
113
+
114
+ - name: Build tutorials
115
+ run: |
116
+ if [[ ! -d tutorial ]]; then
117
+ exit 0
118
+ fi
119
+
120
+ mkdir -p pages/tutorial
121
+
122
+ for nb in tutorial/*.ipynb; do
123
+ jupyter nbconvert --to html --output-dir pages/tutorial "$nb"
124
+ done
125
+
126
+ # Generate /tutorial/ index listing all tutorials.
127
+ if [[ ! -f tutorial/index.html ]]; then
128
+ {
129
+ echo '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8">'
130
+ echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">'
131
+ echo '<title>Tutorials - spdx-python-model</title>'
132
+ echo '<style>body{font-family:system-ui,sans-serif;max-width:640px;margin:4rem auto;padding:0 1.5rem;color:#222}a{color:#0969da}li{margin-bottom:.5rem}</style>'
133
+ echo '</head><body>'
134
+ echo '<h1><a href="../">spdx-python-model</a></h1>'
135
+ echo '<h2>Tutorials</h2><ul>'
136
+ for html in pages/tutorial/*.html; do
137
+ [[ "$(basename "$html")" == "index.html" ]] && continue
138
+ name=$(basename "$html" .html)
139
+ echo "<li><a href=\"$name.html\">$name</a> (<a href=\"https://github.com/spdx/spdx-python-model/blob/main/tutorial/$name.ipynb\">download .ipynb</a>)</li>"
140
+ done
141
+ echo '</ul></body></html>'
142
+ } > pages/tutorial/index.html
143
+ fi
144
+
145
+ # File not found (404) page from repo.
146
+ if [[ -f www/404.html ]]; then
147
+ cp www/404.html pages/404.html
148
+ fi
149
+
150
+ - name: Setup Pages
151
+ uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
152
+
153
+ - name: Upload artifact
154
+ uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
155
+ with:
156
+ path: pages
157
+
158
+ - name: Deploy to GitHub Pages
159
+ id: deployment
160
+ uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0
@@ -15,10 +15,12 @@ jobs:
15
15
  - "3.10"
16
16
  - "3.11"
17
17
  - "3.12"
18
+ - "3.13"
19
+ - "3.14"
18
20
  steps:
19
- - uses: actions/checkout@v4
21
+ - uses: actions/checkout@v6
20
22
  - name: Setup Python ${{ matrix.python-version }}
21
- uses: actions/setup-python@v4
23
+ uses: actions/setup-python@v6
22
24
  with:
23
25
  python-version: ${{ matrix.python-version }}
24
26
  - name: Install dependencies
@@ -161,4 +161,5 @@ cython_debug/
161
161
  #.idea/
162
162
 
163
163
  src/spdx_python_model/bindings/
164
- gen/*.py
164
+ gen/**/*.py
165
+ gen/**/*.pyi
@@ -0,0 +1,202 @@
1
+ Metadata-Version: 2.4
2
+ Name: spdx-python-model
3
+ Version: 0.0.6
4
+ Summary: SPDX Model Python Bindings
5
+ Project-URL: homepage, https://spdx.github.io/spdx-python-model/
6
+ Project-URL: repository, https://github.com/spdx/spdx-python-model.git
7
+ Project-URL: download, https://github.com/spdx/spdx-python-model/releases
8
+ Project-URL: documentation, https://spdx.github.io/spdx-python-model/doc/
9
+ Project-URL: issues, https://github.com/spdx/spdx-python-model/issues
10
+ Author-email: Joshua Watt <JPEWhacker@gmail.com>
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ Keywords: bindings,sbom,shacl2code,software-bill-of-materials,spdx,spdx3
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Requires-Python: >=3.9
25
+ Provides-Extra: dev
26
+ Requires-Dist: mypy>=1.19.1; extra == 'dev'
27
+ Requires-Dist: pylint>=3.3.9; extra == 'dev'
28
+ Requires-Dist: pytest>=7.4; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # spdx-python-model
32
+
33
+ [![PyPI - Version](https://img.shields.io/pypi/v/spdx-python-model)](https://pypi.org/project/spdx-python-model/)
34
+ ![Apache-2.0 license](https://img.shields.io/github/license/spdx/spdx-python-model)
35
+
36
+ `spdx-python-model` is a Python library for working with the SPDX 3 data model.
37
+
38
+ Read the [API documentation](https://spdx.github.io/spdx-python-model/).
39
+
40
+ All bindings in this repository are auto-generated from the RDF and SHACL
41
+ definitions of the [SPDX specification version 3][spdx-spec] using
42
+ [shacl2code](https://github.com/JPEWdev/shacl2code) during the package build
43
+ process.
44
+
45
+ **NOTE:** The bindings are pretty low level, intended for more directly
46
+ manipulating SPDX files. While they are fully functions, they lack higher level
47
+ helper functions that may be useful for creating SPDX documents. If you want a
48
+ higher level approach, please see the
49
+ [SPDX Python Tools](https://github.com/spdx/tools-python) (however, it
50
+ doesn't yet support SPDX 3).
51
+
52
+ [spdx-spec]: https://spdx.org/specifications
53
+
54
+ ## Installation
55
+
56
+ ### Install from PyPI
57
+
58
+ ```shell
59
+ python3 -m pip install spdx-python-model
60
+ ```
61
+
62
+ ### Install from Git
63
+
64
+ If you would like to pull the bindings directly from Git instead of using a
65
+ released version from PyPI, the following command can be used:
66
+
67
+ ```shell
68
+ python3 -m pip install git+https://github.com/spdx/spdx-python-model.git@main
69
+ ```
70
+
71
+ Note that this will pull the latest version from the `main` branch. If you want
72
+ a specific commit, replace `main` with the git commit SHA.
73
+
74
+ ### Install/build using local SPDX model files
75
+
76
+ Using local SPDX model files is ideal for testing pre-release versions
77
+ or when official URLs are not yet live.
78
+
79
+ It is also required for build systems that prohibit network access during
80
+ packaging, such as Debian or Yocto.
81
+
82
+ To build using local model files:
83
+
84
+ 1) Clone the repository:
85
+
86
+ ```shell
87
+ git clone https://github.com/spdx/spdx-python-model.git
88
+ cd spdx-python-model
89
+ ```
90
+
91
+ 2) Download model files:
92
+
93
+ Run the following commands to download the necessary files
94
+ for a specific SPDX version and keep it in a local directory:
95
+
96
+ ```shell
97
+ mkdir -p ~/spdx_models/v3.0.1
98
+ cd ~/spdx_models/v3.0.1
99
+ wget https://spdx.org/rdf/3.0.1/spdx-context.jsonld
100
+ wget https://spdx.org/rdf/3.0.1/spdx-json-serialize-annotations.ttl
101
+ wget https://spdx.org/rdf/3.0.1/spdx-model.ttl
102
+ ```
103
+
104
+ Or use your own model files.
105
+
106
+ The local directory must be organized by SPDX version,
107
+ with specific file names.
108
+
109
+ ```text
110
+ <SHACL2CODE_SPDX_DIR>/
111
+ └── v[VERSION]/
112
+ ├── spdx-context.jsonld
113
+ ├── spdx-json-serialize-annotations.ttl
114
+ └── spdx-model.ttl
115
+ ```
116
+
117
+ 3) Set the model directory:
118
+
119
+ Point `SHACL2CODE_SPDX_DIR` environment variable to that local directory.
120
+
121
+ ```shell
122
+ export SHACL2CODE_SPDX_DIR=~/spdx_models
123
+ ```
124
+
125
+ 4) Install/build:
126
+
127
+ ```shell
128
+ python3 -m pip install .
129
+ ```
130
+
131
+ or
132
+
133
+ ```shell
134
+ python3 -m build
135
+ ```
136
+
137
+ ## Usage
138
+
139
+ Each version of the SPDX spec has a module named `v{MAJOR}_{MINOR}_{MICRO}`
140
+ that contains the bindings for that version under the `spdx_python_model` top
141
+ level. For example:
142
+
143
+ ```python
144
+ import spdx_python_model
145
+
146
+ p = spdx_python_model.v3_0_1.Person()
147
+ ```
148
+
149
+ Alternatively, if a shorter name is desired, a specific version can be imported
150
+ with another name:
151
+
152
+ ```python
153
+ from spdx_python_model import v3_0_1 as spdx_3_0
154
+
155
+ p = spdx_3_0.Person()
156
+ ```
157
+
158
+ You can also have the bindings automatically detect the correct version to use
159
+ using the `load()` API:
160
+
161
+ ```python
162
+ import spdx_python_model
163
+
164
+ path = Path("/path/to/file.spdx3.json")
165
+
166
+ model, objset = spdx_python_model.load(path)
167
+
168
+ p = model.Person()
169
+ ```
170
+
171
+ Check out this short [Python notebook tutorial][tutorial]
172
+ to get started with spdx-python-model.
173
+
174
+ [tutorial]: https://spdx.github.io/spdx-python-model/tutorial/using-spdx3.html
175
+
176
+ ## Testing
177
+
178
+ This repository has support for running tests against the bindings using `pytest`.
179
+ To run the tests, first setup a virtual environment and install the development
180
+ variant of the package in editable mode:
181
+
182
+ ```shell
183
+ python3 -m venv .venv
184
+ . .venv/bin/activate
185
+ pip install -e '.[dev]'
186
+ ```
187
+
188
+ Then the tests can be run with:
189
+
190
+ ```shell
191
+ pytest -vx
192
+ ```
193
+
194
+ ## Making a new release
195
+
196
+ To make a new release of this repository, bump the version number found in
197
+ `src/spdx_python_model/version.py`, and merge it into the repo. After this,
198
+ make a new release in GitHub with the name `v` + *VERSION*, where *VERSION*
199
+ matches the version number specified in `version.py` (e.g. `v1.0.0`).
200
+
201
+ After this, GitHub actions will do the rest to build the package and publish it
202
+ to PyPI.
@@ -0,0 +1,172 @@
1
+ # spdx-python-model
2
+
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/spdx-python-model)](https://pypi.org/project/spdx-python-model/)
4
+ ![Apache-2.0 license](https://img.shields.io/github/license/spdx/spdx-python-model)
5
+
6
+ `spdx-python-model` is a Python library for working with the SPDX 3 data model.
7
+
8
+ Read the [API documentation](https://spdx.github.io/spdx-python-model/).
9
+
10
+ All bindings in this repository are auto-generated from the RDF and SHACL
11
+ definitions of the [SPDX specification version 3][spdx-spec] using
12
+ [shacl2code](https://github.com/JPEWdev/shacl2code) during the package build
13
+ process.
14
+
15
+ **NOTE:** The bindings are pretty low level, intended for more directly
16
+ manipulating SPDX files. While they are fully functions, they lack higher level
17
+ helper functions that may be useful for creating SPDX documents. If you want a
18
+ higher level approach, please see the
19
+ [SPDX Python Tools](https://github.com/spdx/tools-python) (however, it
20
+ doesn't yet support SPDX 3).
21
+
22
+ [spdx-spec]: https://spdx.org/specifications
23
+
24
+ ## Installation
25
+
26
+ ### Install from PyPI
27
+
28
+ ```shell
29
+ python3 -m pip install spdx-python-model
30
+ ```
31
+
32
+ ### Install from Git
33
+
34
+ If you would like to pull the bindings directly from Git instead of using a
35
+ released version from PyPI, the following command can be used:
36
+
37
+ ```shell
38
+ python3 -m pip install git+https://github.com/spdx/spdx-python-model.git@main
39
+ ```
40
+
41
+ Note that this will pull the latest version from the `main` branch. If you want
42
+ a specific commit, replace `main` with the git commit SHA.
43
+
44
+ ### Install/build using local SPDX model files
45
+
46
+ Using local SPDX model files is ideal for testing pre-release versions
47
+ or when official URLs are not yet live.
48
+
49
+ It is also required for build systems that prohibit network access during
50
+ packaging, such as Debian or Yocto.
51
+
52
+ To build using local model files:
53
+
54
+ 1) Clone the repository:
55
+
56
+ ```shell
57
+ git clone https://github.com/spdx/spdx-python-model.git
58
+ cd spdx-python-model
59
+ ```
60
+
61
+ 2) Download model files:
62
+
63
+ Run the following commands to download the necessary files
64
+ for a specific SPDX version and keep it in a local directory:
65
+
66
+ ```shell
67
+ mkdir -p ~/spdx_models/v3.0.1
68
+ cd ~/spdx_models/v3.0.1
69
+ wget https://spdx.org/rdf/3.0.1/spdx-context.jsonld
70
+ wget https://spdx.org/rdf/3.0.1/spdx-json-serialize-annotations.ttl
71
+ wget https://spdx.org/rdf/3.0.1/spdx-model.ttl
72
+ ```
73
+
74
+ Or use your own model files.
75
+
76
+ The local directory must be organized by SPDX version,
77
+ with specific file names.
78
+
79
+ ```text
80
+ <SHACL2CODE_SPDX_DIR>/
81
+ └── v[VERSION]/
82
+ ├── spdx-context.jsonld
83
+ ├── spdx-json-serialize-annotations.ttl
84
+ └── spdx-model.ttl
85
+ ```
86
+
87
+ 3) Set the model directory:
88
+
89
+ Point `SHACL2CODE_SPDX_DIR` environment variable to that local directory.
90
+
91
+ ```shell
92
+ export SHACL2CODE_SPDX_DIR=~/spdx_models
93
+ ```
94
+
95
+ 4) Install/build:
96
+
97
+ ```shell
98
+ python3 -m pip install .
99
+ ```
100
+
101
+ or
102
+
103
+ ```shell
104
+ python3 -m build
105
+ ```
106
+
107
+ ## Usage
108
+
109
+ Each version of the SPDX spec has a module named `v{MAJOR}_{MINOR}_{MICRO}`
110
+ that contains the bindings for that version under the `spdx_python_model` top
111
+ level. For example:
112
+
113
+ ```python
114
+ import spdx_python_model
115
+
116
+ p = spdx_python_model.v3_0_1.Person()
117
+ ```
118
+
119
+ Alternatively, if a shorter name is desired, a specific version can be imported
120
+ with another name:
121
+
122
+ ```python
123
+ from spdx_python_model import v3_0_1 as spdx_3_0
124
+
125
+ p = spdx_3_0.Person()
126
+ ```
127
+
128
+ You can also have the bindings automatically detect the correct version to use
129
+ using the `load()` API:
130
+
131
+ ```python
132
+ import spdx_python_model
133
+
134
+ path = Path("/path/to/file.spdx3.json")
135
+
136
+ model, objset = spdx_python_model.load(path)
137
+
138
+ p = model.Person()
139
+ ```
140
+
141
+ Check out this short [Python notebook tutorial][tutorial]
142
+ to get started with spdx-python-model.
143
+
144
+ [tutorial]: https://spdx.github.io/spdx-python-model/tutorial/using-spdx3.html
145
+
146
+ ## Testing
147
+
148
+ This repository has support for running tests against the bindings using `pytest`.
149
+ To run the tests, first setup a virtual environment and install the development
150
+ variant of the package in editable mode:
151
+
152
+ ```shell
153
+ python3 -m venv .venv
154
+ . .venv/bin/activate
155
+ pip install -e '.[dev]'
156
+ ```
157
+
158
+ Then the tests can be run with:
159
+
160
+ ```shell
161
+ pytest -vx
162
+ ```
163
+
164
+ ## Making a new release
165
+
166
+ To make a new release of this repository, bump the version number found in
167
+ `src/spdx_python_model/version.py`, and merge it into the repo. After this,
168
+ make a new release in GitHub with the name `v` + *VERSION*, where *VERSION*
169
+ matches the version number specified in `version.py` (e.g. `v1.0.0`).
170
+
171
+ After this, GitHub actions will do the rest to build the package and publish it
172
+ to PyPI.
@@ -0,0 +1,85 @@
1
+ #! /bin/sh
2
+ #
3
+ # SPDX-FileType: SOURCE
4
+ # SPDX-License-Identifier: Apache-2.0
5
+ #
6
+ # Generate the per-version bindings and the bindings package __init__.py.
7
+
8
+ set -e
9
+
10
+ # SPDX versions to generate
11
+ SPDX_VERSIONS="3.0.1"
12
+
13
+ get_context_url() {
14
+ echo "https://spdx.org/rdf/$1/spdx-context.jsonld"
15
+ }
16
+
17
+ # Generate the per-version bindings with shacl2code.
18
+ # Each version ends up in its own subpackage (e.g. "v3_0_1").
19
+ for v in $SPDX_VERSIONS; do
20
+ MODNAME="v$(echo "$v" | sed 's/[^a-zA-Z0-9_]/_/g')"
21
+
22
+ CONTEXT_URL="$(get_context_url "$v")"
23
+ if [ -n "${SHACL2CODE_SPDX_DIR}" ] && [ -d "${SHACL2CODE_SPDX_DIR}/$v" ]
24
+ then
25
+ shacl2code generate --input "file://${SHACL2CODE_SPDX_DIR}/$v/spdx-model.ttl" \
26
+ --input "file://${SHACL2CODE_SPDX_DIR}/$v/spdx-json-serialize-annotations.ttl" \
27
+ --context-url "file://${SHACL2CODE_SPDX_DIR}/$v/spdx-context.jsonld" $CONTEXT_URL \
28
+ --license Apache-2.0 \
29
+ python \
30
+ --output "$MODNAME"
31
+ else
32
+ shacl2code generate --input https://spdx.org/rdf/$v/spdx-model.ttl \
33
+ --input https://spdx.org/rdf/$v/spdx-json-serialize-annotations.ttl \
34
+ --context $CONTEXT_URL \
35
+ --license Apache-2.0 \
36
+ python \
37
+ --output "$MODNAME"
38
+ fi
39
+ done
40
+
41
+ # Generate the bindings package __init__.py.
42
+ {
43
+ echo '# SPDX-FileType: SOURCE'
44
+ echo '# SPDX-License-Identifier: Apache-2.0'
45
+ echo '#'
46
+ echo '# Generated by generate-bindings at build time. DO NOT EDIT.'
47
+ echo '"""SPDX model bindings, one submodule per version.'
48
+ echo
49
+ echo 'Versions are not imported here, so importing one does not load the others.'
50
+ echo '"""'
51
+ echo
52
+ echo '# JSON-LD @context URL -> version submodule name, for lazy lookup by load().'
53
+ echo '_CONTEXT_TABLE = {'
54
+ for v in $SPDX_VERSIONS; do
55
+ MODNAME="v$(echo "$v" | sed 's/[^a-zA-Z0-9_]/_/g')"
56
+ CONTEXT_URL="$(get_context_url "$v")"
57
+ echo " \"$CONTEXT_URL\": \"$MODNAME\","
58
+ done
59
+ echo '}'
60
+ } > __init__.py
61
+
62
+ # Generate _reexport.pyi: lets type checkers resolve spdx_python_model.vX types
63
+ # while the runtime loads versions lazily (imported only under TYPE_CHECKING).
64
+ {
65
+ echo '# SPDX-FileType: SOURCE'
66
+ echo '# SPDX-License-Identifier: Apache-2.0'
67
+ echo '#'
68
+ echo '# Generated by generate-bindings at build time. DO NOT EDIT.'
69
+ echo '"""Type-checking-only re-exports so ``spdx_python_model.vX`` types resolve.'
70
+ echo
71
+ echo 'Imported under TYPE_CHECKING only; the runtime loads versions lazily via the'
72
+ echo 'package __getattr__. __all__ marks the names as re-exports for --no-implicit-reexport.'
73
+ echo '"""'
74
+ for v in $SPDX_VERSIONS; do
75
+ MODNAME="v$(echo "$v" | sed 's/[^a-zA-Z0-9_]/_/g')"
76
+ echo "from . import $MODNAME"
77
+ done
78
+ echo
79
+ echo '__all__ = ['
80
+ for v in $SPDX_VERSIONS; do
81
+ MODNAME="v$(echo "$v" | sed 's/[^a-zA-Z0-9_]/_/g')"
82
+ echo " \"$MODNAME\","
83
+ done
84
+ echo ']'
85
+ } > _reexport.pyi