Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Changelog
Next release
--------------

- Fix a crash when scanning Dart packages with ``path:``, ``git:`` or
``hosted:`` dependencies in ``pubspec.yaml``: dependency sources given
as mappings are now parsed instead of raising
``AttributeError: 'dict' object has no attribute 'replace'``.
https://github.com/aboutcode-org/scancode-toolkit/issues/5482

- Fix the optional ``licenses`` extra dependency typo to install
``licensedcode-data``.
https://github.com/aboutcode-org/scancode-toolkit/pull/5056
Expand Down
26 changes: 22 additions & 4 deletions src/packagedcode/pubspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,28 @@ def build_dep(name, version, scope, is_runtime=True, is_optional=False):
# TODO: these can be more complex for SDKs
# https://dart.dev/tools/pub/dependencies#dependency-sources

if isinstance(version, dict) and 'sdk' in version:
# {'sdk': 'flutter'} type of deps....
# which is a wart that we keep as a requiremnet
version = ', '.join(': '.join([k, str(v)]) for k, v in version.items())
if isinstance(version, dict):
# Dependency sources can be mappings, e.g. `path:`, `git:` or
# `hosted:` dependencies, such as:
# my_package:
# path: ../my_package
# my_package:
# git:
# url: https://github.com/example/my_package.git
# ref: some-branch
# my_package:
# hosted: https://example.com
# version: ^1.0.0
# Flatten the mapping into a requirement string, keeping the
# source information, e.g. `path: ../my_package`.
# The `sdk:` form, e.g. `{'sdk': 'flutter'}`, is handled the
# same way and keeps its previous rendering: `sdk: flutter`.
parts = []
for key, value in version.items():
if isinstance(value, dict):
value = ', '.join(f'{k}: {v}' for k, v in value.items())
parts.append(f'{key}: {value}')
version = ', '.join(parts)

if version.replace('.', '').isdigit():
# version is pinned exactly if it is only made of dots and digits
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: dependency-sources
version: 1.0.0
description: Test pubspec with dependency sources as mappings

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
hosted_dep:
hosted: https://example.com
version: ^1.0.0
git_dep:
git:
url: https://github.com/example/git_dep.git
ref: main
git_url_dep:
git: https://github.com/example/git_url_dep.git
path_dep:
path: ../path_dep
sdk_dep:
sdk: flutter

dev_dependencies:
dev_path_dep:
path: ../dev_path_dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
[
{
"type": "dart",
"namespace": null,
"name": "dependency-sources",
"version": "1.0.0",
"qualifiers": {},
"subpath": null,
"primary_language": "dart",
"description": "Test pubspec with dependency sources as mappings",
"release_date": null,
"parties": [],
"keywords": [],
"homepage_url": null,
"download_url": "https://pub.dartlang.org/packages/dependency-sources/versions/1.0.0.tar.gz",
"size": null,
"sha1": null,
"md5": null,
"sha256": null,
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
"vcs_url": null,
"copyright": null,
"holder": null,
"declared_license_expression": null,
"declared_license_expression_spdx": null,
"license_detections": [],
"other_license_expression": null,
"other_license_expression_spdx": null,
"other_license_detections": [],
"extracted_license_statement": null,
"notice_text": null,
"source_packages": [],
"file_references": [],
"is_private": false,
"is_virtual": false,
"extra_data": {},
"dependencies": [
{
"purl": "pkg:pubspec/hosted_dep",
"extracted_requirement": "hosted: https://example.com, version: ^1.0.0",
"scope": "dependencies",
"is_runtime": true,
"is_optional": false,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {}
},
{
"purl": "pkg:pubspec/git_dep",
"extracted_requirement": "git: url: https://github.com/example/git_dep.git, ref: main",
"scope": "dependencies",
"is_runtime": true,
"is_optional": false,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {}
},
{
"purl": "pkg:pubspec/git_url_dep",
"extracted_requirement": "git: https://github.com/example/git_url_dep.git",
"scope": "dependencies",
"is_runtime": true,
"is_optional": false,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {}
},
{
"purl": "pkg:pubspec/path_dep",
"extracted_requirement": "path: ../path_dep",
"scope": "dependencies",
"is_runtime": true,
"is_optional": false,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {}
},
{
"purl": "pkg:pubspec/sdk_dep",
"extracted_requirement": "sdk: flutter",
"scope": "dependencies",
"is_runtime": true,
"is_optional": false,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {}
},
{
"purl": "pkg:pubspec/dev_path_dep",
"extracted_requirement": "path: ../dev_path_dep",
"scope": "dev_dependencies",
"is_runtime": false,
"is_optional": true,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {}
},
{
"purl": "pkg:pubspec/sdk",
"extracted_requirement": ">=2.12.0 <3.0.0",
"scope": "environment",
"is_runtime": true,
"is_optional": false,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {}
}
],
"repository_homepage_url": "https://pub.dev/packages/dependency-sources/versions/1.0.0",
"repository_download_url": "https://pub.dartlang.org/packages/dependency-sources/versions/1.0.0.tar.gz",
"api_data_url": "https://pub.dev/api/packages/dependency-sources/versions/1.0.0",
"datasource_id": "pubspec_yaml",
"purl": "pkg:dart/dependency-sources@1.0.0"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: json_serializable
version: 6.15.2
description: >-
Automatically generate code for converting to and from JSON by annotating
Dart classes.
repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable
environment:
sdk: ^3.12.0
topics:
- json
- build-runner
- json-serializable
- codegen

resolution: workspace

dependencies:
analyzer: '>=10.0.0 <15.0.0'
async: ^2.10.0
build: '>=4.0.4 <6.0.0'
build_config: ^1.2.0
dart_style: ^3.1.4

# Use a tight version constraint to ensure that a constraint on
# `json_annotation` properly constrains all features it provides.
json_annotation: '>=4.12.0 <4.13.0'
meta: ^1.16.0
path: ^1.9.0
pub_semver: ^2.1.4
pubspec_parse: ^1.0.0
source_gen: ^4.1.2
source_helper: ^1.3.10

dev_dependencies:
_json_serial_shared_test:
path: ../shared_test
build_runner: ^2.10.5
build_verify: ^3.0.0
collection: ^1.19.0
json_schema: ^5.2.2
logging: ^1.2.0
source_gen_test: ^1.4.1
test: ^1.29.0
test_descriptor: ^2.0.0
test_process: ^2.0.0
yaml: ^3.1.3
Loading
Loading