-
Notifications
You must be signed in to change notification settings - Fork 2
Initial implementation #1
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| --- | ||
| name: Upload SPDX Python Bindings | ||
| on: | ||
| release: | ||
| types: | ||
| - published | ||
|
|
||
| jobs: | ||
| test: | ||
| uses: ./.github/workflows/test.yaml | ||
|
|
||
| deploy: | ||
| needs: | ||
| - test | ||
|
|
||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: '3.x' | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install build | ||
|
|
||
| - name: Build package | ||
| run: python -m build | ||
|
|
||
| # Uncomment this once we have a PyPi repo | ||
| # - name: Publish distribution to PyPI | ||
| # uses: pypa/gh-action-pypi-publish@release/v1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| --- | ||
| name: Test SPDX Python Bindings | ||
| on: | ||
| - push | ||
| - pull_request | ||
| - workflow_call | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: | ||
| - "3.9" | ||
| - "3.10" | ||
| - "3.11" | ||
| - "3.12" | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Setup Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install build | ||
| - name: Build package | ||
| run: | | ||
| python -m build | ||
| - name: Install package | ||
| run: | | ||
| pip install -e .[dev] | ||
| - name: Run tests | ||
| run: | | ||
| pytest -v |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| # Byte-compiled / optimized / DLL files | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
|
|
||
| # C extensions | ||
| *.so | ||
|
|
||
| # Distribution / packaging | ||
| .Python | ||
| build/ | ||
| develop-eggs/ | ||
| dist/ | ||
| downloads/ | ||
| eggs/ | ||
| .eggs/ | ||
| lib/ | ||
| lib64/ | ||
| parts/ | ||
| sdist/ | ||
| var/ | ||
| wheels/ | ||
| share/python-wheels/ | ||
| *.egg-info/ | ||
| .installed.cfg | ||
| *.egg | ||
| MANIFEST | ||
|
|
||
| # PyInstaller | ||
| # Usually these files are written by a python script from a template | ||
| # before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
| *.manifest | ||
| *.spec | ||
|
|
||
| # Installer logs | ||
| pip-log.txt | ||
| pip-delete-this-directory.txt | ||
|
|
||
| # Unit test / coverage reports | ||
| htmlcov/ | ||
| .tox/ | ||
| .nox/ | ||
| .coverage | ||
| .coverage.* | ||
| *.lcov | ||
| .cache | ||
| nosetests.xml | ||
| coverage.xml | ||
| *.cover | ||
| *.py,cover | ||
| .hypothesis/ | ||
| .pytest_cache/ | ||
| cover/ | ||
|
|
||
| # Translations | ||
| *.mo | ||
| *.pot | ||
|
|
||
| # Django stuff: | ||
| *.log | ||
| local_settings.py | ||
| db.sqlite3 | ||
| db.sqlite3-journal | ||
|
|
||
| # Flask stuff: | ||
| instance/ | ||
| .webassets-cache | ||
|
|
||
| # Scrapy stuff: | ||
| .scrapy | ||
|
|
||
| # Sphinx documentation | ||
| docs/_build/ | ||
|
|
||
| # PyBuilder | ||
| .pybuilder/ | ||
| target/ | ||
|
|
||
| # Jupyter Notebook | ||
| .ipynb_checkpoints | ||
|
|
||
| # IPython | ||
| profile_default/ | ||
| ipython_config.py | ||
|
|
||
| # pyenv | ||
| # For a library or package, you might want to ignore these files since the code is | ||
| # intended to run in multiple environments; otherwise, check them in: | ||
| # .python-version | ||
|
|
||
| # pipenv | ||
| # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
| # However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
| # having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
| # install all needed dependencies. | ||
| #Pipfile.lock | ||
|
|
||
| # poetry | ||
| # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
| # This is especially recommended for binary packages to ensure reproducibility, and is more | ||
| # commonly ignored for libraries. | ||
| # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
| #poetry.lock | ||
|
|
||
| # pdm | ||
| # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
| #pdm.lock | ||
| # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
| # in version control. | ||
| # https://pdm.fming.dev/#use-with-ide | ||
| .pdm.toml | ||
|
|
||
| # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
| __pypackages__/ | ||
|
|
||
| # Celery stuff | ||
| celerybeat-schedule | ||
| celerybeat.pid | ||
|
|
||
| # SageMath parsed files | ||
| *.sage.py | ||
|
|
||
| # Environments | ||
| .env | ||
| .venv | ||
| env/ | ||
| venv/ | ||
| ENV/ | ||
| env.bak/ | ||
| venv.bak/ | ||
|
|
||
| # Spyder project settings | ||
| .spyderproject | ||
| .spyproject | ||
|
|
||
| # Rope project settings | ||
| .ropeproject | ||
|
|
||
| # mkdocs documentation | ||
| /site | ||
|
|
||
| # mypy | ||
| .mypy_cache/ | ||
| .dmypy.json | ||
| dmypy.json | ||
|
|
||
| # Pyre type checker | ||
| .pyre/ | ||
|
|
||
| # pytype static type analyzer | ||
| .pytype/ | ||
|
|
||
| # Cython debug symbols | ||
| cython_debug/ | ||
|
|
||
| # PyCharm | ||
| # JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
| # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
| # and can be added to the global gitignore or merged into this file. For a more nuclear | ||
| # option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
| #.idea/ | ||
|
|
||
| src/spdx_python_model/bindings/ | ||
| gen/*.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,82 @@ | ||
| # spdx-python-model | ||
| Generated Python code for SPDX Spec version 3 | ||
|
|
||
| All bindings in this repository are generated using | ||
| [shacl2code](https://github.com/JPEWdev/shacl2code) at the time the package is | ||
| built. | ||
|
|
||
| **NOTE:** The bindings are pretty low level, intended for more directly | ||
| manipulating SPDX files. While they are fully functions, they lack higher level | ||
| helper functions that may be useful for creating SPDX documents. If you want a | ||
| higher level approach, please see the | ||
| [SPDX Python Tools](https://github.com/spdx/tools-python) (however this repo | ||
| doesn't yet support SPDX 3) | ||
|
|
||
| ## Installation (PyPi) | ||
|
|
||
| **TODO** Add instructions for how to install these from PyPi once they are published there | ||
|
|
||
|
|
||
| ## Installation (Git) | ||
|
|
||
| If you would like to pull the bindings directly from Git instead of using a | ||
| released version from PyPi, the following command can be used: | ||
|
|
||
| ```shell | ||
| python3 -m pip install git+https://github.com/spdx/spdx-python-model.git@main | ||
| ``` | ||
|
|
||
| Note that this will pull the latest version from the `main` branch. If you want | ||
| a specific commit, replace `main` with the git commit SHA | ||
|
|
||
| ## Usage | ||
|
|
||
| Each version of the SPDX spec has a module named `v{MAJOR}_{MINOR}_{MICRO}` | ||
| that contains the bindings for that version under the `spdx_python_model` top | ||
| level. For example: | ||
|
|
||
| ```python | ||
| import spdx_python_model | ||
|
|
||
| p = spdx_python_model.v3_0_1.Person() | ||
| ``` | ||
|
|
||
| Alternatively, if a shorter name is desired, a specific version can be imported | ||
| with another name: | ||
|
|
||
|
|
||
| ```python | ||
| from spdx_python_model import v3_0_1 as spdx_3_0_1 | ||
|
|
||
| p = spdx_3_0_1.Person() | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| This repository has support for running tests against the bindings using `pytest`. | ||
| To run the tests, first setup a virtual environment and install the development | ||
| variant of the package in editable mode: | ||
|
|
||
| ```shell | ||
| python3 -m venv .venv | ||
| . .venv/bin/activate | ||
| pip install -e '.[dev]' | ||
| ``` | ||
|
|
||
| Then the tests can be run with: | ||
|
|
||
| ```shell | ||
| pytest -vx | ||
| ``` | ||
|
|
||
| ## Making a new release | ||
|
|
||
| **NOTE** We do not have a PyPi repo yet, so this won't work | ||
|
|
||
| To make a new release of this repository, bump the version number found in | ||
| `src/spdx_python_model/version.py`, and merge it into the repo. After this, | ||
| make a new release in GitHub with the name `v` + *VERSION*, where *VERSION* | ||
| matches the version number specified in `version.py` (e.g. `v1.0.0`). | ||
|
|
||
| After this, GitHub actions will do the rest to build the package and publish it | ||
| to PyPi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #! /bin/sh | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| set -e | ||
|
|
||
| # SPDX versions to generate | ||
| SPDX_VERSIONS="3.0.1" | ||
|
|
||
| mkdir -p "gen" | ||
|
|
||
| echo "# Import all versions" > __init__.py | ||
|
|
||
| for v in $SPDX_VERSIONS; do | ||
| MODNAME="v$(echo "$v" | sed 's/[^a-zA-Z0-9_]/_/g')" | ||
|
|
||
| shacl2code generate --input https://spdx.org/rdf/$v/spdx-model.ttl \ | ||
| --input https://spdx.org/rdf/$v/spdx-json-serialize-annotations.ttl \ | ||
| --context https://spdx.org/rdf/$v/spdx-context.jsonld \ | ||
| --license Apache-2.0 \ | ||
| python \ | ||
| -o "$MODNAME.py" | ||
|
|
||
| echo "from . import $MODNAME" >> __init__.py | ||
| done |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.