python-inspector 0.13.1__py3-none-any.whl → 0.14.1__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 +141 -64
- python_inspector/dependencies.py +12 -10
- python_inspector/lockfile.py +32 -0
- python_inspector/package_data.py +54 -43
- python_inspector/resolution.py +114 -92
- python_inspector/resolve_cli.py +6 -7
- python_inspector/settings.py +66 -0
- python_inspector/setup_py_live_eval.py +2 -2
- python_inspector/utils.py +44 -4
- python_inspector/utils_pip_compatibility_tags.py +4 -2
- python_inspector/utils_pypi.py +139 -122
- {python_inspector-0.13.1.dist-info → python_inspector-0.14.1.dist-info}/METADATA +103 -43
- python_inspector-0.14.1.dist-info/RECORD +42 -0
- {python_inspector-0.13.1.dist-info → python_inspector-0.14.1.dist-info}/WHEEL +1 -1
- {python_inspector-0.13.1.dist-info → python_inspector-0.14.1.dist-info}/licenses/CHANGELOG.rst +43 -1
- {python_inspector-0.13.1.dist-info → python_inspector-0.14.1.dist-info}/licenses/NOTICE +2 -22
- python_inspector-0.14.1.dist-info/licenses/README.rst +240 -0
- python_inspector-0.13.1.dist-info/RECORD +0 -39
- {python_inspector-0.13.1.dist-info → python_inspector-0.14.1.dist-info}/entry_points.txt +0 -0
- {python_inspector-0.13.1.dist-info → python_inspector-0.14.1.dist-info}/licenses/AUTHORS.rst +0 -0
- {python_inspector-0.13.1.dist-info → python_inspector-0.14.1.dist-info}/licenses/CODE_OF_CONDUCT.rst +0 -0
- {python_inspector-0.13.1.dist-info → python_inspector-0.14.1.dist-info}/licenses/apache-2.0.LICENSE +0 -0
- {python_inspector-0.13.1.dist-info → python_inspector-0.14.1.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
|
|
|
@@ -78,7 +82,7 @@ def resolve_dependencies(
|
|
|
78
82
|
specifiers=tuple(),
|
|
79
83
|
python_version=None,
|
|
80
84
|
operating_system=None,
|
|
81
|
-
index_urls
|
|
85
|
+
index_urls: tuple[str, ...] = pyinspector_settings.INDEX_URL,
|
|
82
86
|
pdt_output=None,
|
|
83
87
|
netrc_file=None,
|
|
84
88
|
max_rounds=200000,
|
|
@@ -101,7 +105,7 @@ def resolve_dependencies(
|
|
|
101
105
|
linux OS.
|
|
102
106
|
|
|
103
107
|
Download from the provided PyPI simple index_urls INDEX(s) URLs defaulting
|
|
104
|
-
to PyPI.org
|
|
108
|
+
to PyPI.org or a configured setting.
|
|
105
109
|
"""
|
|
106
110
|
|
|
107
111
|
if not operating_system:
|
|
@@ -146,15 +150,11 @@ def resolve_dependencies(
|
|
|
146
150
|
|
|
147
151
|
files = []
|
|
148
152
|
|
|
149
|
-
if PYPI_SIMPLE_URL not in index_urls:
|
|
150
|
-
index_urls = tuple([PYPI_SIMPLE_URL]) + tuple(index_urls)
|
|
151
|
-
|
|
152
153
|
# requirements
|
|
153
154
|
for req_file in requirement_files:
|
|
154
155
|
deps = dependencies.get_dependencies_from_requirements(requirements_file=req_file)
|
|
155
156
|
for extra_data in dependencies.get_extra_data_from_requirements(requirements_file=req_file):
|
|
156
|
-
index_urls = (
|
|
157
|
-
index_urls = (*index_urls, *tuple(extra_data.get("index_url") or []))
|
|
157
|
+
index_urls = get_index_urls(index_urls, extra_data)
|
|
158
158
|
direct_dependencies.extend(deps)
|
|
159
159
|
package_data = [
|
|
160
160
|
pkg_data.to_dict() for pkg_data in PipRequirementsFileHandler.parse(location=req_file)
|
|
@@ -248,29 +248,32 @@ def resolve_dependencies(
|
|
|
248
248
|
if verbose:
|
|
249
249
|
printer(f"environment: {environment}")
|
|
250
250
|
|
|
251
|
-
|
|
251
|
+
repos_by_url = {}
|
|
252
252
|
if not use_pypi_json_api:
|
|
253
253
|
# Collect PyPI repos
|
|
254
|
+
use_only_confed = pyinspector_settings.USE_ONLY_CONFIGURED_INDEX_URLS
|
|
254
255
|
for index_url in index_urls:
|
|
255
256
|
index_url = index_url.strip("/")
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
|
273
275
|
|
|
276
|
+
repos = repos_by_url.values()
|
|
274
277
|
if verbose:
|
|
275
278
|
printer("repos:")
|
|
276
279
|
for repo in repos:
|
|
@@ -286,21 +289,27 @@ def resolve_dependencies(
|
|
|
286
289
|
pdt_output=pdt_output,
|
|
287
290
|
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
|
|
288
291
|
ignore_errors=ignore_errors,
|
|
292
|
+
verbose=verbose,
|
|
293
|
+
printer=printer,
|
|
289
294
|
)
|
|
290
295
|
|
|
291
|
-
|
|
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
|
+
)
|
|
292
301
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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]
|
|
304
313
|
|
|
305
314
|
if verbose:
|
|
306
315
|
printer("done!")
|
|
@@ -312,18 +321,39 @@ def resolve_dependencies(
|
|
|
312
321
|
)
|
|
313
322
|
|
|
314
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
|
+
|
|
315
343
|
resolver_api = resolve_dependencies
|
|
316
344
|
|
|
317
345
|
|
|
318
346
|
def resolve(
|
|
319
|
-
direct_dependencies,
|
|
320
|
-
environment,
|
|
321
|
-
repos=tuple(),
|
|
322
|
-
as_tree=False,
|
|
323
|
-
max_rounds=200000,
|
|
324
|
-
pdt_output=False,
|
|
325
|
-
analyze_setup_py_insecurely=False,
|
|
326
|
-
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,
|
|
327
357
|
):
|
|
328
358
|
"""
|
|
329
359
|
Resolve dependencies given a ``direct_dependencies`` list of
|
|
@@ -350,6 +380,8 @@ def resolve(
|
|
|
350
380
|
pdt_output=pdt_output,
|
|
351
381
|
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
|
|
352
382
|
ignore_errors=ignore_errors,
|
|
383
|
+
verbose=verbose,
|
|
384
|
+
printer=printer,
|
|
353
385
|
)
|
|
354
386
|
|
|
355
387
|
return resolved_dependencies, packages
|
|
@@ -364,32 +396,77 @@ def get_resolved_dependencies(
|
|
|
364
396
|
pdt_output: bool = False,
|
|
365
397
|
analyze_setup_py_insecurely: bool = False,
|
|
366
398
|
ignore_errors: bool = False,
|
|
367
|
-
|
|
399
|
+
verbose: bool = False,
|
|
400
|
+
printer=print,
|
|
401
|
+
) -> Tuple[List[Dict], List[str]]:
|
|
368
402
|
"""
|
|
369
403
|
Return resolved dependencies of a ``requirements`` list of Requirement for
|
|
370
|
-
an ``
|
|
404
|
+
an ``environment`` Environment. The resolved dependencies are formatted as
|
|
371
405
|
parent/children or a nested tree if ``as_tree`` is True.
|
|
372
406
|
|
|
373
407
|
Used the provided ``repos`` list of PypiSimpleRepository.
|
|
374
|
-
If empty, use instead the PyPI.org JSON API exclusively instead
|
|
408
|
+
If empty, use instead the PyPI.org JSON API exclusively instead.
|
|
375
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
|
+
|
|
376
461
|
resolver = Resolver(
|
|
377
|
-
provider=
|
|
378
|
-
environment=environment,
|
|
379
|
-
repos=repos,
|
|
380
|
-
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
|
|
381
|
-
ignore_errors=ignore_errors,
|
|
382
|
-
),
|
|
462
|
+
provider=provider,
|
|
383
463
|
reporter=BaseReporter(),
|
|
384
464
|
)
|
|
385
465
|
resolver_results = resolver.resolve(requirements=requirements, max_rounds=max_rounds)
|
|
386
466
|
package_list = get_package_list(results=resolver_results)
|
|
387
467
|
if pdt_output:
|
|
388
|
-
return
|
|
389
|
-
return (
|
|
390
|
-
format_resolution(resolver_results, as_tree=as_tree),
|
|
391
|
-
package_list,
|
|
392
|
-
)
|
|
468
|
+
return format_pdt_tree(resolver_results), package_list
|
|
469
|
+
return format_resolution(resolver_results, as_tree=as_tree), package_list
|
|
393
470
|
|
|
394
471
|
|
|
395
472
|
def get_requirements_from_direct_dependencies(
|
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()
|