python-inspector 0.12.1__py3-none-any.whl → 0.14.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- _packagedcode/pypi.py +37 -25
- python_inspector/__init__.py +6 -1
- python_inspector/api.py +147 -80
- python_inspector/cli_utils.py +1 -2
- python_inspector/dependencies.py +12 -10
- python_inspector/lockfile.py +32 -0
- python_inspector/package_data.py +58 -45
- python_inspector/resolution.py +121 -110
- python_inspector/resolve_cli.py +9 -13
- python_inspector/settings.py +66 -0
- python_inspector/setup_py_live_eval.py +2 -2
- python_inspector/utils.py +33 -1
- python_inspector/utils_pip_compatibility_tags.py +4 -2
- python_inspector/utils_pip_compatibility_tags.py.ABOUT +1 -1
- python_inspector/utils_pypi.py +136 -121
- python_inspector-0.14.0.dist-info/METADATA +239 -0
- python_inspector-0.14.0.dist-info/RECORD +42 -0
- {python_inspector-0.12.1.dist-info → python_inspector-0.14.0.dist-info}/WHEEL +1 -1
- {python_inspector-0.12.1.dist-info → python_inspector-0.14.0.dist-info/licenses}/CHANGELOG.rst +52 -1
- {python_inspector-0.12.1.dist-info → python_inspector-0.14.0.dist-info/licenses}/NOTICE +2 -22
- python_inspector-0.14.0.dist-info/licenses/README.rst +179 -0
- python_inspector-0.12.1.dist-info/METADATA +0 -127
- python_inspector-0.12.1.dist-info/RECORD +0 -39
- {python_inspector-0.12.1.dist-info → python_inspector-0.14.0.dist-info}/entry_points.txt +0 -0
- {python_inspector-0.12.1.dist-info → python_inspector-0.14.0.dist-info/licenses}/AUTHORS.rst +0 -0
- {python_inspector-0.12.1.dist-info → python_inspector-0.14.0.dist-info/licenses}/CODE_OF_CONDUCT.rst +0 -0
- {python_inspector-0.12.1.dist-info → python_inspector-0.14.0.dist-info/licenses}/apache-2.0.LICENSE +0 -0
- {python_inspector-0.12.1.dist-info → python_inspector-0.14.0.dist-info}/top_level.txt +0 -0
_packagedcode/pypi.py
CHANGED
|
@@ -457,7 +457,7 @@ def parse_metadata(location, datasource_id, package_type):
|
|
|
457
457
|
name=name,
|
|
458
458
|
version=version,
|
|
459
459
|
description=get_description(metainfo=meta, location=str(location)),
|
|
460
|
-
#TODO: https://github.com/aboutcode-org/scancode-toolkit/issues/3014
|
|
460
|
+
# TODO: https://github.com/aboutcode-org/scancode-toolkit/issues/3014
|
|
461
461
|
declared_license=get_declared_license(meta),
|
|
462
462
|
keywords=get_keywords(meta),
|
|
463
463
|
parties=get_parties(meta),
|
|
@@ -521,19 +521,25 @@ class PypiWheelHandler(BasePypiHandler):
|
|
|
521
521
|
|
|
522
522
|
@classmethod
|
|
523
523
|
def parse(cls, location):
|
|
524
|
-
with zipfile.ZipFile(location) as zf:
|
|
525
|
-
for path in ZipPath(zf).iterdir():
|
|
526
|
-
if not path.name.endswith(META_DIR_SUFFIXES):
|
|
527
|
-
continue
|
|
528
|
-
for metapath in path.iterdir():
|
|
529
|
-
if not metapath.name.endswith('METADATA'):
|
|
530
|
-
continue
|
|
531
524
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
525
|
+
from python_inspector import lockfile
|
|
526
|
+
from python_inspector.utils_pypi import PYINSP_CACHE_LOCK_TIMEOUT
|
|
527
|
+
lock_file = os.path.join(f"{location}.lockfile")
|
|
528
|
+
with lockfile.FileLock(lock_file).locked(timeout=PYINSP_CACHE_LOCK_TIMEOUT):
|
|
529
|
+
|
|
530
|
+
with zipfile.ZipFile(location) as zf:
|
|
531
|
+
for path in ZipPath(zf).iterdir():
|
|
532
|
+
if not path.name.endswith(META_DIR_SUFFIXES):
|
|
533
|
+
continue
|
|
534
|
+
for metapath in path.iterdir():
|
|
535
|
+
if not metapath.name.endswith('METADATA'):
|
|
536
|
+
continue
|
|
537
|
+
|
|
538
|
+
yield parse_metadata(
|
|
539
|
+
location=metapath,
|
|
540
|
+
datasource_id=cls.datasource_id,
|
|
541
|
+
package_type=cls.default_package_type,
|
|
542
|
+
)
|
|
537
543
|
|
|
538
544
|
|
|
539
545
|
class PypiEggHandler(BasePypiHandler):
|
|
@@ -547,20 +553,26 @@ class PypiEggHandler(BasePypiHandler):
|
|
|
547
553
|
|
|
548
554
|
@classmethod
|
|
549
555
|
def parse(cls, location):
|
|
550
|
-
with zipfile.ZipFile(location) as zf:
|
|
551
|
-
for path in ZipPath(zf).iterdir():
|
|
552
|
-
if not path.name.endswith(META_DIR_SUFFIXES):
|
|
553
|
-
continue
|
|
554
556
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
+
from python_inspector import lockfile
|
|
558
|
+
from python_inspector.utils_pypi import PYINSP_CACHE_LOCK_TIMEOUT
|
|
559
|
+
lock_file = os.path.join(f"{location}.lockfile")
|
|
560
|
+
with lockfile.FileLock(lock_file).locked(timeout=PYINSP_CACHE_LOCK_TIMEOUT):
|
|
561
|
+
|
|
562
|
+
with zipfile.ZipFile(location) as zf:
|
|
563
|
+
for path in ZipPath(zf).iterdir():
|
|
564
|
+
if not path.name.endswith(META_DIR_SUFFIXES):
|
|
557
565
|
continue
|
|
558
566
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
567
|
+
for metapath in path.iterdir():
|
|
568
|
+
if not metapath.name.endswith('PKG-INFO'):
|
|
569
|
+
continue
|
|
570
|
+
|
|
571
|
+
yield parse_metadata(
|
|
572
|
+
location=metapath,
|
|
573
|
+
datasource_id=cls.datasource_id,
|
|
574
|
+
package_type=cls.default_package_type,
|
|
575
|
+
)
|
|
564
576
|
|
|
565
577
|
|
|
566
578
|
class PypiSdistArchiveHandler(BasePypiHandler):
|
|
@@ -765,7 +777,6 @@ class SetupCfgHandler(BaseExtractedPythonLayout):
|
|
|
765
777
|
)
|
|
766
778
|
]
|
|
767
779
|
|
|
768
|
-
|
|
769
780
|
yield models.PackageData(
|
|
770
781
|
datasource_id=cls.datasource_id,
|
|
771
782
|
type=cls.default_package_type,
|
|
@@ -818,6 +829,7 @@ def get_resolved_purl(purl: PackageURL, specifiers: SpecifierSet):
|
|
|
818
829
|
is_resolved=is_resolved,
|
|
819
830
|
)
|
|
820
831
|
|
|
832
|
+
|
|
821
833
|
class PipfileHandler(BaseDependencyFileHandler):
|
|
822
834
|
datasource_id = 'pipfile'
|
|
823
835
|
path_patterns = ('*Pipfile',)
|
python_inspector/__init__.py
CHANGED
|
@@ -7,4 +7,9 @@
|
|
|
7
7
|
# See https://aboutcode.org for more information about nexB OSS projects.
|
|
8
8
|
#
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
from python_inspector import settings
|
|
11
|
+
|
|
12
|
+
# Initialize global settings
|
|
13
|
+
pyinspector_settings = settings.Settings()
|
|
14
|
+
|
|
15
|
+
settings.create_cache_directory(pyinspector_settings.CACHE_THIRDPARTY_DIR)
|
python_inspector/api.py
CHANGED
|
@@ -5,16 +5,17 @@
|
|
|
5
5
|
# ScanCode is a trademark of nexB Inc.
|
|
6
6
|
# SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
|
|
8
|
-
# See https://aboutcode-
|
|
8
|
+
# See https://aboutcode-org/python-inspector for support or download.
|
|
9
9
|
# See https://aboutcode.org for more information about nexB OSS projects.
|
|
10
10
|
#
|
|
11
|
-
|
|
11
|
+
import asyncio
|
|
12
12
|
import os
|
|
13
13
|
from netrc import netrc
|
|
14
14
|
from typing import Dict
|
|
15
15
|
from typing import List
|
|
16
16
|
from typing import NamedTuple
|
|
17
17
|
from typing import Sequence
|
|
18
|
+
from typing import Tuple
|
|
18
19
|
|
|
19
20
|
from packageurl import PackageURL
|
|
20
21
|
from packvers.requirements import Requirement
|
|
@@ -26,8 +27,9 @@ from _packagedcode.models import PackageData
|
|
|
26
27
|
from _packagedcode.pypi import PipRequirementsFileHandler
|
|
27
28
|
from _packagedcode.pypi import PythonSetupPyHandler
|
|
28
29
|
from _packagedcode.pypi import can_process_dependent_package
|
|
29
|
-
from
|
|
30
|
+
from _packagedcode.pypi import get_resolved_purl
|
|
30
31
|
from python_inspector import dependencies
|
|
32
|
+
from python_inspector import pyinspector_settings
|
|
31
33
|
from python_inspector import utils
|
|
32
34
|
from python_inspector import utils_pypi
|
|
33
35
|
from python_inspector.package_data import get_pypi_data_from_purl
|
|
@@ -39,9 +41,11 @@ from python_inspector.resolution import get_package_list
|
|
|
39
41
|
from python_inspector.resolution import get_python_version_from_env_tag
|
|
40
42
|
from python_inspector.resolution import get_reqs_insecurely
|
|
41
43
|
from python_inspector.resolution import get_requirements_from_python_manifest
|
|
44
|
+
from python_inspector.utils import Candidate
|
|
45
|
+
from python_inspector.utils import unique
|
|
42
46
|
from python_inspector.utils_pypi import PLATFORMS_BY_OS
|
|
43
|
-
from python_inspector.utils_pypi import PYPI_SIMPLE_URL
|
|
44
47
|
from python_inspector.utils_pypi import Environment
|
|
48
|
+
from python_inspector.utils_pypi import PypiSimpleRepository
|
|
45
49
|
from python_inspector.utils_pypi import valid_python_versions
|
|
46
50
|
|
|
47
51
|
|
|
@@ -54,7 +58,7 @@ class Resolution(NamedTuple):
|
|
|
54
58
|
``files`` is a parsed list of input file data.
|
|
55
59
|
"""
|
|
56
60
|
|
|
57
|
-
resolution: Dict
|
|
61
|
+
resolution: List[Dict]
|
|
58
62
|
packages: List[PackageData]
|
|
59
63
|
files: List[Dict]
|
|
60
64
|
|
|
@@ -64,8 +68,7 @@ class Resolution(NamedTuple):
|
|
|
64
68
|
# clean file paths
|
|
65
69
|
for file in files:
|
|
66
70
|
path = file["path"]
|
|
67
|
-
file["path"] = utils.remove_test_data_dir_variable_prefix(
|
|
68
|
-
path=path)
|
|
71
|
+
file["path"] = utils.remove_test_data_dir_variable_prefix(path=path)
|
|
69
72
|
return {
|
|
70
73
|
"files": files,
|
|
71
74
|
"packages": [package for package in self.packages],
|
|
@@ -79,7 +82,7 @@ def resolve_dependencies(
|
|
|
79
82
|
specifiers=tuple(),
|
|
80
83
|
python_version=None,
|
|
81
84
|
operating_system=None,
|
|
82
|
-
index_urls
|
|
85
|
+
index_urls: tuple[str, ...] = pyinspector_settings.INDEX_URL,
|
|
83
86
|
pdt_output=None,
|
|
84
87
|
netrc_file=None,
|
|
85
88
|
max_rounds=200000,
|
|
@@ -102,7 +105,7 @@ def resolve_dependencies(
|
|
|
102
105
|
linux OS.
|
|
103
106
|
|
|
104
107
|
Download from the provided PyPI simple index_urls INDEX(s) URLs defaulting
|
|
105
|
-
to PyPI.org
|
|
108
|
+
to PyPI.org or a configured setting.
|
|
106
109
|
"""
|
|
107
110
|
|
|
108
111
|
if not operating_system:
|
|
@@ -147,25 +150,17 @@ def resolve_dependencies(
|
|
|
147
150
|
|
|
148
151
|
files = []
|
|
149
152
|
|
|
150
|
-
if PYPI_SIMPLE_URL not in index_urls:
|
|
151
|
-
index_urls = tuple([PYPI_SIMPLE_URL]) + tuple(index_urls)
|
|
152
|
-
|
|
153
153
|
# requirements
|
|
154
154
|
for req_file in requirement_files:
|
|
155
|
-
deps = dependencies.get_dependencies_from_requirements(
|
|
156
|
-
requirements_file=req_file)
|
|
155
|
+
deps = dependencies.get_dependencies_from_requirements(requirements_file=req_file)
|
|
157
156
|
for extra_data in dependencies.get_extra_data_from_requirements(requirements_file=req_file):
|
|
158
|
-
index_urls = (
|
|
159
|
-
*index_urls, *tuple(extra_data.get("extra_index_urls") or []))
|
|
160
|
-
index_urls = (
|
|
161
|
-
*index_urls, *tuple(extra_data.get("index_url") or []))
|
|
157
|
+
index_urls = get_index_urls(index_urls, extra_data)
|
|
162
158
|
direct_dependencies.extend(deps)
|
|
163
159
|
package_data = [
|
|
164
160
|
pkg_data.to_dict() for pkg_data in PipRequirementsFileHandler.parse(location=req_file)
|
|
165
161
|
]
|
|
166
162
|
if generic_paths:
|
|
167
|
-
req_file = utils.remove_test_data_dir_variable_prefix(
|
|
168
|
-
path=req_file)
|
|
163
|
+
req_file = utils.remove_test_data_dir_variable_prefix(path=req_file)
|
|
169
164
|
|
|
170
165
|
files.append(
|
|
171
166
|
dict(
|
|
@@ -218,15 +213,13 @@ def resolve_dependencies(
|
|
|
218
213
|
files=[setup_py_file],
|
|
219
214
|
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
|
|
220
215
|
)
|
|
221
|
-
setup_py_file_deps = list(
|
|
222
|
-
get_dependent_packages_from_reqs(reqs))
|
|
216
|
+
setup_py_file_deps = list(get_dependent_packages_from_reqs(reqs))
|
|
223
217
|
direct_dependencies.extend(setup_py_file_deps)
|
|
224
218
|
|
|
225
219
|
package_data.dependencies = setup_py_file_deps
|
|
226
220
|
file_package_data = [package_data.to_dict()]
|
|
227
221
|
if generic_paths:
|
|
228
|
-
setup_py_file = utils.remove_test_data_dir_variable_prefix(
|
|
229
|
-
path=setup_py_file)
|
|
222
|
+
setup_py_file = utils.remove_test_data_dir_variable_prefix(path=setup_py_file)
|
|
230
223
|
files.append(
|
|
231
224
|
dict(
|
|
232
225
|
type="file",
|
|
@@ -255,31 +248,32 @@ def resolve_dependencies(
|
|
|
255
248
|
if verbose:
|
|
256
249
|
printer(f"environment: {environment}")
|
|
257
250
|
|
|
258
|
-
|
|
251
|
+
repos_by_url = {}
|
|
259
252
|
if not use_pypi_json_api:
|
|
260
253
|
# Collect PyPI repos
|
|
254
|
+
use_only_confed = pyinspector_settings.USE_ONLY_CONFIGURED_INDEX_URLS
|
|
261
255
|
for index_url in index_urls:
|
|
262
256
|
index_url = index_url.strip("/")
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
repos.append(repo)
|
|
257
|
+
if use_only_confed and index_url not in pyinspector_settings.INDEX_URL:
|
|
258
|
+
if verbose:
|
|
259
|
+
printer(f"Skipping index URL unknown in settings: {index_url!r}")
|
|
260
|
+
continue
|
|
261
|
+
if index_url in repos_by_url:
|
|
262
|
+
continue
|
|
263
|
+
|
|
264
|
+
credentials = None
|
|
265
|
+
if parsed_netrc:
|
|
266
|
+
login, password = utils.get_netrc_auth(index_url, parsed_netrc)
|
|
267
|
+
if login and password:
|
|
268
|
+
credentials = dict(login=login, password=password)
|
|
269
|
+
repo = utils_pypi.PypiSimpleRepository(
|
|
270
|
+
index_url=index_url,
|
|
271
|
+
use_cached_index=use_cached_index,
|
|
272
|
+
credentials=credentials,
|
|
273
|
+
)
|
|
274
|
+
repos_by_url[index_url] = repo
|
|
282
275
|
|
|
276
|
+
repos = repos_by_url.values()
|
|
283
277
|
if verbose:
|
|
284
278
|
printer("repos:")
|
|
285
279
|
for repo in repos:
|
|
@@ -295,21 +289,27 @@ def resolve_dependencies(
|
|
|
295
289
|
pdt_output=pdt_output,
|
|
296
290
|
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
|
|
297
291
|
ignore_errors=ignore_errors,
|
|
292
|
+
verbose=verbose,
|
|
293
|
+
printer=printer,
|
|
298
294
|
)
|
|
299
295
|
|
|
300
|
-
|
|
296
|
+
async def gather_pypi_data():
|
|
297
|
+
async def get_pypi_data(package):
|
|
298
|
+
data = await get_pypi_data_from_purl(
|
|
299
|
+
package, repos=repos, environment=environment, prefer_source=prefer_source
|
|
300
|
+
)
|
|
301
301
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
302
|
+
if verbose:
|
|
303
|
+
printer(f" retrieved package '{package}'")
|
|
304
|
+
|
|
305
|
+
return data
|
|
306
|
+
|
|
307
|
+
if verbose:
|
|
308
|
+
printer(f"retrieve package data from pypi:")
|
|
309
|
+
|
|
310
|
+
return await asyncio.gather(*[get_pypi_data(package) for package in purls])
|
|
311
|
+
|
|
312
|
+
packages = [pkg.to_dict() for pkg in asyncio.run(gather_pypi_data()) if pkg is not None]
|
|
313
313
|
|
|
314
314
|
if verbose:
|
|
315
315
|
printer("done!")
|
|
@@ -321,18 +321,39 @@ def resolve_dependencies(
|
|
|
321
321
|
)
|
|
322
322
|
|
|
323
323
|
|
|
324
|
+
def get_index_urls(index_urls: Tuple, extra_data: Dict) -> Tuple:
|
|
325
|
+
"""
|
|
326
|
+
Return a list of index URLs from the extra_data.
|
|
327
|
+
The extra_data is a dictionary that may contain
|
|
328
|
+
"extra_index_urls" and "index_url" keys.
|
|
329
|
+
"""
|
|
330
|
+
if isinstance(index_urls, str):
|
|
331
|
+
index_urls = [index_urls]
|
|
332
|
+
if isinstance(index_urls, tuple):
|
|
333
|
+
index_urls = list(index_urls)
|
|
334
|
+
extra_index_urls = extra_data.get("extra_index_urls") or []
|
|
335
|
+
index_url = extra_data.get("index_url") or []
|
|
336
|
+
if isinstance(extra_index_urls, list):
|
|
337
|
+
index_urls = (*index_urls, *tuple(extra_index_urls))
|
|
338
|
+
if isinstance(index_url, str):
|
|
339
|
+
index_urls = (*index_urls, *tuple([index_url]))
|
|
340
|
+
return tuple(unique(index_urls))
|
|
341
|
+
|
|
342
|
+
|
|
324
343
|
resolver_api = resolve_dependencies
|
|
325
344
|
|
|
326
345
|
|
|
327
346
|
def resolve(
|
|
328
|
-
direct_dependencies,
|
|
329
|
-
environment,
|
|
330
|
-
repos=tuple(),
|
|
331
|
-
as_tree=False,
|
|
332
|
-
max_rounds=200000,
|
|
333
|
-
pdt_output=False,
|
|
334
|
-
analyze_setup_py_insecurely=False,
|
|
335
|
-
ignore_errors=False,
|
|
347
|
+
direct_dependencies: List[DependentPackage],
|
|
348
|
+
environment: Environment,
|
|
349
|
+
repos: Sequence[utils_pypi.PypiSimpleRepository] = tuple(),
|
|
350
|
+
as_tree: bool = False,
|
|
351
|
+
max_rounds: int = 200000,
|
|
352
|
+
pdt_output: bool = False,
|
|
353
|
+
analyze_setup_py_insecurely: bool = False,
|
|
354
|
+
ignore_errors: bool = False,
|
|
355
|
+
verbose: bool = False,
|
|
356
|
+
printer=print,
|
|
336
357
|
):
|
|
337
358
|
"""
|
|
338
359
|
Resolve dependencies given a ``direct_dependencies`` list of
|
|
@@ -359,6 +380,8 @@ def resolve(
|
|
|
359
380
|
pdt_output=pdt_output,
|
|
360
381
|
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
|
|
361
382
|
ignore_errors=ignore_errors,
|
|
383
|
+
verbose=verbose,
|
|
384
|
+
printer=printer,
|
|
362
385
|
)
|
|
363
386
|
|
|
364
387
|
return resolved_dependencies, packages
|
|
@@ -373,33 +396,77 @@ def get_resolved_dependencies(
|
|
|
373
396
|
pdt_output: bool = False,
|
|
374
397
|
analyze_setup_py_insecurely: bool = False,
|
|
375
398
|
ignore_errors: bool = False,
|
|
376
|
-
|
|
399
|
+
verbose: bool = False,
|
|
400
|
+
printer=print,
|
|
401
|
+
) -> Tuple[List[Dict], List[str]]:
|
|
377
402
|
"""
|
|
378
403
|
Return resolved dependencies of a ``requirements`` list of Requirement for
|
|
379
|
-
an ``
|
|
404
|
+
an ``environment`` Environment. The resolved dependencies are formatted as
|
|
380
405
|
parent/children or a nested tree if ``as_tree`` is True.
|
|
381
406
|
|
|
382
407
|
Used the provided ``repos`` list of PypiSimpleRepository.
|
|
383
|
-
If empty, use instead the PyPI.org JSON API exclusively instead
|
|
408
|
+
If empty, use instead the PyPI.org JSON API exclusively instead.
|
|
384
409
|
"""
|
|
410
|
+
provider = PythonInputProvider(
|
|
411
|
+
environment=environment,
|
|
412
|
+
repos=repos,
|
|
413
|
+
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
|
|
414
|
+
ignore_errors=ignore_errors,
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
# gather version data for all requirements concurrently in advance.
|
|
418
|
+
|
|
419
|
+
async def gather_version_data():
|
|
420
|
+
async def get_version_data(name: str):
|
|
421
|
+
versions = await provider.fill_versions_for_package(name)
|
|
422
|
+
|
|
423
|
+
if verbose:
|
|
424
|
+
printer(f" retrieved versions for package '{name}'")
|
|
425
|
+
|
|
426
|
+
return versions
|
|
427
|
+
|
|
428
|
+
if verbose:
|
|
429
|
+
printer(f"versions:")
|
|
430
|
+
|
|
431
|
+
return await asyncio.gather(
|
|
432
|
+
*[get_version_data(requirement.name) for requirement in requirements]
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
asyncio.run(gather_version_data())
|
|
436
|
+
|
|
437
|
+
# gather dependencies for all pinned requirements concurrently in advance.
|
|
438
|
+
|
|
439
|
+
async def gather_dependencies():
|
|
440
|
+
async def get_dependencies(requirement: Requirement):
|
|
441
|
+
purl = PackageURL(type="pypi", name=requirement.name)
|
|
442
|
+
resolved_purl = get_resolved_purl(purl=purl, specifiers=requirement.specifier)
|
|
443
|
+
|
|
444
|
+
if resolved_purl:
|
|
445
|
+
purl = resolved_purl.purl
|
|
446
|
+
candidate = Candidate(requirement.name, purl.version, requirement.extras)
|
|
447
|
+
await provider.fill_requirements_for_package(purl, candidate)
|
|
448
|
+
|
|
449
|
+
if verbose:
|
|
450
|
+
printer(f" retrieved dependencies for requirement '{str(purl)}'")
|
|
451
|
+
|
|
452
|
+
if verbose:
|
|
453
|
+
printer(f"dependencies:")
|
|
454
|
+
|
|
455
|
+
return await asyncio.gather(
|
|
456
|
+
*[get_dependencies(requirement) for requirement in requirements]
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
asyncio.run(gather_dependencies())
|
|
460
|
+
|
|
385
461
|
resolver = Resolver(
|
|
386
|
-
provider=
|
|
387
|
-
environment=environment,
|
|
388
|
-
repos=repos,
|
|
389
|
-
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
|
|
390
|
-
ignore_errors=ignore_errors,
|
|
391
|
-
),
|
|
462
|
+
provider=provider,
|
|
392
463
|
reporter=BaseReporter(),
|
|
393
464
|
)
|
|
394
|
-
resolver_results = resolver.resolve(
|
|
395
|
-
requirements=requirements, max_rounds=max_rounds)
|
|
465
|
+
resolver_results = resolver.resolve(requirements=requirements, max_rounds=max_rounds)
|
|
396
466
|
package_list = get_package_list(results=resolver_results)
|
|
397
467
|
if pdt_output:
|
|
398
|
-
return
|
|
399
|
-
return (
|
|
400
|
-
format_resolution(resolver_results, as_tree=as_tree),
|
|
401
|
-
package_list,
|
|
402
|
-
)
|
|
468
|
+
return format_pdt_tree(resolver_results), package_list
|
|
469
|
+
return format_resolution(resolver_results, as_tree=as_tree), package_list
|
|
403
470
|
|
|
404
471
|
|
|
405
472
|
def get_requirements_from_direct_dependencies(
|
python_inspector/cli_utils.py
CHANGED
|
@@ -21,8 +21,7 @@ class FileOptionType(click.File):
|
|
|
21
21
|
|
|
22
22
|
def convert(self, value, param, ctx):
|
|
23
23
|
known_opts = set(
|
|
24
|
-
chain.from_iterable(
|
|
25
|
-
p.opts for p in ctx.command.params if isinstance(p, click.Option))
|
|
24
|
+
chain.from_iterable(p.opts for p in ctx.command.params if isinstance(p, click.Option))
|
|
26
25
|
)
|
|
27
26
|
if value in known_opts:
|
|
28
27
|
self.fail(
|
python_inspector/dependencies.py
CHANGED
|
@@ -8,26 +8,29 @@
|
|
|
8
8
|
# See https://github.com/nexB/skeleton for support or download.
|
|
9
9
|
# See https://aboutcode.org for more information about nexB OSS projects.
|
|
10
10
|
#
|
|
11
|
+
from typing import Iterable
|
|
12
|
+
from typing import Mapping
|
|
11
13
|
|
|
12
14
|
from packageurl import PackageURL
|
|
13
15
|
from packvers.requirements import Requirement
|
|
14
|
-
from pip_requirements_parser import InstallRequirement
|
|
15
16
|
|
|
16
17
|
from _packagedcode import models
|
|
18
|
+
from _packagedcode.models import DependentPackage
|
|
17
19
|
from _packagedcode.pypi import PipRequirementsFileHandler
|
|
18
20
|
from _packagedcode.pypi import get_requirements_txt_dependencies
|
|
19
21
|
|
|
20
22
|
"""
|
|
21
|
-
Utilities to resolve dependencies
|
|
23
|
+
Utilities to resolve dependencies.
|
|
22
24
|
"""
|
|
23
25
|
|
|
24
26
|
TRACE = False
|
|
25
27
|
|
|
26
28
|
|
|
27
|
-
def get_dependencies_from_requirements(
|
|
29
|
+
def get_dependencies_from_requirements(
|
|
30
|
+
requirements_file="requirements.txt",
|
|
31
|
+
) -> Iterable[DependentPackage]:
|
|
28
32
|
"""
|
|
29
|
-
Yield DependentPackage for each requirement in a `requirement`
|
|
30
|
-
file.
|
|
33
|
+
Yield DependentPackage for each requirement in a `requirement` file.
|
|
31
34
|
"""
|
|
32
35
|
dependent_packages, _ = get_requirements_txt_dependencies(
|
|
33
36
|
location=requirements_file, include_nested=True
|
|
@@ -41,21 +44,20 @@ def get_dependencies_from_requirements(requirements_file="requirements.txt"):
|
|
|
41
44
|
yield dependent_package
|
|
42
45
|
|
|
43
46
|
|
|
44
|
-
def get_extra_data_from_requirements(requirements_file="requirements.txt"):
|
|
47
|
+
def get_extra_data_from_requirements(requirements_file="requirements.txt") -> Iterable[Mapping]:
|
|
45
48
|
"""
|
|
46
|
-
Yield extra_data for each requirement in a `requirement`
|
|
47
|
-
file.
|
|
49
|
+
Yield extra_data for each requirement in a `requirement` file.
|
|
48
50
|
"""
|
|
49
51
|
for package_data in PipRequirementsFileHandler.parse(location=requirements_file):
|
|
50
52
|
yield package_data.extra_data
|
|
51
53
|
|
|
52
54
|
|
|
53
|
-
def is_requirement_pinned(requirement: Requirement):
|
|
55
|
+
def is_requirement_pinned(requirement: Requirement) -> bool:
|
|
54
56
|
specifiers = requirement.specifier
|
|
55
57
|
return specifiers and len(specifiers) == 1 and next(iter(specifiers)).operator in {"==", "==="}
|
|
56
58
|
|
|
57
59
|
|
|
58
|
-
def get_dependency(specifier):
|
|
60
|
+
def get_dependency(specifier) -> DependentPackage:
|
|
59
61
|
"""
|
|
60
62
|
Return a DependentPackage given a requirement ``specifier`` string.
|
|
61
63
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) nexB Inc. and others. All rights reserved.
|
|
3
|
+
# ScanCode is a trademark of nexB Inc.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
|
|
6
|
+
# See https://github.com/nexB/scancode-toolkit for support or download.
|
|
7
|
+
# See https://aboutcode.org for more information about nexB OSS projects.
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
from contextlib import contextmanager
|
|
11
|
+
|
|
12
|
+
import fasteners
|
|
13
|
+
|
|
14
|
+
"""
|
|
15
|
+
An interprocess lockfile with a timeout.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class LockTimeout(Exception):
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class FileLock(fasteners.InterProcessLock):
|
|
24
|
+
@contextmanager
|
|
25
|
+
def locked(self, timeout):
|
|
26
|
+
acquired = self.acquire(timeout=timeout)
|
|
27
|
+
if not acquired:
|
|
28
|
+
raise LockTimeout(timeout)
|
|
29
|
+
try:
|
|
30
|
+
yield
|
|
31
|
+
finally:
|
|
32
|
+
self.release()
|