Skip to content

Commit 9dbbccd

Browse files
committed
Merge latest develop
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
2 parents 05f93c4 + 9d885d5 commit 9dbbccd

855 files changed

Lines changed: 3626 additions & 1047 deletions

File tree

Some content is hidden

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

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The following organizations or individuals have contributed to ScanCode:
4040
- Johannes Najjar @joshovi
4141
- Jose Nazario @paralax
4242
- Kevin Ji @KevinJi22
43+
- Lali Akhil Raj @lf32
4344
- Lemo Shi @lemoshi
4445
- Li Ha @linexb
4546
- Mankaran Singh @MankaranSingh

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,15 @@ Development environment and Code API changes:
324324
environment variable. There is no need to replace the regen=False with
325325
regen=True in the code.
326326

327+
Miscellaneous
328+
--------------
329+
330+
- Added support for usage of shortcut flags
331+
- `-A` or `--about`
332+
- `-q` or `--quiet`
333+
- `-v` or `--verbose`
334+
- `-V` or `--version` can be used.
335+
327336

328337
30.1.0 - 2021-09-25
329338
--------------------

docs/source/rst_snippets/core_options.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ All "Core" Scan Options
44
-n, --processes INTEGER Scan ``<input>`` using n parallel processes.
55
[Default: 1]
66

7-
--verbose Print verbose file-by-file progress messages.
7+
-v, --verbose Print verbose file-by-file progress messages.
88

9-
--quiet Do not print summary or progress messages.
9+
-q, --quiet Do not print summary or progress messages.
1010

1111
--timeout FLOAT Stop scanning a file if scanning takes longer
1212
than a timeout in seconds. [Default: 120]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ commoncode==31.0.0b4
1313
construct==2.10.68
1414
container-inspector==31.0.0
1515
cryptography==36.0.2
16-
debian-inspector==30.0.0
16+
debian-inspector==31.0.0b1
1717
dockerfile-parse==1.2.0
1818
dparse2==0.6.1
1919
extractcode==31.0.0

setup-mini.cfg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ install_requires =
7171
colorama >= 0.3.9
7272
commoncode==31.0.0b4
7373
container-inspector >= 31.0.0
74-
debian-inspector >= 30.0.0
74+
debian-inspector >= 31.0.0b1
7575
dparse2 >= 0.6.1
7676
fasteners
7777
fingerprints >= 0.6.0
@@ -112,6 +112,8 @@ install_requires =
112112
xmltodict >= 0.11.0
113113
zipp >= 3.0.0; python_version < "3.9"
114114
typecode >= 30.0.0
115+
# typecode[full] >= 30.0.0
116+
# extractcode[full] >= 31.0.0
115117

116118

117119
[options.packages.find]
@@ -128,6 +130,8 @@ testing =
128130
pytest-xdist >= 2
129131
aboutcode-toolkit >= 7.0.2
130132
twine
133+
black
134+
isort
131135

132136
docs =
133137
Sphinx >= 3.3.1

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ install_requires =
7171
colorama >= 0.3.9
7272
commoncode==31.0.0b4
7373
container-inspector >= 31.0.0
74-
debian-inspector >= 30.0.0
74+
debian-inspector >= 31.0.0b1
7575
dparse2 >= 0.6.1
7676
fasteners
7777
fingerprints >= 0.6.0

src/packagedcode/alpine.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,4 +1772,3 @@ def detect_licenses(locin, locout):
17721772
# get_apkindex_licenses(loc, 'alpine-licenses.csv')
17731773
get_apkbuild_licenses(loc, 'alpine-licenses.csv')
17741774
detect_licenses('alpine-licenses.csv', 'alpine-licenses-detection.csv')
1775-

src/packagedcode/models.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from commoncode.datautils import Mapping
2626
from commoncode.datautils import String
2727
from commoncode.fileutils import as_posixpath
28+
from commoncode.resource import Resource
2829
from typecode import contenttype
2930

3031
"""
@@ -1201,7 +1202,7 @@ def __attrs_post_init__(self, *args, **kwargs):
12011202
self.package_uid = build_package_uid(self.purl)
12021203

12031204
def to_dict(self):
1204-
return super().to_dict(with_details=False)
1205+
return super().to_dict(with_details=False)
12051206

12061207
@classmethod
12071208
def from_package_data(cls, package_data, datafile_path):
@@ -1340,6 +1341,24 @@ def get_packages_files(self, codebase):
13401341
yield resource
13411342

13421343

1344+
@attr.attributes(slots=True)
1345+
class PackageWithResources(Package):
1346+
"""
1347+
A Package with Resources.
1348+
"""
1349+
1350+
resources = List(
1351+
item_type=Resource,
1352+
label='List of Resources',
1353+
help='List of Resources for this package.',
1354+
)
1355+
1356+
def to_dict(self):
1357+
package_data = super().to_dict()
1358+
package_data['resources'] = [resource.to_dict() for resource in self.resources]
1359+
return package_data
1360+
1361+
13431362
def get_files_for_packages(codebase):
13441363
"""
13451364
Yield tuple of (Resource, package_uid) for all resources in codebase that are

src/packagedcode/plugin_package.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from packagedcode.models import Dependency
2626
from packagedcode.models import Package
2727
from packagedcode.models import PackageData
28+
from packagedcode.models import PackageWithResources
2829

2930
TRACE = os.environ.get('SCANCODE_DEBUG_PACKAGE_API', False)
3031

@@ -153,6 +154,36 @@ def process_codebase(self, codebase, strip_root=False, **kwargs):
153154
create_package_and_deps(codebase, strip_root=strip_root, **kwargs)
154155

155156

157+
def get_installed_packages(root_dir, processes=2, **kwargs):
158+
"""
159+
Yield Package and their Resources as they are found in `root_dir`
160+
"""
161+
from scancode import cli
162+
163+
_, codebase = cli.run_scan(
164+
input=root_dir,
165+
processes=processes,
166+
quiet=True,
167+
verbose=False,
168+
max_in_memory=0,
169+
return_results=False,
170+
return_codebase=True,
171+
system_package=True,
172+
)
173+
174+
packages_by_uid = {}
175+
for package in codebase.attributes.packages:
176+
p = PackageWithResources.from_dict(package)
177+
packages_by_uid[p.package_uid] = p
178+
179+
for resource in codebase.walk():
180+
for package_uid in resource.for_packages:
181+
p = packages_by_uid[package_uid]
182+
p.resources.append(resource)
183+
184+
yield from packages_by_uid.values()
185+
186+
156187
def create_package_and_deps(codebase, strip_root=False, **kwargs):
157188
"""
158189
Create and save top-level Package and Dependency from the parsed

src/packagedcode/pypi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ def get_requires_dependencies(requires, default_scope='install'):
11961196
is_runtime=True,
11971197
is_optional=False,
11981198
is_resolved=is_resolved,
1199-
extracted_requirement=requirement,
1199+
extracted_requirement=str(req),
12001200
))
12011201

12021202
return dependent_packages

0 commit comments

Comments
 (0)