Skip to content

Commit 5136b4d

Browse files
authored
Merge branch 'nexB:develop' into add_new_flag
2 parents e62be42 + c8cf696 commit 5136b4d

File tree

116 files changed

+1652
-6278
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+1652
-6278
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Outputs:
3131
the JSON output
3232
- Add new Debian machine readable copyright output.
3333
- The CSV output "Resource" column has been renamed to "path".
34+
- The SPDX output now has the mandatory DocumentNamespace attribut per SPDX specs #2344
3435

3536

3637
Copyright detection:
@@ -39,6 +40,11 @@ Copyright detection:
3940
- The data structure in the JSON is now using consistently named attributes as
4041
opposed to a plain value.
4142

43+
- The copyright detection speed has been significantly improved with the tests
44+
taking roughly 1/2 of the time to run. This is achieved mostly by replacing
45+
NLTK with a the minimal and simplified subset we need in a new library named
46+
pygmars.
47+
4248

4349
Package detection:
4450
~~~~~~~~~~~~~~~~~~

CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ with your name and email::
2222
Signed-off-by: Jane Doe <[email protected]>
2323

2424
Please try to write a good commit message, see `good commit message wiki
25-
<https://github.com/nexB/aboutcode/wiki/Writing-good-commit-messages>`_ for
25+
<https://aboutcode.readthedocs.io/en/latest/contributing/writing_good_commit_messages.html>` for
2626
details. In particular use the imperative for your commit subject: think that
2727
you are giving an order to the codebase to update itself.
2828

