Commit ce447564 authored by Cyril Roelandt's avatar Cyril Roelandt
Browse files

Add support for license extraction.

parent 7e6bfa68
include CHANGELOG
include LICENSE
include README.md
include requirements.txt
include tox.ini
......@@ -9,6 +9,10 @@ here = path.abspath(path.dirname(__file__))
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
def _install_reqs():
with open('requirements.txt') as f:
return f.read().split('\n')
setup(
name='upt',
author='Cyril Roelandt',
......@@ -25,7 +29,7 @@ setup(
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3 :: Only',
],
install_requires = [],
install_requires = _install_reqs(),
packages = find_packages(),
entry_points = {
'console_scripts': ['upt = upt.upt:main'],
......
......@@ -2,6 +2,7 @@
envlist=flake8,py36
[testenv]
deps = -rrequirements.txt
commands = python -m unittest
......
# Copyright 2018 Cyril Roelandt
#
# Licensed under the 3-clause BSD license. See the LICENSE file.
from . import licenses
from .upt import Backend
from .upt import Frontend
from .upt import Package
......
This diff is collapsed.
# Copyright 2018 Cyril Roelandt
#
# Licensed under the 3-clause BSD license. See the LICENSE file.
import unittest
from unittest import mock
from upt import licenses
class TestLicenses(unittest.TestCase):
def test_simple_license(self):
class TestLicense(licenses.License):
pass
license = TestLicense()
self.assertFalse(license.is_osi_approved())
self.assertFalse(license.is_gpl_compatible())
def test_osi_approved_license(self):
class TestLicense(licenses.OSIApprovedLicense):
pass
license = TestLicense()
self.assertTrue(license.is_osi_approved())
self.assertFalse(license.is_gpl_compatible())
def test_gpl_compatible_license(self):
class TestLicense(licenses.GPLCompatibleLicense):
pass
license = TestLicense()
self.assertFalse(license.is_osi_approved())
self.assertTrue(license.is_gpl_compatible())
def test_dfsg_compatible_license(self):
class TestLicense(licenses.DFSGCompatibleLicense):
pass
license = TestLicense()
self.assertFalse(license.is_osi_approved())
self.assertFalse(license.is_gpl_compatible())
self.assertTrue(license.is_dfsg_compatible())
def test_osi_gpl_dfsg_license(self):
class TestLicense(licenses.DFSGCompatibleLicense,
licenses.GPLCompatibleLicense,
licenses.OSIApprovedLicense):
pass
license = TestLicense()
self.assertTrue(license.is_dfsg_compatible())
self.assertTrue(license.is_gpl_compatible())
self.assertTrue(license.is_osi_approved())
@mock.patch('spdx_lookup.match')
@mock.patch('builtins.open', new_callable=mock.mock_open, read_data='')
def test_guess_from_file(self, open_fn, match_fn):
# Invalid arguments
with self.assertRaises(ValueError):
licenses.guess_from_file('/some/path', min_confidence=-1)
with self.assertRaises(ValueError):
licenses.guess_from_file('/some/path', min_confidence=101)
# spdx_lookup cannot find anything
match_fn.return_value = None
self.assertIsInstance(licenses.guess_from_file('/some/path'),
licenses.UnknownLicense)
match = mock.Mock(confidence=50, license=mock.Mock(id='BSD-3-Clause'))
match_fn.return_value = match
self.assertIsInstance(licenses.guess_from_file('/some/path'),
licenses.UnknownLicense)
match = mock.Mock(confidence=100, license=mock.Mock(id='BSD-3-Clause'))
match_fn.return_value = match
self.assertIsInstance(licenses.guess_from_file('/some/path'),
licenses.BSDThreeClauseLicense)
......@@ -60,6 +60,7 @@ class Package(object):
- 'test': the test dependencies of the package.
The values associated with these keys are always lists of
PackageRequirement objects.
- licenses: a list of upt.licenses.License objects
"""
def __init__(self, name, version, **kwargs):
self.name = name
......@@ -74,6 +75,7 @@ class Package(object):
# 'test': [pkg3, ...]
# }
self.requirements = kwargs.get('requirements', {})
self.licenses = kwargs.get('licenses', [])
def __str__(self):
return f'{self.name}@{self.version}'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment