diff --git a/swh/indexer/data/podspec.csv b/swh/indexer/data/podspec.csv new file mode 100644 --- /dev/null +++ b/swh/indexer/data/podspec.csv @@ -0,0 +1,68 @@ +Property,Podspec +codeRepository,spec.source +programmingLanguage, +runtimePlatform, +targetProduct, +applicationCategory, +applicationSubCategory, +downloadUrl, +fileSize, +installUrl, +memoryRequirements, +operatingSystem, +permissions, +processorRequirements, +releaseNotes, +softwareHelp, +softwareRequirements, +softwareVersion, +storageRequirements, +supportingData, +author,spec.authors +citation, +contributor, +copyrightHolder, +copyrightYear, +dateCreated, +dateModified, +datePublished, +editor, +encoding, +fileFormat, +funder, +keywords, +license,spec.license +producer, +provider, +publisher, +sponsor, +version,spec.version +isAccessibleForFree, +isPartOf, +hasPart, +position, +description,spec.summary +identifier, +name,spec.name +sameAs, +url,spec.homepage +relatedLink, +givenName, +familyName, +email, +affiliation, +identifier, +name, +address, +type, +id, +softwareSuggestions, +maintainer, +contIntegration, +buildInstructions, +developmentStatus, +embargoDate, +funding, +issueTracker, +referencePublication, +readme, diff --git a/swh/indexer/metadata_dictionary/__init__.py b/swh/indexer/metadata_dictionary/__init__.py --- a/swh/indexer/metadata_dictionary/__init__.py +++ b/swh/indexer/metadata_dictionary/__init__.py @@ -8,7 +8,19 @@ import click -from . import cff, codemeta, composer, dart, github, maven, npm, nuget, python, ruby +from . import ( + cff, + codemeta, + composer, + dart, + github, + maven, + npm, + nuget, + podspec, + python, + ruby, +) from .base import BaseExtrinsicMapping, BaseIntrinsicMapping, BaseMapping INTRINSIC_MAPPINGS: Dict[str, Type[BaseIntrinsicMapping]] = { @@ -21,6 +33,7 @@ "PythonPkginfoMapping": python.PythonPkginfoMapping, "ComposerMapping": composer.ComposerMapping, "NuGetMapping": nuget.NuGetMapping, + "PodspecMapping": podspec.PodspecMapping, } EXTRINSIC_MAPPINGS: Dict[str, Type[BaseExtrinsicMapping]] = { diff --git a/swh/indexer/metadata_dictionary/podspec.py b/swh/indexer/metadata_dictionary/podspec.py new file mode 100644 --- /dev/null +++ b/swh/indexer/metadata_dictionary/podspec.py @@ -0,0 +1,24 @@ +import os.path + +from swh.indexer.codemeta import _DATA_DIR, _read_crosstable + +from .base import DictMapping, SingleFileIntrinsicMapping + +PODSPEC_TABLE_PATH = os.path.join(_DATA_DIR, "podspec.csv") + +with open(PODSPEC_TABLE_PATH) as fd: + (CODEMETA_TERMS, PODSPEC_TABLE) = _read_crosstable(fd) + + +class PodspecMapping(DictMapping, SingleFileIntrinsicMapping): + """ + dedicated class for Podspec mapping and translation + """ + + name = "podspec" + mapping = PODSPEC_TABLE["NuGet"] + string_fields = [ + "description", + "name", + "softwareVersion", + ] diff --git a/swh/indexer/tests/metadata_dictionary/test_podspec.py b/swh/indexer/tests/metadata_dictionary/test_podspec.py new file mode 100644 --- /dev/null +++ b/swh/indexer/tests/metadata_dictionary/test_podspec.py @@ -0,0 +1,49 @@ +# Copyright (C) 2022 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + + +from swh.indexer.metadata_dictionary import MAPPINGS + + +def test_compute_metadata_podspec(): + raw_content = b"""Pod::Spec.new do |spec| + spec.name = 'Reachability' + spec.version = '3.1.0' + spec.license = { :type => 'BSD' } + spec.homepage = 'https://github.com/tonymillion/Reachability' + spec.authors = { 'Tony Million' => 'tonymillion@gmail.com' } + spec.summary = 'ARC and GCD Compatible Reachability Class for iOS and OS X.' + spec.source = { :git => 'https://github.com/tonymillion/Reachability.git' } + spec.module_name = 'Rich' + spec.swift_version = '4.0' + + spec.ios.deployment_target = '9.0' + spec.osx.deployment_target = '10.10' + + spec.source_files = 'Reachability/common/*.swift' + spec.ios.source_files = 'Reachability/ios/*.swift', 'Reachability/extensions/*.swift' + spec.osx.source_files = 'Reachability/osx/*.swift' + + spec.framework = 'SystemConfiguration' + spec.ios.framework = 'UIKit' + spec.osx.framework = 'AppKit' + + spec.dependency 'SomeOtherPod' +end""" + result = MAPPINGS["PodspecMapping"]().translate(raw_content) + expected = { + "@context": "https://doi.org/10.5063/schema/codemeta-2.0", + "type": "SoftwareSourceCode", + "author": [ + {"type": "Person", "name": "Tony Million", "email": "tonymillion@gmail.com"} + ], + "description": "ARC and GCD Compatible Reachability Class for iOS and OS X.", + "url": "https://github.com/tonymillion/Reachability", + "codeRepository": "https://github.com/tonymillion/Reachability.git", + "name": "Reachability", + "softwareVersion": "3.1.0", + } + + assert result == expected diff --git a/swh/indexer/tests/test_cli.py b/swh/indexer/tests/test_cli.py --- a/swh/indexer/tests/test_cli.py +++ b/swh/indexer/tests/test_cli.py @@ -116,6 +116,7 @@ "nuget", "pkg-info", "pubspec", + "podspec", "", ] # must be sorted for test to pass )