etc/release/gen_pypi_simple.py

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
# SPDX-License-Identifier: BSD-2-Clause-Views AND MIT
5+
# Copyright (c) 2010 David Wolever <[email protected]>. All rights reserved.
6+
# originally from https://github.com/wolever/pip2pi
7+
8+
import os
9+
import re
10+
import shutil
11+
12+
from html import escape
13+
from pathlib import Path
14+
15+
"""
16+
name: pip compatibility tags
17+
version: 20.3.1
18+
download_url: https://github.com/pypa/pip/blob/20.3.1/src/pip/_internal/models/wheel.py
19+
copyright: Copyright (c) 2008-2020 The pip developers (see AUTHORS.txt file)
20+
license_expression: mit
21+
notes: the weel name regex is copied from pip-20.3.1 pip/_internal/models/wheel.py
22+
23+
Copyright (c) 2008-2020 The pip developers (see AUTHORS.txt file)
24+
25+
Permission is hereby granted, free of charge, to any person obtaining
26+
a copy of this software and associated documentation files (the
27+
"Software"), to deal in the Software without restriction, including
28+
without limitation the rights to use, copy, modify, merge, publish,
29+
distribute, sublicense, and/or sell copies of the Software, and to
30+
permit persons to whom the Software is furnished to do so, subject to
31+
the following conditions:
32+
33+
The above copyright notice and this permission notice shall be
34+
included in all copies or substantial portions of the Software.
35+
36+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
37+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
38+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
39+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
40+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
41+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
42+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43+
"""
44+
get_wheel_from_filename = re.compile(
45+
r"""^(?P<namever>(?P<name>.+?)-(?P<version>.*?))
46+
((-(?P<build>\d[^-]*?))?-(?P<pyvers>.+?)-(?P<abis>.+?)-(?P<plats>.+?)
47+
\.whl)$""",
48+
re.VERBOSE
49+
).match
50+
51+
sdist_exts = ".tar.gz", ".tar.bz2", ".zip", ".tar.xz",
52+
wheel_ext = ".whl"
53+
app_ext = ".pyz"
54+
dist_exts = sdist_exts + (wheel_ext, app_ext)
55+
56+
57+
class InvalidDistributionFilename(Exception):
58+
pass
59+
60+
61+
def get_package_name_from_filename(filename, normalize=True):
62+
"""
63+
Return the package name extracted from a package ``filename``.
64+
Optionally ``normalize`` the name according to distribution name rules.
65+
Raise an ``InvalidDistributionFilename`` if the ``filename`` is invalid::
66+
67+
>>> get_package_name_from_filename("foo-1.2.3_rc1.tar.gz")
68+
'foo'
69+
>>> get_package_name_from_filename("foo-bar-1.2-py27-none-any.whl")
70+
'foo-bar'
71+
>>> get_package_name_from_filename("Cython-0.17.2-cp26-none-linux_x86_64.whl")
72+
'cython'
73+
>>> get_package_name_from_filename("python_ldap-2.4.19-cp27-none-macosx_10_10_x86_64.whl")
74+
'python-ldap'
75+
>>> get_package_name_from_filename("foo.whl")
76+
Traceback (most recent call last):
77+
...
78+
InvalidDistributionFilename: ...
79+
>>> get_package_name_from_filename("foo.png")
80+
Traceback (most recent call last):
81+
...
82+
InvalidFilePackageName: ...
83+
"""
84+
if not filename or not filename.endswith(dist_exts):
85+
raise InvalidDistributionFilename(filename)
86+
87+
filename = os.path.basename(filename)
88+
89+
if filename.endswith(sdist_exts):
90+
name_ver = None
91+
extension = None
92+
93+
for ext in sdist_exts:
94+
if filename.endswith(ext):
95+
name_ver, extension, _ = filename.rpartition(ext)
96+
break
97+
98+
if not extension or not name_ver:
99+
raise InvalidDistributionFilename(filename)
100+
101+
name, _, version = name_ver.rpartition('-')
102+
103+
if not (name and version):
104+
raise InvalidDistributionFilename(filename)
105+
106+
elif filename.endswith(wheel_ext):
107+
108+
wheel_info = get_wheel_from_filename(filename)
109+
110+
if not wheel_info:
111+
raise InvalidDistributionFilename(filename)
112+
113+
name = wheel_info.group('name')
114+
version = wheel_info.group('version')
115+
116+
if not (name and version):
117+
raise InvalidDistributionFilename(filename)
118+
119+
elif filename.endswith(app_ext):
120+
name_ver, extension, _ = filename.rpartition(".pyz")
121+
122+
if "-" in filename:
123+
name, _, version = name_ver.rpartition('-')
124+
else:
125+
name = name_ver
126+
127+
if not name:
128+
raise InvalidDistributionFilename(filename)
129+
130+
if normalize:
131+
name = name.lower().replace('_', '-')
132+
return name
133+
134+
135+
def build_pypi_index(directory, write_index=False):
136+
"""
137+
Using a ``directory`` directory of wheels and sdists, create the a PyPI simple
138+
directory index at ``directory``/simple/ populated with the proper PyPI simple
139+
index directory structure crafted using symlinks.
140+
141+
WARNING: The ``directory``/simple/ directory is removed if it exists.
142+
"""
143+
144+
directory = Path(directory)
145+
146+
index_dir = directory / "simple"
147+
if index_dir.exists():
148+
shutil.rmtree(str(index_dir), ignore_errors=True)
149+
150+
index_dir.mkdir(parents=True)
151+
152+
if write_index:
153+
simple_html_index = [
154+
"<html><head><title>PyPI Simple Index</title>",
155+
"<meta name='api-version' value='2' /></head><body>",
156+
]
157+
158+
package_names = set()
159+
for pkg_file in directory.iterdir():
160+
161+
pkg_filename = pkg_file.name
162+
163+
if (
164+
not pkg_file.is_file()
165+
or not pkg_filename.endswith(dist_exts)
166+
or pkg_filename.startswith(".")
167+
):
168+
continue
169+
170+
pkg_name = get_package_name_from_filename(pkg_filename)
171+
pkg_index_dir = index_dir / pkg_name
172+
pkg_index_dir.mkdir(parents=True, exist_ok=True)
173+
pkg_indexed_file = pkg_index_dir / pkg_filename
174+
link_target = Path("../..") / pkg_filename
175+
pkg_indexed_file.symlink_to(link_target)
176+
177+
if write_index and pkg_name not in package_names:
178+
esc_name = escape(pkg_name)
179+
simple_html_index.append(f'<a href="{esc_name}/">{esc_name}</a><br/>')
180+
package_names.add(pkg_name)
181+
182+
if write_index:
183+
simple_html_index.append("</body></html>")
184+
index_html = index_dir / "index.html"
185+
index_html.write_text("\n".join(simple_html_index))
186+
187+
188+
if __name__ == "__main__":
189+
import sys
190+
pkg_dir = sys.argv[1]
191+
build_pypi_index(pkg_dir)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
about_resource: gen_pypi_simple.py
2+
name: gen_pypi_simple.py
3+
license_expression: bsd-2-clause-views and mit
4+
copyright: Copyright (c) nexB Inc.
5+
Copyright (c) 2010 David Wolever <[email protected]>
6+
Copyright (c) The pip developers
7+
notes: Originally from https://github.com/wolever/pip2pi and modified extensivley
8+
Also partially derived from pip code
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
SPDX-License-Identifier: BSD-2-Clause-Views AND mit
2+
3+
Copyright (c) nexB Inc.
4+
Copyright (c) 2010 David Wolever <[email protected]>
5+
Copyright (c) The pip developers
6+
7+
8+
Original code: copyright 2010 David Wolever <[email protected]>. All rights reserved.
9+
10+
Redistribution and use in source and binary forms, with or without
11+
modification, are permitted provided that the following conditions are met:
12+
13+
1. Redistributions of source code must retain the above copyright notice,
14+
this list of conditions and the following disclaimer.
15+
16+
2. Redistributions in binary form must reproduce the above copyright notice,
17+
this list of conditions and the following disclaimer in the documentation
18+
and/or other materials provided with the distribution.
19+
20+
THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND ANY EXPRESS OR
21+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
23+
EVENT SHALL <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
31+
The views and conclusions contained in the software and documentation are those
32+
of the authors and should not be interpreted as representing official policies,
33+
either expressed or implied, of David Wolever.
34+
35+
36+
Original code: Copyright (c) 2008-2020 The pip developers
37+
38+
Permission is hereby granted, free of charge, to any person obtaining
39+
a copy of this software and associated documentation files (the
40+
"Software"), to deal in the Software without restriction, including
41+
without limitation the rights to use, copy, modify, merge, publish,
42+
distribute, sublicense, and/or sell copies of the Software, and to
43+
permit persons to whom the Software is furnished to do so, subject to
44+
the following conditions:
45+
46+
The above copyright notice and this permission notice shall be
47+
included in all copies or substantial portions of the Software.
48+
49+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
50+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
52+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
53+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
54+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
55+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56+

