Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove category usage from the poetry detector #991

Merged
merged 3 commits into from
Feb 1, 2024
Merged
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
4 changes: 3 additions & 1 deletion docs/detectors/poetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Poetry detection relies on a poetry.lock file being present.
Poetry detection is performed by parsing a <em>poetry.lock</em> found under the scan directory.

## Known limitations
Poetry detection will not work if lock files are not being used.
1. Poetry detection will not work if lock files are not being used.
2. Dev dependencies are flagged as normal dependencies since it is not possible to determine whether or not
a dependency is a development dependency via the lockfile alone.

Full dependency graph generation is not supported.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
[DataContract]
public class PoetryPackage
{
[DataMember(Name = "category")]
public string Category { get; set; }

[DataMember(Name = "name")]
public string Name { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public PoetryComponentDetector(

public override IEnumerable<ComponentType> SupportedComponentTypes => new[] { ComponentType.Pip };

public override int Version { get; } = 2;
public override int Version { get; } = 3;

public override IEnumerable<string> Categories => new List<string> { "Python" };

Expand All @@ -54,17 +54,15 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID

tofay marked this conversation as resolved.
Show resolved Hide resolved
poetryLock.Package.ToList().ForEach(package =>
{
var isDevelopmentDependency = package.Category != "main";
cobya marked this conversation as resolved.
Show resolved Hide resolved

if (package.Source != null && package.Source.Type == "git")
{
var component = new DetectedComponent(new GitComponent(new Uri(package.Source.Url), package.Source.ResolvedReference));
singleFileComponentRecorder.RegisterUsage(component, isDevelopmentDependency: isDevelopmentDependency);
singleFileComponentRecorder.RegisterUsage(component, isDevelopmentDependency: false);
}
else
{
var component = new DetectedComponent(new PipComponent(package.Name, package.Version));
singleFileComponentRecorder.RegisterUsage(component, isDevelopmentDependency: isDevelopmentDependency);
singleFileComponentRecorder.RegisterUsage(component, isDevelopmentDependency: false);
}
});
await Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public async Task TestPoetryDetector_TestCustomSourceAsync()
name = ""certifi""
version = ""2021.10.8""
description = ""Python package for providing Mozilla's CA Bundle.""
category = ""main""
optional = false
python-versions = ""*""

Expand All @@ -47,49 +46,20 @@ public async Task TestPoetryDetector_TestCustomSourceAsync()
componentRecorder.GetEffectiveDevDependencyValue(queryString.Component.Id).GetValueOrDefault(false).Should().BeFalse();
}

[TestMethod]
public async Task TestPoetryDetector_TestDevDependencyAsync()
{
var poetryLockContent = @"[[package]]
name = ""certifi""
version = ""2021.10.8""
description = ""Python package for providing Mozilla's CA Bundle.""
category = ""dev""
optional = false
python-versions = ""*""
";

var (scanResult, componentRecorder) = await this.DetectorTestUtility
.WithFile("poetry.lock", poetryLockContent)
.ExecuteDetectorAsync();

scanResult.ResultCode.Should().Be(ProcessingResultCode.Success);

var detectedComponents = componentRecorder.GetDetectedComponents();
detectedComponents.Should().ContainSingle();

this.AssertPipComponentNameAndVersion(detectedComponents, "certifi", "2021.10.8");

var queryString = detectedComponents.Single(component => ((PipComponent)component.Component).Name.Contains("certifi"));
componentRecorder.GetEffectiveDevDependencyValue(queryString.Component.Id).GetValueOrDefault(false).Should().BeTrue();
}

[TestMethod]
public async Task TestPoetryDetector_TestGitDependencyAsync()
{
var poetryLockContent = @"[[package]]
name = ""certifi""
version = ""2021.10.8""
description = ""Python package for providing Mozilla's CA Bundle.""
category = ""dev""
optional = false
python-versions = ""*""

[[package]]
name = ""requests""
version = ""2.26.0""
description = ""Python HTTP for Humans.""
category = ""main""
optional = false
python-versions = "">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*""
develop = false
Expand Down
Loading