Skip to content

Commit f097ef1

Browse files
authored
Merge pull request #1650 from blackducksoftware/dev/devm/IDETECT-4937
Add support for environment.yaml in Conda
2 parents 1e2c26e + be1ff4e commit f097ef1

File tree

4 files changed

+89
-9
lines changed

4 files changed

+89
-9
lines changed

detectable/src/main/java/com/blackduck/integration/detectable/detectables/conda/CondaCliDetectable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import com.blackduck.integration.detectable.extraction.Extraction;
1414
import com.blackduck.integration.detectable.extraction.ExtractionEnvironment;
1515

16-
@DetectableInfo(name = "Conda CLI", language = "Python", forge = "Anaconda", accuracy = DetectableAccuracyType.HIGH, requirementsMarkdown = "File: environment.yml. Executable: conda.")
16+
@DetectableInfo(name = "Conda CLI", language = "Python", forge = "Anaconda", accuracy = DetectableAccuracyType.HIGH, requirementsMarkdown = "File: environment.yml or environment.yaml. Executable: conda.")
1717
public class CondaCliDetectable extends Detectable {
1818
public static final String ENVIRONMENT_YML = "environment.yml";
19-
19+
public static final String ENVIRONMENT_YAML = "environment.yaml";
2020
private final FileFinder fileFinder;
2121
private final CondaResolver condaResolver;
2222
private final CondaCliExtractor condaExtractor;
@@ -41,7 +41,7 @@ public CondaCliDetectable(
4141
@Override
4242
public DetectableResult applicable() {
4343
Requirements requirements = new Requirements(fileFinder, environment);
44-
requirements.file(ENVIRONMENT_YML);
44+
requirements.eitherFile(ENVIRONMENT_YML, ENVIRONMENT_YAML);
4545
return requirements.result();
4646
}
4747

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.blackduck.integration.detectable.detectables.conda.functional;
2+
3+
import com.blackduck.integration.bdio.model.Forge;
4+
import com.blackduck.integration.detectable.Detectable;
5+
import com.blackduck.integration.detectable.DetectableEnvironment;
6+
import com.blackduck.integration.detectable.ExecutableTarget;
7+
import com.blackduck.integration.detectable.detectable.exception.DetectableException;
8+
import com.blackduck.integration.detectable.detectable.executable.resolver.CondaResolver;
9+
import com.blackduck.integration.detectable.detectables.conda.CondaCliDetectableOptions;
10+
import com.blackduck.integration.detectable.extraction.Extraction;
11+
import com.blackduck.integration.detectable.functional.DetectableFunctionalTest;
12+
import com.blackduck.integration.detectable.util.graph.NameVersionGraphAssert;
13+
import com.blackduck.integration.executable.ExecutableOutput;
14+
import org.jetbrains.annotations.NotNull;
15+
import org.junit.jupiter.api.Assertions;
16+
17+
import java.io.IOException;
18+
19+
public class CondaDetectableTest extends DetectableFunctionalTest {
20+
21+
public CondaDetectableTest() throws IOException {
22+
super("conda");
23+
}
24+
25+
@Override
26+
protected void setup() throws IOException {
27+
addFile("environment.yaml");
28+
29+
ExecutableOutput condaListOutput = createStandardOutput(
30+
"[",
31+
" {",
32+
" \"base_url\": null,",
33+
" \"build_number\": 0,",
34+
" \"build_string\": \"0\",",
35+
" \"channel\": \"defaults\",",
36+
" \"dist_name\": \"mkl-2017.0.3-0\",",
37+
" \"name\": \"mkl\",",
38+
" \"platform\": null,",
39+
" \"version\": \"2017.0.3\",",
40+
" \"with_features_depends\": null",
41+
" }",
42+
"]"
43+
);
44+
addExecutableOutput(condaListOutput, "conda", "list", "-n", "conda-env", "--json");
45+
46+
ExecutableOutput condaInfoOutput = createStandardOutput(
47+
"{",
48+
" \"conda_build_version\": \"not installed\",",
49+
" \"conda_env_version\": \"4.3.22\",",
50+
" \"conda_location\": \"/usr/local/miniconda3/lib/python3.6/site-packages/conda\",",
51+
" \"conda_prefix\": \"/usr/local/miniconda3\",",
52+
" \"conda_private\": false,",
53+
" \"conda_version\": \"4.3.22\",",
54+
" \"default_prefix\": \"/usr/local/miniconda3\",",
55+
" \"platform\": \"win-64\"",
56+
"}"
57+
);
58+
addExecutableOutput(getOutputDirectory(), condaInfoOutput, "conda", "info", "--json");
59+
}
60+
61+
@NotNull
62+
@Override
63+
public Detectable create(@NotNull DetectableEnvironment detectableEnvironment) {
64+
class CondaResolverTest implements CondaResolver {
65+
66+
@Override
67+
public ExecutableTarget resolveConda() throws DetectableException {
68+
return ExecutableTarget.forCommand("conda");
69+
}
70+
}
71+
return detectableFactory.createCondaCliDetectable(detectableEnvironment, new CondaResolverTest(), new CondaCliDetectableOptions("conda-env"));
72+
}
73+
74+
@Override
75+
public void assertExtraction(@NotNull Extraction extraction) {
76+
Assertions.assertEquals(1, extraction.getCodeLocations().size());
77+
78+
NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.ANACONDA, extraction.getCodeLocations().get(0).getDependencyGraph());
79+
graphAssert.hasRootSize(1);
80+
graphAssert.hasRootDependency("mkl", "2017.0.3-0-win-64");
81+
82+
}
83+
}

documentation/src/main/markdown/currentreleasenotes.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222

2323
* With the addition of the `detect.cargo.included.features` and `detect.cargo.disable.default.features` properties, [detect_product_short] now supports Cargo features and the inclusion or exclusion of dependencies as options. See [Cargo](properties/detectors/cargo.md) for details.
2424
<note type="note">This feature is supported for Cargo CLI Detector. Cargo Lockfile Detector will log a warning if these properties are provided.</note>
25+
* (IDETECT-4937) Add support for `environment.yaml` in [detect_product_short] Conda CLI Detector.
2526

2627
### Resolved issues
2728

28-
* (IDETECT-4960) Added support for Cargo features and optional dependencies in Cargo CLI Detector, allowing precise control over which features are included in the SBOM through cargo tree command flags. See [Cargo](properties/detectors/cargo.md) for details.
29-
30-
### Dependency Updates
31-
32-
* Project Inspector version updated to 2024.12.2
29+
* (IDETECT-4960) Added support for Cargo features and optional dependencies in Cargo CLI Detector, allowing precise control over which features are included in the SBOM through cargo tree command flags. See [Cargo](properties/detectors/cargo.md) for details.

documentation/src/main/markdown/packagemgrs/conda.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
The Conda detector discovers dependencies of python projects utilizing the Conda package and environment manager.
1010

11-
[detect_product_short] runs the Conda detector if an environment.yml file is found in your project.
11+
[detect_product_short] runs the Conda detector if an environment.yml or environment.yaml file is found in your project.
1212

1313
The Conda detector requires that the *conda* executable is on the PATH, or that its path is passed in via `--detect.conda.path`.
1414

0 commit comments

Comments
 (0)