etc/release/utils_thirdparty.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ class Sdist(Distribution):
975975
@classmethod
976976
def from_filename(cls, filename):
977977
"""
978-
Return a sdist object built from a filename.
978+
Return a Sdist object built from a filename.
979979
Raise an exception if this is not a valid sdist filename
980980
"""
981981
name_ver = None
@@ -1048,12 +1048,12 @@ class Wheel(Distribution):
10481048
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10491049
"""
10501050

1051-
wheel_file_re = re.compile(
1051+
get_wheel_from_filename = re.compile(
10521052
r"""^(?P<namever>(?P<name>.+?)-(?P<ver>.*?))
10531053
((-(?P<build>\d[^-]*?))?-(?P<pyvers>.+?)-(?P<abis>.+?)-(?P<plats>.+?)
10541054
\.whl)$""",
10551055
re.VERBOSE
1056-
)
1056+
).match
10571057

10581058
build = attr.ib(
10591059
type=str,
@@ -1092,7 +1092,7 @@ def from_filename(cls, filename):
10921092
Return a wheel object built from a filename.
10931093
Raise an exception if this is not a valid wheel filename
10941094
"""
1095-
wheel_info = cls.wheel_file_re.match(filename)
1095+
wheel_info = cls.get_wheel_from_filename(filename)
10961096
if not wheel_info:
10971097
raise InvalidDistributionFilename(filename)
10981098

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cffi==1.14.5
99
chardet==4.0.0
1010
click==8.0.1
1111
colorama==0.4.4
12-
commoncode==21.5.25
12+
commoncode==21.6.11
1313
cryptography==3.4.7
1414
debian-inspector==21.5.25
1515
dparse==0.5.1
@@ -34,7 +34,6 @@ license-expression==1.2
3434
lxml==4.6.3
3535
MarkupSafe==2.0.1
3636
more-itertools==8.8.0
37-
nltk==3.4.5
3837
normality==2.2.2
3938
packageurl-python==0.9.4
4039
packaging==20.9
@@ -50,6 +49,7 @@ publicsuffix2==2.20191221
5049
pyahocorasick==1.4.2
5150
pycparser==2.20
5251
Pygments==2.9.0
52+
pygmars==0.5.0
5353
pymaven-patch==0.3.0
5454
pyparsing==2.4.7
5555
PyYAML==5.4.1

setup-mini.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ install_requires =
7676
license_expression >= 1.0
7777
lxml >= 4.6.3, < 5.0.0
7878
MarkupSafe >= 1.0
79-
nltk >= 3.2, !=3.6, < 4.0
8079
packageurl_python >= 0.9.0
8180
packaging > 20
8281
pdfminer.six >= 20200101
@@ -86,6 +85,7 @@ install_requires =
8685
plugincode >= 21.1.21
8786
publicsuffix2
8887
pyahocorasick >= 1.4.0, < 1.5
88+
pygmars
8989
pygments
9090
pymaven_patch >= 0.2.8
9191
requests >= 2.7.0, < 3.0.0
@@ -234,6 +234,6 @@ python_functions=test
234234

235235
addopts =
236236
-rfExXw
237-
--strict
237+
--strict-markers
238238
--ignore setup.py
239239
--doctest-modules

0 commit comments

Comments
 (0)