Skip to content

[issue-518] rename file_type to file_types #519

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
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ 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_type=FileType.TEXT,
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")

Expand Down
2 changes: 1 addition & 1 deletion src/spdx/jsonschema/file_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _get_property_value(self, file: Any, file_property: FileProperty, document:
elif file_property == FileProperty.FILE_NAME:
return file.name
elif file_property == FileProperty.FILE_TYPES:
return [file_type.name for file_type in file.file_type] or None
return [file_type.name for file_type in file.file_types] or None
elif file_property == FileProperty.LICENSE_COMMENTS:
return file.license_comment
elif file_property == FileProperty.LICENSE_CONCLUDED:
Expand Down
6 changes: 3 additions & 3 deletions src/spdx/model/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class File:
name: str
spdx_id: str
checksums: List[Checksum]
file_type: List[FileType] = field(default_factory=list)
file_types: List[FileType] = field(default_factory=list)
license_concluded: Optional[Union[LicenseExpression, SpdxNoAssertion, SpdxNone]] = None
license_info_in_file: Optional[Union[List[LicenseExpression], SpdxNoAssertion, SpdxNone]] = field(
default_factory=list)
Expand All @@ -55,14 +55,14 @@ class File:
# - artifact of (3 properties): replace by an external package reference and a GENERATED_FROM relationship
# between the file and this package

def __init__(self, name: str, spdx_id: str, checksums: List[Checksum], file_type: List[FileType] = None,
def __init__(self, name: str, spdx_id: str, checksums: List[Checksum], file_types: List[FileType] = None,
license_concluded: Optional[Union[LicenseExpression, SpdxNoAssertion, SpdxNone]] = None,
license_info_in_file: Optional[Union[List[LicenseExpression], SpdxNoAssertion, SpdxNone]] = None,
license_comment: Optional[str] = None,
copyright_text: Optional[Union[str, SpdxNoAssertion, SpdxNone]] = None,
comment: str = None, notice: Optional[str] = None,
contributors: List[str] = None, attribution_texts: List[str] = None):
file_type = [] if file_type is None else file_type
file_types = [] if file_types is None else file_types
license_info_in_file = [] if license_info_in_file is None else license_info_in_file
contributors = [] if contributors is None else contributors
attribution_texts = [] if attribution_texts is None else attribution_texts
Expand Down
2 changes: 1 addition & 1 deletion src/spdx/parser/jsonlikedict/file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def parse_file(self, file_dict: Dict) -> Optional[File]:

file = construct_or_raise_parsing_error(File, dict(name=name, spdx_id=spdx_id, checksums=checksums,
attribution_texts=attribution_texts, comment=comment,
copyright_text=copyright_text, file_type=file_types,
copyright_text=copyright_text, file_types=file_types,
contributors=file_contributors,
license_comment=license_comments,
license_concluded=license_concluded,
Expand Down
2 changes: 1 addition & 1 deletion src/spdx/parser/rdf/file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def parse_file(file_node: URIRef, graph: Graph, doc_namespace: str) -> File:
raise_parsing_error_if_logger_has_messages(logger, "File")
file = construct_or_raise_parsing_error(File, dict(name=name, spdx_id=spdx_id, checksums=checksums,
attribution_texts=attribution_texts, comment=comment,
copyright_text=copyright_text, file_type=file_types,
copyright_text=copyright_text, file_types=file_types,
contributors=file_contributors,
license_comment=license_comment,
license_concluded=license_concluded,
Expand Down
2 changes: 1 addition & 1 deletion src/spdx/parser/tagvalue/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def p_file_type(self, p):
except KeyError:
self.current_element["logger"].append(f"Invalid FileType: {p[2]}. Line {p.lineno(1)}")
return
self.current_element.setdefault("file_type", []).append(file_type)
self.current_element.setdefault("file_types", []).append(file_type)

@grammar_rule("file_checksum : FILE_CHECKSUM CHECKSUM")
def p_file_checksum(self, p):
Expand Down
2 changes: 1 addition & 1 deletion src/spdx/writer/rdf/file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def add_file_to_graph(file: File, graph: Graph, doc_namespace: str,
file_resource = URIRef(add_namespace_to_spdx_id(file.spdx_id, doc_namespace, external_doc_ref_to_namespace))
graph.add((file_resource, RDF.type, SPDX_NAMESPACE.File))
graph.add((file_resource, SPDX_NAMESPACE.fileName, Literal(file.name)))
for file_type in file.file_type:
for file_type in file.file_types:
graph.add((file_resource, SPDX_NAMESPACE.fileType,
SPDX_NAMESPACE[f"fileType_{snake_case_to_camel_case(file_type.name)}"]))

Expand Down
2 changes: 1 addition & 1 deletion src/spdx/writer/tagvalue/file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def write_file(file: File, text_output: TextIO):
write_value("FileName", file.name, text_output)
write_value("SPDXID", file.spdx_id, text_output)

for file_type in file.file_type:
for file_type in file.file_types:
write_value("FileType", file_type.name, text_output)

for file_checksum in file.checksums:
Expand Down
6 changes: 3 additions & 3 deletions tests/spdx/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ def creation_info_fixture(spdx_version="SPDX-2.3", spdx_id="SPDXRef-DOCUMENT", n
external_document_refs, license_list_version, document_comment)


def file_fixture(name="./fileName.py", spdx_id="SPDXRef-File", checksums=None, file_type=None,
def file_fixture(name="./fileName.py", spdx_id="SPDXRef-File", checksums=None, file_types=None,
license_concluded=get_spdx_licensing().parse("MIT and GPL-2.0"), license_info_in_file=None,
license_comment="licenseComment", copyright_text="copyrightText", comment="fileComment",
notice="fileNotice", contributors=None, attribution_texts=None) -> File:
checksums = [checksum_fixture()] if checksums is None else checksums
file_type = [FileType.TEXT] if file_type is None else file_type
file_types = [FileType.TEXT] if file_types is None else file_types
license_info_in_file = [get_spdx_licensing().parse("MIT"),
get_spdx_licensing().parse("GPL-2.0")] if license_info_in_file is None else license_info_in_file
contributors = ["fileContributor"] if contributors is None else contributors
attribution_texts = ["fileAttributionText"] if attribution_texts is None else attribution_texts
return File(name=name, spdx_id=spdx_id, checksums=checksums, file_type=file_type,
return File(name=name, spdx_id=spdx_id, checksums=checksums, file_types=file_types,
license_concluded=license_concluded, license_info_in_file=license_info_in_file,
license_comment=license_comment, copyright_text=copyright_text, comment=comment, notice=notice,
contributors=contributors, attribution_texts=attribution_texts)
Expand Down
4 changes: 2 additions & 2 deletions tests/spdx/jsonschema/test_file_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_successful_conversion(converter: FileConverter):
converter.annotation_converter.convert.return_value = "mock_converted_annotation"
file = File(name="name", spdx_id="spdxId",
checksums=[Checksum(ChecksumAlgorithm.SHA224, "sha224"), Checksum(ChecksumAlgorithm.MD2, "md2")],
file_type=[FileType.SPDX, FileType.OTHER], license_concluded=Licensing().parse("MIT and GPL-2.0"),
file_types=[FileType.SPDX, FileType.OTHER], license_concluded=Licensing().parse("MIT and GPL-2.0"),
license_info_in_file=[Licensing().parse("MIT"), Licensing().parse("GPL-2.0")],
license_comment="licenseComment", copyright_text="copyrightText", comment="comment", notice="notice",
contributors=["contributor1", "contributor2"],
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_successful_conversion(converter: FileConverter):

def test_null_values(converter: FileConverter):
file = file_fixture(copyright_text=None, license_concluded=None, license_comment=None, comment=None, notice=None,
attribution_texts=[], checksums=[], contributors=[], file_type=[], license_info_in_file=[])
attribution_texts=[], checksums=[], contributors=[], file_types=[], license_info_in_file=[])
document = Document(creation_info_fixture(), files=[file])

converted_dict = converter.convert(file, document)
Expand Down
6 changes: 3 additions & 3 deletions tests/spdx/model/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_correct_initialization(checksum):
assert file.name == "name"
assert file.spdx_id == "id"
assert file.checksums == [checksum, checksum]
assert file.file_type == [FileType.OTHER, FileType.SPDX]
assert file.file_types == [FileType.OTHER, FileType.SPDX]
assert file.license_concluded == SpdxNone()
assert file.license_info_in_file == SpdxNoAssertion()
assert file.license_comment == "comment on license"
Expand All @@ -32,7 +32,7 @@ def test_correct_initialization_with_default_values(checksum):
assert file.name == "name"
assert file.spdx_id == "id"
assert file.checksums == [checksum, checksum]
assert file.file_type == []
assert file.file_types == []
assert file.license_concluded is None
assert file.license_info_in_file == []
assert file.license_comment is None
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_wrong_type_in_checksum():
@mock.patch('spdx.model.checksum.Checksum', autospec=True)
def test_wrong_type_in_file_type(checksum):
with pytest.raises(TypeError):
File("name", "id", [checksum], file_type=FileType.OTHER)
File("name", "id", [checksum], file_types=FileType.OTHER)


@mock.patch('spdx.model.checksum.Checksum', autospec=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/spdx/parser/jsonlikedict/test_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_parse_file():
Checksum(ChecksumAlgorithm.MD5, "624c1abb3664f4b35547e7c73864ad24")])
assert file.comment == "The concluded license was taken from the package level that the file was included in.\nThis information was found in the COPYING.txt file in the xyz directory."
assert file.copyright_text == "Copyright 2008-2010 John Smith"
assert file.file_type == [FileType.SOURCE]
assert file.file_types == [FileType.SOURCE]
TestCase().assertCountEqual(file.contributors, ["The Regents of the University of California",
"Modified by Paul Mundt lethal@linux-sh.org", "IBM Corporation"])
assert file.license_concluded == Licensing().parse("(LGPL-2.0-only OR LicenseRef-2)")
Expand Down
2 changes: 1 addition & 1 deletion tests/spdx/parser/rdf/test_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_parse_file():
assert file.name == "./fileName.py"
assert file.spdx_id == "SPDXRef-File"
assert file.checksums == [Checksum(ChecksumAlgorithm.SHA1, "71c4025dd9897b364f3ebbb42c484ff43d00791c")]
assert file.file_type == [FileType.TEXT]
assert file.file_types == [FileType.TEXT]
assert file.comment == "fileComment"
assert file.copyright_text == "copyrightText"
assert file.contributors == ["fileContributor"]
Expand Down
2 changes: 1 addition & 1 deletion tests/spdx/parser/tagvalue/test_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_parse_file():
spdx_file = document.files[0]
assert spdx_file.name == "testfile.java"
assert spdx_file.spdx_id == "SPDXRef-File"
assert spdx_file.file_type == [FileType.SOURCE, FileType.TEXT]
assert spdx_file.file_types == [FileType.SOURCE, FileType.TEXT]
assert spdx_file.comment == "Very long file"
assert spdx_file.attribution_texts == [
"Acknowledgements that might be required to be communicated in some contexts."]
Expand Down