Skip to content

Commit 06762b8

Browse files
committed
wip
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent fa9072e commit 06762b8

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

cyclonedx_py/_internal/utils/pep639.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
from base64 import b64encode
2525
from collections.abc import Generator
26-
from glob import glob
2726
from os.path import dirname, join
2827
from typing import TYPE_CHECKING, Any
2928

@@ -32,6 +31,7 @@
3231

3332
from .bytes import bytes2str
3433
from .mimetypes import guess_type
34+
from .py_interop import glob
3535

3636
if TYPE_CHECKING: # pragma: no cover
3737
from importlib.metadata import Distribution
@@ -54,7 +54,7 @@ def project2licenses(project: dict[str, Any], lfac: 'LicenseFactory',
5454
# https://peps.python.org/pep-0639/#add-license-files-key
5555
plfiles_root = dirname(fpath)
5656
for plfile_glob in plfiles:
57-
for plfile in glob(plfile_glob, root_dir=plfiles_root):
57+
for plfile in glob(plfile_glob, root_dir=plfiles_root, recursive=True):
5858
# per spec:
5959
# > Tools MUST assume that license file content is valid UTF-8 encoded text
6060
# anyway, we don't trust this and assume binary
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This file is part of CycloneDX Python
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
__all__ = ['glob']
19+
20+
import sys
21+
from glob import glob as _glob
22+
23+
if sys.version_info > (3, 10):
24+
glob = _glob
25+
else:
26+
from os.path import join, sep
27+
from typing import Optional
28+
29+
def glob(pathname: str, *, root_dir: Optional[str] = None, recursive: bool = False) -> list[str]:
30+
if root_dir is not None:
31+
pathname = join(root_dir, pathname)
32+
files = glob(pathname, recursive=recursive)
33+
if root_dir is not None:
34+
if not root_dir.endswith(sep):
35+
root_dir += sep
36+
files = [f.removeprefix(root_dir) for f in files]
37+
return files
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is the content of licenses_b/legal/NOTICE.txt file. it is expected to be detected.

tests/_data/infiles/environment/with-license-pep639/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ license = "MIT OR GPL-2.0-or-later OR (FSFUL AND BSD-2-Clause)"
99
# https://peps.python.org/pep-0639/#add-license-files-key
1010
license-files = [
1111
"LICEN[CS]E*", "AUTHORS*",
12-
"licenses_a/LICENSE.MIT", "licenses_a/LICENSE.CC0",
13-
"LICENSE.txt", "licenses_b/*",
12+
"licenses_a/LICENSE.MIT", "licenses_a/*.CC0",
13+
"LICENSE.txt", "licenses_b/**",
1414
"nonexisting_file", "nonexisting_dir/foo",
1515
]
1616

0 commit comments

Comments
 (0)