mirror of
https://github.com/macports/upt-macports.git
synced 2026-07-13 03:18:43 -07:00
Add support for license conversion and Include tests
This commit is contained in:
@@ -2,4 +2,5 @@ include CHANGELOG
|
||||
include LICENSE
|
||||
include README.md
|
||||
include tox.ini
|
||||
include upt_macports/spdx2macports.json
|
||||
include upt_macports/templates/*
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"0BSD": "BSD",
|
||||
"AFL-2.1": "AFL-2.1",
|
||||
"AFL-3.0": "AFL-3",
|
||||
"AGPL-1.0": "GPL-1",
|
||||
"AGPL-1.0-only": "GPL-1",
|
||||
"AGPL-1.0-or-later": "GPL-1",
|
||||
"AGPL-3.0": "AGPL-3",
|
||||
"AGPL-3.0-only": "AGPL-3",
|
||||
"AGPL-3.0-or-later": "AGPL-3+",
|
||||
"AMPAS": "AMPAS",
|
||||
"APSL-1.0": "APSL",
|
||||
"APSL-1.1": "APSL-1.1",
|
||||
"APSL-1.2": "APSL-1.2",
|
||||
"APSL-2.0": "APSL-2",
|
||||
"Apache-1.0": "Apache",
|
||||
"Apache-1.1": "Apache-1.1",
|
||||
"Apache-2.0": "Apache-2.0",
|
||||
"Artistic-1.0": "Artistic-1",
|
||||
"Artistic-1.0-Perl": "Artistic-1",
|
||||
"Artistic-1.0-cl8": "Artistic-1",
|
||||
"Artistic-2.0": "Artistic-2.0",
|
||||
"BSD-1-Clause": "BSD",
|
||||
"BSD-2-Clause": "BSD",
|
||||
"BSD-2-Clause-FreeBSD": "BSD",
|
||||
"BSD-2-Clause-NetBSD": "BSD",
|
||||
"BSD-2-Clause-Patent": "BSD",
|
||||
"BSD-3-Clause": "BSD",
|
||||
"BSD-3-Clause-Attribution": "BSD",
|
||||
"BSD-3-Clause-Clear": "BSD",
|
||||
"BSD-3-Clause-LBNL": "BSD",
|
||||
"BSD-3-Clause-No-Nuclear-License": "BSD",
|
||||
"BSD-3-Clause-No-Nuclear-License-2014": "BSD",
|
||||
"BSD-3-Clause-No-Nuclear-Warranty": "BSD",
|
||||
"BSD-4-Clause": "BSD",
|
||||
"BSD-4-Clause-UC": "BSD",
|
||||
"BSD-Protection": "BSD",
|
||||
"BSD-Source-Code": "BSD",
|
||||
"Beerware": "Beerware",
|
||||
"CC-BY-1.0": "CC-BY",
|
||||
"CC-BY-NC-SA-3.0": "CC-BY-NC-SA-3",
|
||||
"CC-BY-SA-1.0": "CC-BY-SA",
|
||||
"CC-BY-SA-3.0": "CC-BY-SA-3",
|
||||
"CC-BY-SA-4.0": "CC-BY-SA-4",
|
||||
"GPL-1.0": "GPL-1",
|
||||
"GPL-1.0+": "GPL-1+",
|
||||
"GPL-1.0-only": "GPL-1",
|
||||
"GPL-1.0-or-later": "GPL-1+",
|
||||
"GPL-2.0": "GPL-2",
|
||||
"GPL-2.0+": "GPL-2+",
|
||||
"GPL-2.0-only": "GPL-2",
|
||||
"GPL-2.0-or-later": "GPL-2+",
|
||||
"GPL-2.0-with-GCC-exception": "GPL-2",
|
||||
"GPL-2.0-with-autoconf-exception": "GPL-2",
|
||||
"GPL-2.0-with-bison-exception": "GPL-2",
|
||||
"GPL-2.0-with-classpath-exception": "GPL-2",
|
||||
"GPL-2.0-with-font-exception": "GPL-2",
|
||||
"GPL-3.0": "GPL-3",
|
||||
"GPL-3.0+": "GPL-3+",
|
||||
"GPL-3.0-only": "GPL-3",
|
||||
"GPL-3.0-or-later": "GPL-3+",
|
||||
"GPL-3.0-with-GCC-exception": "GPL-3",
|
||||
"GPL-3.0-with-autoconf-exception": "GPL-3",
|
||||
"LGPL-2.0": "LGPL-2",
|
||||
"LGPL-2.0+": "LGPL-2+",
|
||||
"LGPL-2.0-only": "LGPL-2",
|
||||
"LGPL-2.0-or-later": "LGPL-2+",
|
||||
"LGPL-2.1": "LGPL-2.1",
|
||||
"LGPL-2.1+": "LGPL-2.1+",
|
||||
"LGPL-2.1-only": "LGPL-2.1",
|
||||
"LGPL-2.1-or-later": "LGPL-2.1+",
|
||||
"LGPL-3.0": "LGPL-3",
|
||||
"LGPL-3.0+": "LGPL-3+",
|
||||
"LGPL-3.0-only": "LGPL-3",
|
||||
"LGPL-3.0-or-later": "LGPL-3+",
|
||||
"MIT": "MIT",
|
||||
"MIT-0": "MIT"
|
||||
}
|
||||
@@ -18,11 +18,7 @@ platforms darwin
|
||||
{% block dist_info %}
|
||||
{% endblock %}
|
||||
|
||||
{% if pkg.upt_pkg.licenses|length > 0 %}
|
||||
license {% for i in pkg.upt_pkg.licenses %}{{i.name}}{% endfor %}
|
||||
{% else %}
|
||||
license unknown
|
||||
{% endif %}
|
||||
licenses {{ pkg.licenses }}
|
||||
|
||||
checksums sha256 {{ pkg.upt_pkg.archives[0].sha256 }} \
|
||||
rmd160 {{ pkg.upt_pkg.archives[0].rmd160 }} \
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import unittest
|
||||
import upt
|
||||
from upt_macports.upt_macports import MacPortsPackage
|
||||
|
||||
|
||||
class TestMacPortsPackageLicenses(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.package = MacPortsPackage()
|
||||
self.package.upt_pkg = upt.Package('foo', '42')
|
||||
|
||||
def test_no_licenses(self):
|
||||
self.package.upt_pkg.licenses = []
|
||||
expected = ''
|
||||
self.assertEqual(self.package.licenses, expected)
|
||||
|
||||
def test_one_license(self):
|
||||
self.package.upt_pkg.licenses = [upt.licenses.BSDThreeClauseLicense()]
|
||||
expected = 'BSD'
|
||||
self.assertEqual(self.package.licenses, expected)
|
||||
|
||||
def test_bad_license(self):
|
||||
self.package.upt_pkg.licenses = [upt.licenses.UnknownLicense()]
|
||||
expected = 'unknown'
|
||||
self.assertEqual(self.package.licenses, expected)
|
||||
|
||||
def test_multiple_license(self):
|
||||
self.package.upt_pkg.licenses = [
|
||||
upt.licenses.BSDTwoClauseLicense(),
|
||||
upt.licenses.BSDThreeClauseLicense()
|
||||
]
|
||||
expected = 'BSD BSD'
|
||||
self.assertEqual(self.package.licenses, expected)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,6 +1,8 @@
|
||||
import upt
|
||||
import logging
|
||||
import jinja2
|
||||
import pkg_resources
|
||||
import json
|
||||
|
||||
|
||||
class MacPortsPackage(object):
|
||||
@@ -24,6 +26,16 @@ class MacPortsPackage(object):
|
||||
template = env.get_template(self.template)
|
||||
return template.render(pkg=self)
|
||||
|
||||
@property
|
||||
def licenses(self):
|
||||
relpath = 'spdx2macports.json'
|
||||
filepath = pkg_resources.resource_filename(__name__, relpath)
|
||||
with open(filepath) as f:
|
||||
spdx2macports = json.loads(f.read())
|
||||
|
||||
return ' '.join([spdx2macports.get(license.spdx_identifier, 'unknown')
|
||||
for license in self.upt_pkg.licenses])
|
||||
|
||||
def _depends(self, phase):
|
||||
return self.upt_pkg.requirements.get(phase, [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user