Add Swift Package Manager scanner - #31
Open
jthDEV wants to merge 1 commit into
Open
Conversation
Ports the dependency resolution logic from the retired ts-spm plugin (https://github.com/TrustSource/ts-spm) into ts-scan's own Scanner interface. Detects Package.swift and parses the JSON tree produced by `swift package show-dependencies --format json`.
| @@ -0,0 +1,83 @@ | |||
| import json | |||
| from subprocess import CompletedProcess | |||
| def test_accepts_requires_package_swift(tmp_path): | ||
| scanner = SwiftScanner() | ||
|
|
||
| assert not scanner.accepts(tmp_path) |
|
|
||
| (tmp_path / 'Package.swift').write_text('// swift-tools-version:5.9\n') | ||
|
|
||
| assert scanner.accepts(tmp_path) |
|
|
||
| scan = scanner.scan(tmp_path) | ||
|
|
||
| assert scan is not None |
| scan = scanner.scan(tmp_path) | ||
|
|
||
| assert scan is not None | ||
| assert scan.module == 'MyPackage' |
|
|
||
| arg_parser = next(d for d in root.dependencies if d.name == 'swift-argument-parser') | ||
| assert arg_parser.versions == ['1.2.0'] | ||
| assert arg_parser.repoUrl == 'https://github.com/apple/swift-argument-parser' |
| arg_parser = next(d for d in root.dependencies if d.name == 'swift-argument-parser') | ||
| assert arg_parser.versions == ['1.2.0'] | ||
| assert arg_parser.repoUrl == 'https://github.com/apple/swift-argument-parser' | ||
| assert arg_parser.key == 'swift:swift-argument-parser' |
| assert arg_parser.key == 'swift:swift-argument-parser' | ||
|
|
||
| log = next(d for d in root.dependencies if d.name == 'swift-log') | ||
| assert [d.name for d in log.dependencies] == ['swift-argument-parser'] |
|
|
||
| # The transitive occurrence of swift-argument-parser under swift-log resolves | ||
| # to the same Dependency instance as the direct one. | ||
| assert log.dependencies[0] is arg_parser |
| lambda *args, **kwargs: CompletedProcess(args, 0, stdout=b'') | ||
| ) | ||
|
|
||
| assert scanner.scan(tmp_path) is None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Scannerinterface, replacing the need for a separate pluginPackage.swiftand parses the JSON tree produced byswift package show-dependencies --format jsoninto ts-scan'sDependency/DependencyScanmodel, using theswiftpurl type as key/purl prefixSwiftScanneralongside the other package-manager scanners;--swift:ignore,--swift:executableand--swift:forwardbecome available like for the other PM-backed scannersDependencies added
None — uses only the
swiftexecutable already required by Swift Package Manager projects.Test plan
pytest tests/test_swift.py— accepts()/scan() unit tests with a mockedswift package show-dependenciesJSON tree (including diamond-dependency de-duplication)pytest tests/— full existing suite still passes