### Set up Development Environment
Source: https://github.com/spdx/tools-python/blob/main/CONTRIBUTING.md
This snippet shows how to create a virtual environment, activate it, and install the project's development dependencies, including optional ones, to ensure all tests can be executed.
```sh
git checkout -b fix-or-improve-something
python -m venv ./venv
./venv/bin/activate
pip install -e ".[development]"
```
--------------------------------
### Install and Run Pytest
Source: https://github.com/spdx/tools-python/blob/main/CONTRIBUTING.md
This snippet demonstrates how to install the pytest testing framework and then run the project's tests with verbose output.
```sh
pip install pytest
pytest -vvs
```
--------------------------------
### Install Python tools-python
Source: https://github.com/spdx/tools-python/blob/main/README.md
Installs the spdx-tools Python package from PyPI or a local source distribution. It's recommended to use a virtual environment for installation.
```bash
yourenv/bin/pip install .
yourenv/bin/pip install spdx-tools==0.8.0a2
pip install "spdx-tools[graph_generation]"
```
--------------------------------
### Create Checksum Object with ChecksumAlgorithm
Source: https://github.com/spdx/tools-python/wiki/How-to-migrate-from-0.6.1-to-0.7.0
Illustrates how to create a Checksum object using the new ChecksumAlgorithm enum. The identifier for the checksum must now be an instance of ChecksumAlgorithm, such as ChecksumAlgorithm.SHA1.
```python
from spdx.checksum import ChecksumAlgorithm
from spdx.checksum import Checksum
new_checksum = Checksum(identifier=ChecksumAlgorithm.SHA1, value="85ed0817af83a24ad8da68c2b5094de69833983c")
```
--------------------------------
### Assign FileType to File Object
Source: https://github.com/spdx/tools-python/wiki/How-to-migrate-from-0.6.1-to-0.7.0
Shows the updated method for assigning file types to a File object. File types should now be represented using the FileType enum, for example, FileType.OTHER.
```python
from spdx.file import File
from spdx.file import FileType
file = File('./some/path/tofile')
file.spdx_id = 'SPDXRef-File'
file.file_types = [FileType.OTHER]
```
--------------------------------
### Check Code Style with Linters
Source: https://github.com/spdx/tools-python/blob/main/CONTRIBUTING.md
These commands are used to check and automatically format code according to project standards using isort, black, and flake8. isort and black handle import sorting and code formatting, while flake8 checks for style guide violations.
```sh
# run the following commands in the repo root
isort src tests
black src tests
flake8 src tests
```
--------------------------------
### SPDX YAML Serialization
Source: https://github.com/spdx/tools-python/blob/main/DOCUMENTATION.md
Serializes an SPDX document to YAML format. Similar to JSON and XML, it starts by creating a dictionary representation of the document's tree structure and then uses the yaml package for serialization. Validation is enabled by default.
```python
from spdx_tools.spdx.writer.yaml.yaml_writer import write_yaml
# Example usage:
# write_yaml(spdx_document, output_file, validate=True, drop_duplicates=True)
```
--------------------------------
### Python: Parse, Modify, Validate, and Write SPDX Document
Source: https://github.com/spdx/tools-python/blob/main/README.md
This example demonstrates how to read an SPDX document from a file, modify its properties, add new files and relationships, validate the document, and log any validation messages. It highlights the recommended way to update lists to ensure type checking.
```Python
import logging
from license_expression import get_spdx_licensing
from spdx_tools.spdx.model import (
Checksum,
ChecksumAlgorithm,
File,
FileType,
Relationship,
RelationshipType,
)
from spdx_tools.spdx.parser.parse_anything import parse_file
from spdx_tools.spdx.validation.document_validator import validate_full_spdx_document
from spdx_tools.spdx.writer.write_anything import write_file
# read in an SPDX document from a file
document = parse_file("spdx_document.json")
# change the document's name
document.creation_info.name = "new document name"
# define a file and a DESCRIBES relationship between the file and the document
checksum = Checksum(ChecksumAlgorithm.SHA1, "71c4025dd9897b364f3ebbb42c484ff43d00791c")
file = File(name="./fileName.py", spdx_id="SPDXRef-File", checksums=[checksum],
file_types=[FileType.TEXT],
license_concluded=get_spdx_licensing().parse("MIT and GPL-2.0"),
license_comment="licenseComment", copyright_text="copyrightText")
relationship = Relationship("SPDXRef-DOCUMENT", RelationshipType.DESCRIBES, "SPDXRef-File")
# add the file and the relationship to the document
# (note that we do not use "document.files.append(file)" as that would circumvent the type checking)
document.files = document.files + [file]
document.relationships = document.relationships + [relationship]
# validate the edited document and log the validation messages
# (depending on your use case, you might also want to utilize the validation_message.context)
validation_messages = validate_full_spdx_document(document)
for validation_message in validation_messages:
logging.warning(validation_message.validation_message)
# if there are no validation messages, the document is valid
```
--------------------------------
### Update File-to-Package Relationship in SPDX
Source: https://github.com/spdx/tools-python/wiki/How-to-migrate-from-0.6.1-to-0.7.0
Demonstrates the change in how files are associated with packages in the SPDX data model. Previously, files were added directly to a package. Now, files are added at the document level, and a 'CONTAINS' relationship is explicitly created between the package and the file.
```python
package.add_file(file_entry)
```
```python
doc.add_file(file_entry)
relationship = Relationship(package.spdx_id + " CONTAINS " + file_entry.spdx_id)
doc.add_relationship(relationship)
```
--------------------------------
### Initialize Relationship Object in Python
Source: https://github.com/spdx/tools-python/wiki/How-to-migrate-from-0.7-to-0.8
Illustrates the constructor for the `Relationship` class, which now requires explicit parameters instead of parsing from a string.
```Python
def __init__(self, spdx_element_id: str, relationship_type: RelationshipType,
related_spdx_element_id: Union[str, SpdxNone, SpdxNoAssertion], comment: Optional[str] = None)
```
--------------------------------
### Run Project Tests
Source: https://github.com/spdx/tools-python/blob/main/CONTRIBUTING.md
This command executes all tests for the project using pytest with verbose output, including showing the full traceback for failures.
```sh
pytest -vvs
```
--------------------------------
### Generate Markdown, Refs, and RDF with Spec-Parser
Source: https://github.com/spdx/tools-python/blob/main/src/spdx_tools/spdx3/writer/json_ld/process.md
This command generates Markdown documentation, references, and RDF files from the SPDX-3 model using the spec-parser tool. It requires the spdx-3-model and spec-parser to be in specific states.
```shell
spec-parser --gen-md --gen-refs --gen-rdf ../spdx-3-model/model
```
--------------------------------
### Parse SPDX License Expressions in Python
Source: https://github.com/spdx/tools-python/wiki/How-to-migrate-from-0.7-to-0.8
Shows how to parse SPDX license expressions using the `license-expression` package. It contrasts the new method with the previous approach.
```Python
get_spdx_licensing().parse("Apache-2.0 and BSD-2-Clause")
```
--------------------------------
### Update Document Annotations in Python
Source: https://github.com/spdx/tools-python/wiki/How-to-migrate-from-0.7-to-0.8
Demonstrates the updated method for adding annotations to an SPDX document. The new approach involves direct property assignment rather than using an `add_annotation` method.
```Python
document.annotations = document.annotations + [my_annotation]
```
--------------------------------
### SPDX 2 to SPDX 3 Conversion
Source: https://github.com/spdx/tools-python/blob/main/DOCUMENTATION.md
The `bump_from_spdx2` package handles the conversion of SPDX-2 documents to the SPDX-3 model, following migration guidelines. This is a key component for updating older SPDX documents.
```python
from spdx_tools.spdx3.bump_from_spdx2.converter import bump_from_spdx2
# Example usage:
# spdx3_document = bump_from_spdx2(spdx2_document)
```
--------------------------------
### Deserializing JSON, YAML, and XML to Dictionaries
Source: https://github.com/spdx/tools-python/blob/main/DOCUMENTATION.md
This snippet outlines the initial step for parsing JSON, YAML, and XML formats, where each is deserialized into a dictionary representing its tree structure. This is achieved using the `json`, `yaml`, and `xmltodict` packages, respectively. The logic for translating these dictionaries into the internal data model resides in the `jsonlikedict` package.
```python
# Example for JSON parsing (conceptual)
# import json
# json_data = '{"spdxVersion": "SPDX-2.3"}'
# data_dict = json.loads(json_data)
# print(data_dict)
# Example for YAML parsing (conceptual)
# import yaml
# yaml_data = "spdxVersion: SPDX-2.3"
# data_dict = yaml.safe_load(yaml_data)
# print(data_dict)
# Example for XML parsing (conceptual)
# import xmltodict
# xml_data = 'SPDX-2.3'
# data_dict = xmltodict.parse(xml_data)
# print(data_dict)
```
--------------------------------
### Convert SPDX files with pyspdxtools
Source: https://github.com/spdx/tools-python/blob/main/README.md
Converts SPDX documents from one format to another using the pyspdxtools CLI. Input and output formats are inferred from file extensions. Validation can be skipped with the --novalidation flag.
```bash
pyspdxtools -i -o
pyspdxtools -i tests/data/SPDXJSONExample-v2.3.spdx.json -o output.tag
pyspdxtools -i tests/data/SPDXJSONExample-v2.3.spdx.json -o output.tag --novalidation
```
--------------------------------
### Push Branch to Fork
Source: https://github.com/spdx/tools-python/blob/main/CONTRIBUTING.md
This command pushes the current local branch with its commits to the remote repository on GitHub, making the changes available for review.
```sh
git push origin fix-or-improve-something
```
--------------------------------
### Write SPDX Documents in JSON, YAML, XML using Python
Source: https://github.com/spdx/tools-python/wiki/Additional-format-support-for-the-Python-Libraries,-Google-Summer-of-Code-2019
This snippet illustrates writing SPDX documents from library models into JSON, YAML, and XML formats using Python. It utilizes format-specific libraries to serialize the unified data structure into the desired output file formats.
```Python
import json
import yaml
import xmltodict
# Assume 'spdx_library_models' holds the unified SPDX data
# spdx_library_models = ...
# Example for JSON writing
with open('output_spdx.json', 'w') as f:
json.dump(spdx_library_models, f, indent=2)
# Example for YAML writing
with open('output_spdx.yaml', 'w') as f:
yaml.dump(spdx_library_models, f, default_flow_style=False)
# Example for XML writing
# Note: xmltodict.unparse requires a dictionary structure
# spdx_xml_dict = ... # Convert library models to dict suitable for XML
# with open('output_spdx.xml', 'w') as f:
# f.write(xmltodict.unparse(spdx_xml_dict))
```
--------------------------------
### Deserializing RDF Graphs with rdflib
Source: https://github.com/spdx/tools-python/blob/main/DOCUMENTATION.md
This describes the process of deserializing RDF graphs from XML format using the `rdflib` library. The parsed RDF graph is then translated into the internal data model of the spdx-tools-python project.
```python
# Example using rdflib for RDF parsing (conceptual)
# from rdflib import Graph
# g = Graph()
# g.parse("spdx_document.rdf", format="xml")
# # Logic to translate rdflib graph to internal model
# for subj, pred, obj in g:
# print(f"Triple: {subj} {pred} {obj}")
```
--------------------------------
### Convert SPDX v2 to SPDX v3 Document (Python)
Source: https://github.com/spdx/tools-python/blob/main/README.md
Explains the process of converting an SPDX v2 document to the SPDX v3 format using the `bump_from_spdx2` module. The function `bump_spdx_document` returns a payload containing the converted `SpdxDocument` and its constituent elements.
```python
from spdx_tools.spdx3.bump_from_spdx2 import spdx_document
payload = spdx_document(v2_document_object)
```
--------------------------------
### SPDX RDF Serialization
Source: https://github.com/spdx/tools-python/blob/main/DOCUMENTATION.md
Constructs an RDF graph from the internal data model and serializes it to XML format using the rdflib library. This writer also performs validation by default.
```python
from spdx_tools.spdx.writer.rdf.rdf_writer import write_rdf
# Example usage:
# write_rdf(spdx_document, output_file, validate=True, drop_duplicates=True)
```
--------------------------------
### Integrate License Expression Library in Python
Source: https://github.com/spdx/tools-python/wiki/Additional-format-support-for-the-Python-Libraries,-Google-Summer-of-Code-2019
This snippet shows the integration of the `license-expression` library in Python to support complex license expressions within SPDX documents. It addresses the limitation of handling only single operators by enabling combinations and 'WITH' exceptions.
```Python
from license_expression import Expression, License, Or, And, With
# Example of a complex license expression string
expression_string = "(MIT AND GPL-2.0-only) OR (Apache-2.0 WITH LLVM-exception)"
# Parse the expression string
parsed_expression = Expression.parse(expression_string)
# You can then use this parsed_expression object within your SPDX document models.
# For example, to check compatibility or represent it:
print(f"Parsed expression: {parsed_expression}")
# Example of creating an expression programmatically:
expr1 = And(License("MIT"), License("GPL-2.0-only"))
expr2 = With(License("Apache-2.0"), "LLVM-exception")
combined_expression = Or(expr1, expr2)
print(f"Programmatically created expression: {combined_expression}")
```
--------------------------------
### Parse SPDX Documents with JSON, YAML, XML in Python
Source: https://github.com/spdx/tools-python/wiki/Additional-format-support-for-the-Python-Libraries,-Google-Summer-of-Code-2019
This snippet demonstrates how to parse SPDX documents from JSON, YAML, and XML formats using Python. It leverages specific libraries like `json`, `PyYAML`, and `xmltodict` to handle the different file structures before unifying them for processing.
```Python
import json
import yaml
import xmltodict
# Example for JSON parsing
with open('spdx_document.json', 'r') as f:
spdx_data_json = json.load(f)
# Example for YAML parsing
with open('spdx_document.yaml', 'r') as f:
spdx_data_yaml = yaml.safe_load(f)
# Example for XML parsing
with open('spdx_document.xml', 'r') as f:
spdx_data_xml = f.read()
spdx_data_xml_dict = xmltodict.parse(spdx_data_xml)
# Further processing would involve unifying these structures into library models.
```
--------------------------------
### Generate SPDX document graph with pyspdxtools
Source: https://github.com/spdx/tools-python/blob/main/README.md
Generates a visual graph representation of an SPDX document's structure using the pyspdxtools CLI. Requires optional dependencies 'networkx' and 'pygraphviz'.
```bash
pyspdxtools -i --graph -o
pyspdxtools -i tests/data/SPDXJSONExample-v2.3.spdx.json --graph -o SPDXJSONExample-v2.3.spdx.png
```
--------------------------------
### Parsing SPDX Licenses with license-expression
Source: https://github.com/spdx/tools-python/blob/main/DOCUMENTATION.md
This snippet demonstrates how to parse SPDX license expressions using the 'license-expression' library. The `get_spdx_licensing()` function from the `spdx_licensing` module in the `common` package is used for this purpose. It's important to note that calling `get_spdx_licensing()` can be time-consuming, so its return value should be reused.
```python
from spdx_tools.common.spdx_licensing import get_spdx_licensing
license_string = "MIT"
license_expression_parser = get_spdx_licensing()
parsed_license = license_expression_parser.parse(license_string)
print(parsed_license)
```
--------------------------------
### Serialize Payload to Console Output (Python)
Source: https://github.com/spdx/tools-python/blob/main/README.md
Demonstrates serializing a Payload to the console for debugging purposes. This output is not part of the official SPDX specification and may change in the future.
```python
from spdx_tools.spdx3.writer.console import payload_writer
payload_writer.write_payload(payload)
```
--------------------------------
### Fix Travis CI Build Failure in SPDX Tools Python
Source: https://github.com/spdx/tools-python/wiki/Update-Python-SPDX-library-to-SPDX-2.1,-Google-Summer-of-Code-2018
Addresses a build failure in Travis CI, Appveyor, and CircleCI by ensuring files are opened in text mode for string operations, as Python 3 handles bytes differently than strings when reading/writing to binary streams. This change is crucial for correct file handling in the SPDX tools.
```Python
def fix_build_failure():
# Files need to be opened in text mode for str related operations
# Example: with open('file.txt', 'r') as f:
pass
```
--------------------------------
### SPDX XML Serialization
Source: https://github.com/spdx/tools-python/blob/main/DOCUMENTATION.md
Serializes an SPDX document to XML format using the xmltodict package. The process involves generating a dictionary representation of the document's tree structure, similar to JSON and YAML serialization. Validation is enabled by default.
```python
from spdx_tools.spdx.writer.xml.xml_writer import write_xml
# Example usage:
# write_xml(spdx_document, output_file, validate=True, drop_duplicates=True)
```
--------------------------------
### Generate JSON-LD from SPDX Test File with Context
Source: https://github.com/spdx/tools-python/blob/main/src/spdx_tools/spdx3/writer/json_ld/process.md
This command uses the pyspdxtools3 tool to generate a JSON-LD serialization from an input SPDX JSON file, incorporating context information. The output is saved to a specified directory.
```shell
pyspdxtools3 -i ./tests/spdx/data/SPDXJSONExample-v2.3.spdx.json -o example_with_context
```
--------------------------------
### Parse and Validate SPDX files with pyspdxtools
Source: https://github.com/spdx/tools-python/blob/main/README.md
Parses and validates SPDX documents using the pyspdxtools command-line interface. The input format is automatically detected from the file extension.
```bash
pyspdxtools -i
pyspdxtools -i tests/data/SPDXJSONExample-v2.3.spdx.json
```
--------------------------------
### Type Checking with beartype and custom dataclasses
Source: https://github.com/spdx/tools-python/blob/main/DOCUMENTATION.md
This code illustrates the use of a custom `@dataclass_with_properties` decorator, which extends the standard `@dataclass` functionality by implementing fields as properties with getters and setters. The `beartype` library is used for type checking, raising a `TypeError` upon type mismatches. Each class includes a custom `__init__()` that calls `check_types_and_set_values()` to catch and report all type errors during object construction.
```python
from beartype.roar import ConstructorTypeErrors
from spdx_tools.common.utils.dataclass_utils import dataclass_with_properties
@dataclass_with_properties
class MySpdxObject:
name: str
version: int
def __init__(self, **kwargs):
# Custom init to call type checking
pass # Placeholder for actual implementation
try:
obj = MySpdxObject(name="Example", version="invalid_type")
except ConstructorTypeErrors as e:
print(f"Type errors found: {e}")
```
--------------------------------
### SPDX JSON Serialization
Source: https://github.com/spdx/tools-python/blob/main/DOCUMENTATION.md
Serializes an SPDX document to JSON format. It first generates a dictionary representation of the document's tree structure using DocumentConverter and then serializes it using the json package. Validation is enabled by default.
```python
from spdx_tools.spdx.writer.json.json_writer import write_json
# Example usage:
# write_json(spdx_document, output_file, validate=True, drop_duplicates=True)
```
--------------------------------
### SPDX License Expression Validation
Source: https://github.com/spdx/tools-python/blob/main/DOCUMENTATION.md
Utilizes the license-expression library's `validate` and `parse` functions to check license symbols against the SPDX license list. This is part of the broader SPDX validation process.
```python
from license_expression import validate, parse
# Example usage:
# is_valid = validate('MIT AND Apache-2.0')
# parsed_expression = parse('MIT OR GPL-2.0-only')
```
--------------------------------
### Parsing Tag-Value SPDX format with PLY
Source: https://github.com/spdx/tools-python/blob/main/DOCUMENTATION.md
This section describes the implementation of a custom deserialization code for the SPDX Tag-Value format using the `ply` library. It leverages `lex` for lexing and `yacc` for parsing to handle the SPDX-specific format, as no readily available parsers exist.
```python
# Example using PLY for Tag-Value parsing (conceptual)
# from ply import lex, yacc
# Define tokens
# tokens = ('KEY', 'VALUE')
# ... lexer and parser rules ...
# parser = yacc.yacc()
# data = "SPDXVersion: SPDX-2.3\nDataLicense: CC0-1.0\n"
# result = parser.parse(data)
# print(result)
```
--------------------------------
### Serialize SPDX Document without Validation (Python)
Source: https://github.com/spdx/tools-python/blob/main/README.md
Demonstrates how to serialize an SPDX document to a file in RDF format without performing validation. This is useful when the document is already known to be valid.
```python
if not validation_messages:
write_file(document, "new_spdx_document.rdf", validate=False)
```
--------------------------------
### Serialize Payload to JSON-LD (Python)
Source: https://github.com/spdx/tools-python/blob/main/README.md
Shows how to serialize a collection of SPDX Elements, organized in a Payload, into a JSON-LD file. This is one of the supported serialization formats for SPDX 3.0.
```python
from spdx_tools.spdx3.writer.json_ld import json_ld_writer
json_ld_writer.write_payload(payload, "output.jsonld")
```
--------------------------------
### Convert SPDX OWL to JSON-LD Context using Python
Source: https://github.com/spdx/tools-python/blob/main/src/spdx_tools/spdx3/writer/json_ld/process.md
This Python function converts an SPDX OWL file into a JSON-LD context file. It is a crucial step in preparing the serialization format for SPDX data.
```python
convert_spdx_owl_to_jsonld_context("SPDX_OWL.json")
```
--------------------------------
### Commit Changes with Sign-off
Source: https://github.com/spdx/tools-python/blob/main/CONTRIBUTING.md
This command commits staged changes with a sign-off, indicating that the contribution is licensed under the terms of the Developer Certificate of Origin.
```sh
git commit --signoff -m 'description of my changes'
```
--------------------------------
### SPDX Tag-Value Serialization
Source: https://github.com/spdx/tools-python/blob/main/DOCUMENTATION.md
Serializes an SPDX document into the tag-value format, following the official specification's ordering. It writes only non-null fields and includes validation by default, which can be disabled.
```python
from spdx_tools.spdx.writer.tag_value.tag_value_writer import write_tag_value
# Example usage:
# write_tag_value(spdx_document, output_file, validate=True, drop_duplicates=True)
```
--------------------------------
### Upgrade Document Class to SPDX 2.1 Specification
Source: https://github.com/spdx/tools-python/wiki/Update-Python-SPDX-library-to-SPDX-2.1,-Google-Summer-of-Code-2018
Enhances the 'Document' class to fully support the SPDX 2.1 specification. This includes adding attributes for 'SPDX Identifier', 'Document Name', 'SPDX Document Namespace', and 'External Document References', providing more comprehensive metadata for SPDX documents.
```Python
class Document:
def __init__(self):
self.spdx_identifier = None
self.document_name = None
self.spdx_document_namespace = None
self.external_document_references = []
# ... other methods and attributes
```
--------------------------------
### SPDX Document Validation
Source: https://github.com/spdx/tools-python/blob/main/DOCUMENTATION.md
Validates an SPDX document against specification nonconformities, focusing on string formatting and SPDXID existence. It supports SPDX versions 2.2 and 2.3, with validation logic differing slightly between them. The main validator calls subvalidators for document components.
```python
from spdx_tools.spdx.validation.document_validator import validate_full_spdx_document
# Example usage:
# validation_messages = validate_full_spdx_document(spdx_document, spdx_version='SPDX-2.3')
# if not validation_messages:
# print('Document is valid')
# else:
# for msg in validation_messages:
# print(f"Validation Error: {msg.validation_message} in context: {msg.validation_context}")
```
--------------------------------
### Add Annotation Class for SPDX 2.1 Specification
Source: https://github.com/spdx/tools-python/wiki/Update-Python-SPDX-library-to-SPDX-2.1,-Google-Summer-of-Code-2018
Introduces the 'Annotation' class as part of the SPDX 2.1 specification. This class supports key attributes such as 'Annotator', 'Annotation Date', 'Annotation Type', 'SPDX Identifier Reference', and 'Annotation Comment', allowing for detailed annotation of SPDX information.
```Python
class Annotation:
def __init__(self):
self.annotator = None
self.annotation_date = None
self.annotation_type = None
self.spdx_identifier_reference = None
self.annotation_comment = None
# ... other methods and attributes
```
--------------------------------
### Clean up Local Branches
Source: https://github.com/spdx/tools-python/blob/main/CONTRIBUTING.md
This sequence of commands switches to the master branch, pulls the latest changes, lists all branches, and then deletes the local feature branch after it has been merged or is no longer needed.
```sh
git checkout master
git pull -p
git branch -a
git branch -d fix-or-improve-something
```
--------------------------------
### Upgrade Package Class to SPDX 2.1 Specification
Source: https://github.com/spdx/tools-python/wiki/Update-Python-SPDX-library-to-SPDX-2.1,-Google-Summer-of-Code-2018
Upgrades the 'Package' class to conform to the SPDX 2.1 specification. New attributes added include 'Package SPDX Identifier', 'Files Analyzed', 'Package Comment', 'External Reference', and 'External Reference Comment', enhancing the detail and accuracy of package information.
```Python
class Package:
def __init__(self):
self.package_spdx_identifier = None
self.files_analyzed = None
self.package_comment = None
self.external_reference = None
self.external_reference_comment = None
# ... other methods and attributes
```
--------------------------------
### Add Snippet Class for SPDX 2.1 Specification
Source: https://github.com/spdx/tools-python/wiki/Update-Python-SPDX-library-to-SPDX-2.1,-Google-Summer-of-Code-2018
Implements the 'Snippet' class to align with the SPDX 2.1 specification. This class includes support for various snippet-related attributes like 'Snippet SPDX Identifier', 'Snippet from File SPDX Identifier', 'Snippet Concluded License', 'License Information in Snippet', 'Snippet Comments on License', 'Snippet Copyright Text', 'Snippet Comments', 'Snippet Name', 'Snippet Byte Range', and 'Snippet File Range'.
```Python
class Snippet:
def __init__(self):
self.snippet_spdx_identifier = None
self.snippet_from_file_spdx_identifier = None
self.snippet_concluded_license = None
self.license_information_in_snippet = None
self.snippet_comments_on_license = None
self.snippet_copyright_text = None
self.snippet_comments = None
self.snippet_name = None
self.snippet_byte_range = None
self.snippet_file_range = None
# ... other methods and attributes
```
--------------------------------
### Upgrade File Class to SPDX 2.1 Specification
Source: https://github.com/spdx/tools-python/wiki/Update-Python-SPDX-library-to-SPDX-2.1,-Google-Summer-of-Code-2018
Updates the 'File' class to comply with the SPDX 2.1 specification. The primary addition is support for the 'File SPDX Identifier', enabling unique identification of files within an SPDX document.
```Python
class File:
def __init__(self):
self.file_spdx_identifier = None
# ... other methods and attributes
```
--------------------------------
### Report UNKNOWN_TAG Errors Correctly in SPDX Tools Python
Source: https://github.com/spdx/tools-python/wiki/Update-Python-SPDX-library-to-SPDX-2.1,-Google-Summer-of-Code-2018
Rectifies an error in the `p_unknown_tag` method within `parsers/tagvalue.py`. The fix involves correcting the context-free grammar specification to ensure that lines following an `UNKNOWN_TAG` are properly processed, improving error reporting accuracy.
```Python
def p_unknown_tag(p):
# Original incorrect grammar specification might have caused issues
# Corrected grammar specification ensures proper line processing
pass
```
--------------------------------
### Return Messages Instead of Modifying Lists in SPDX Tools Python
Source: https://github.com/spdx/tools-python/wiki/Update-Python-SPDX-library-to-SPDX-2.1,-Google-Summer-of-Code-2018
Refactors validation functions to return new lists with modifications instead of altering lists in place. This promotes side-effect-free functions, reducing the likelihood of complex and hard-to-debug issues often associated with in-place modifications.
```Python
def validation_function(data):
# Instead of modifying data in place:
# modified_data = data[:]
# modified_data.append(new_element)
# return modified_data
pass
```
--------------------------------
### Report Correct Line Numbers for Errors in SPDX Tools Python
Source: https://github.com/spdx/tools-python/wiki/Update-Python-SPDX-library-to-SPDX-2.1,-Google-Summer-of-Code-2018
Resolves an issue with reporting incorrect line numbers in error messages, stemming from the `t_text_end` method in `lexers\tagvalue.py`. The fix ensures newline characters are counted before stripping whitespace and newlines, preserving essential line information.
```Python
def t_text_end(t):
# Original issue: t.value.count('\n') might not detect newlines correctly after stripping
# Resolved by counting newlines first, then stripping whitespace
pass
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.