pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools/url2pkg/files pkgtools/url2pkg: move license ...
details: https://anonhg.NetBSD.org/pkgsrc/rev/16a1878cfaed
branches: trunk
changeset: 416560:16a1878cfaed
user: rillig <rillig%pkgsrc.org@localhost>
date: Sun Oct 27 13:15:04 2019 +0000
description:
pkgtools/url2pkg: move license handling from Python to common code
This way, the code is shared between Python modules, Perl modules, and
maybe in the future R packages.
No functional change.
diffstat:
pkgtools/url2pkg/files/setuptools.py | 38 +++++++-------------
pkgtools/url2pkg/files/url2pkg.py | 61 ++++++++++++++++++++++++++++++---
pkgtools/url2pkg/files/url2pkg_test.py | 22 ++++++++++--
3 files changed, 86 insertions(+), 35 deletions(-)
diffs (222 lines):
diff -r 86537656df7e -r 16a1878cfaed pkgtools/url2pkg/files/setuptools.py
--- a/pkgtools/url2pkg/files/setuptools.py Sun Oct 27 13:05:46 2019 +0000
+++ b/pkgtools/url2pkg/files/setuptools.py Sun Oct 27 13:15:04 2019 +0000
@@ -1,28 +1,13 @@
-# $NetBSD: setuptools.py,v 1.5 2019/10/05 22:02:32 rillig Exp $
+# $NetBSD: setuptools.py,v 1.6 2019/10/27 13:15:04 rillig Exp $
# This is a drop-in replacement for the setuptools Python module. Instead
# of actually searching for the dependencies, it extracts the dependency
# information and includes it in the generated pkgsrc package Makefile.
-url2pkg_license_mapping = {
- 'Apache 2': 'apache-2.0',
- 'Apache 2.0': 'apache-2.0',
- 'Apache Software License': '', # too unspecific; needs a version number
- 'BSD': '', # too unspecific
- 'GNU Lesser General Public License (LGPL), Version 3': 'gnu-lgpl-v3',
- 'LGPL': 'gnu-lgpl-v2',
- 'MIT': 'mit',
- 'MIT License': 'mit',
- 'PSF': 'python-software-foundation',
- 'PSF license': 'python-software-foundation',
- 'Python Software Foundation License': 'python-software-foundation',
- 'ZPL 2.1': 'zpl-2.1',
-}
-
-def url2pkg_print_depends(keyword, depends):
+def url2pkg_print_depends(varname, depends):
for dep in depends:
- print('%s\t%s%s' % (keyword, dep.replace(' ', ''), '' if '>' in dep else '>=0'))
+ print('%s\t%s%s' % (varname, dep.replace(' ', ''), '' if '>' in dep else '>=0'))
def url2pkg_print_var(varname, value):
@@ -30,14 +15,17 @@
print('var\t%s\t%s' % (varname, value))
-def url2pkg_print_license(license):
- if license == '':
+def url2pkg_print_cmd(cmd, arg):
+ print('\t'.join(('cmd', cmd, arg)))
+
+
+def url2pkg_print_license(license_name):
+ if license_name == '':
return
- pkgsrc_license = url2pkg_license_mapping.get(license, '')
- if pkgsrc_license == '':
- url2pkg_print_var('#LICENSE', '%s # TODO: from setup.py; needs to be adjusted' % license)
- else:
- url2pkg_print_var('LICENSE', pkgsrc_license)
+ url2pkg_print_cmd('license', license_name)
+ url2pkg_print_cmd(
+ 'license_default',
+ '%s # TODO: from setup.py; needs to be adjusted' % license_name)
def setup(**kwargs):
diff -r 86537656df7e -r 16a1878cfaed pkgtools/url2pkg/files/url2pkg.py
--- a/pkgtools/url2pkg/files/url2pkg.py Sun Oct 27 13:05:46 2019 +0000
+++ b/pkgtools/url2pkg/files/url2pkg.py Sun Oct 27 13:15:04 2019 +0000
@@ -1,5 +1,5 @@
#! @PYTHONBIN@
-# $NetBSD: url2pkg.py,v 1.22 2019/10/13 08:48:23 rillig Exp $
+# $NetBSD: url2pkg.py,v 1.23 2019/10/27 13:15:04 rillig Exp $
# Copyright (c) 2019 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -115,11 +115,32 @@
output = subprocess.check_output((self.make, 'show-var', 'VARNAME=' + varname))
return output.decode('utf-8').strip()
+ def pkgsrc_license(self, license_name: str) -> str:
+ known_licenses = (
+ ('',
+ 'Apache Software License', # too unspecific; needs a version number
+ 'BSD'), # too unspecific, may be 2-clause, 3-clause, 4-clause
+ ('${PERL5_LICENSE}', 'perl'),
+ ('apache-2.0', 'Apache 2', 'Apache 2.0'),
+ ('gnu-gpl-v3', 'GNU Lesser General Public License (LGPL), Version 3'),
+ ('gnu-lgpl-v2', 'LGPL'),
+ ('mit', 'MIT', 'MIT License'),
+ ('python-software-foundation',
+ 'PSF', 'PSF license', 'Python Software Foundation License'),
+ ('zpl-2.1', 'ZPL 2.1'),
+ )
+
+ for known_license in known_licenses:
+ if license_name in known_license:
+ return known_license[0]
+ if (self.pkgsrcdir / 'licenses' / license_name).is_file():
+ return license_name
+ return ''
class Lines:
"""
- A list of lines with high-level methods for manipulating variable
- assignments.
+ A list of Makefile lines with high-level methods for manipulating
+ variable assignments.
"""
lines: List[str]
@@ -362,7 +383,7 @@
pattern = r'''(?x)
^https://github\.com/
(.+)/ # org
- (.+)/ # proj
+ (.+)/ # proj
releases/download/
(.+)/ # tag
(.+) # base
@@ -616,6 +637,9 @@
self.g.debug('reading dependencies: cd {0} && env {1} {2}', str(cwd), env, cmd)
output: bytes = subprocess.check_output(args=cmd, shell=True, env=effective_env, cwd=cwd)
+ license_name = ''
+ license_default = ''
+
dep_lines: List[Tuple[str, str, str, str]] = []
for line in output.decode('utf-8').splitlines():
# example: DEPENDS pkgbase>=1.2.3:../../category/pkgbase
@@ -627,13 +651,27 @@
# example: var VARNAME value # possibly with comment
m = re.search(r'^var\t(\S+)\t(.+)$', line)
if m:
- if not self.makefile_lines.set(m[1], m[2]):
- self.extra_vars.append(Var(m[1], '=', m[2]))
+ self.set_or_add(m[1], m[2])
+ continue
+
+ m = re.search(r'^cmd\t(\S+)\t(.+)$', line)
+ if m:
+ cmd, arg = m.groups()
+ if cmd == 'license':
+ license_name = arg
+ elif cmd == 'license_default':
+ license_default = arg
+ else:
+ self.g.debug('unknown command: {0}', line)
continue
if line != '':
self.g.debug('unknown dependency line: {0}', line)
+ self.set_license(license_name, license_default)
+ self.add_dependencies(pkgname_prefix, dep_lines)
+
+ def add_dependencies(self, pkgname_prefix: str, dep_lines: List[Tuple[str, str, str, str]]):
for dep_line in dep_lines:
kind, pkgbase, constraint, dep_dir = dep_line
@@ -646,6 +684,17 @@
self.add_dependency(kind, pkgbase, constraint, dep_dir)
+ def set_or_add(self, varname: str, value: str):
+ if not self.makefile_lines.set(varname, value):
+ self.extra_vars.append(Var(varname, '=', value))
+
+ def set_license(self, license_name: str, license_default: str):
+ pkgsrc_license_name = self.g.pkgsrc_license(license_name)
+ if pkgsrc_license_name != '':
+ self.set_or_add('LICENSE', pkgsrc_license_name)
+ elif license_default != '':
+ self.set_or_add('#LICENSE', license_default)
+
def wrksrc_open(self, relative_pathname: str):
return (self.abs_wrksrc / relative_pathname).open()
diff -r 86537656df7e -r 16a1878cfaed pkgtools/url2pkg/files/url2pkg_test.py
--- a/pkgtools/url2pkg/files/url2pkg_test.py Sun Oct 27 13:05:46 2019 +0000
+++ b/pkgtools/url2pkg/files/url2pkg_test.py Sun Oct 27 13:15:04 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: url2pkg_test.py,v 1.21 2019/10/13 08:48:23 rillig Exp $
+# $NetBSD: url2pkg_test.py,v 1.22 2019/10/27 13:15:04 rillig Exp $
import pytest
from url2pkg import *
@@ -93,6 +93,18 @@
]
+def test_Global_pkgsrc_license():
+ assert g.pkgsrc_license('BSD') == ''
+ assert g.pkgsrc_license('apache-2.0') == 'apache-2.0'
+ assert g.pkgsrc_license('Apache 2') == 'apache-2.0'
+
+ # Not explicitly in the list, looked up from PKGSRCDIR.
+ assert g.pkgsrc_license('artistic-2.0') == 'artistic-2.0'
+
+ # Neither in the list nor in PKGSRCDIR/licenses.
+ assert g.pkgsrc_license('unknown') == ''
+
+
def test_Lines__write_and_read(tmp_path: Path):
example = tmp_path / 'example'
@@ -654,8 +666,10 @@
'A line that is not a dependency at all',
'',
'var\tHOMEPAGE\thttps://homepage.example.org/',
- 'var\t#LICENSE\tBSD # TODO: too unspecific',
- ''
+ '',
+ 'cmd\tlicense\tBSD',
+ 'cmd\tlicense_default\tBSD # (from Python package)',
+ 'cmd\tunknown-cmd\targ',
]
env = {'URL2PKG_DEPENDENCIES': '\n'.join(child_process_output)}
cmd = "printf '%s\n' \"$URL2PKG_DEPENDENCIES\""
@@ -682,7 +696,7 @@
'TEST_DEPENDS+= pkglint>=0:../../pkgtools/pkglint',
'',
'HOMEPAGE= https://homepage.example.org/',
- '#LICENSE= BSD # TODO: too unspecific',
+ '#LICENSE= BSD # (from Python package)',
'',
'BUILDLINK_API_DEPENDS.x11-links+= x11-links>=120.0',
'.include "../../pkgtools/x11-links/buildlink3.mk"'
Home |
Main Index |
Thread Index |
Old Index