Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
The Universal Packaging Tool
upt
Commits
ce447564
Commit
ce447564
authored
Feb 21, 2018
by
Cyril Roelandt
Browse files
Add support for license extraction.
parent
7e6bfa68
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
MANIFEST.in
View file @
ce447564
include CHANGELOG
include LICENSE
include README.md
include requirements.txt
include tox.ini
requirements.txt
0 → 100644
View file @
ce447564
spdx_lookup
setup.py
View file @
ce447564
...
...
@@ -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'
],
...
...
tox.ini
View file @
ce447564
...
...
@@ -2,6 +2,7 @@
envlist
=
flake8,py36
[testenv]
deps
=
-rrequirements.txt
commands
=
python -m unittest
...
...
upt/__init__.py
View file @
ce447564
# 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
...
...
upt/licenses.py
0 → 100644
View file @
ce447564
This diff is collapsed.
Click to expand it.
upt/tests/test_licenses.py
0 → 100644
View file @
ce447564
# 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
)
upt/upt.py
View file @
ce447564
...
...
@@ -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
}
'
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment