Skip to content

Commit

Permalink
Add fixes and list test python
Browse files Browse the repository at this point in the history
  • Loading branch information
Octaviusss committed Jan 9, 2025
1 parent 9633ca0 commit 4ae5d2e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
14 changes: 9 additions & 5 deletions extractor/filesystem/language/python/conda/condameta.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,18 @@ func (e Extractor) FileRequired(api filesystem.FileAPI) bool {
// Normalize the path to use forward slashes, making it platform-independent
path = filepath.ToSlash(path)

// Verify the path contains the `envs/` directory and check extension
if !strings.Contains(path, "envs/") || !strings.HasSuffix(path, ".json") {
// Verify the path contains the `envs/` directory
if !(strings.HasPrefix(path, "envs/") || strings.Contains(path, "/envs/")) {
return false
}

parts := strings.Split(path, "/")
// Ensure there are enough parts and the last directory is `conda-meta`.
if len(parts) < 3 || !strings.HasSuffix(filepath.Dir(path), "conda-meta") {
// Verify extension
if !strings.HasSuffix(path, ".json") {
return false
}

// Ensure the last directory is `conda-meta`.
if !strings.HasSuffix(filepath.Dir(path), "conda-meta") {
return false
}

Expand Down
5 changes: 5 additions & 0 deletions extractor/filesystem/language/python/conda/condameta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func TestFileRequired(t *testing.T) {
path: "path/to/envs/data_analysis/conda-meta/numpy-1.21.2-py39h123abcde.json",
wantRequired: true,
},
{
name: "invalid envs dir",
path: "/path/to/fooenvs/conda-meta/numpy-1.21.2-py39h123abcde.json",
wantRequired: false,
},
{
name: "invalid path conda json file",
path: "envs/data_analysis/test/numpy-1.21.2-py39h123abcde.json",
Expand Down
6 changes: 3 additions & 3 deletions extractor/filesystem/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ func TestExtractorsFromNames(t *testing.T) {
{
desc: "Find all extractors of a type",
names: []string{"python"},
wantExts: []string{"python/pdmlock", "python/Pipfilelock", "python/poetrylock", "python/wheelegg", "python/requirements"},
wantExts: []string{"python/pdmlock", "python/Pipfilelock", "python/poetrylock", "python/condameta", "python/wheelegg", "python/requirements"},
},
{
desc: "Case-insensitive",
names: []string{"Python"},
wantExts: []string{"python/pdmlock", "python/Pipfilelock", "python/poetrylock", "python/wheelegg", "python/requirements"},
wantExts: []string{"python/pdmlock", "python/Pipfilelock", "python/poetrylock", "python/condameta", "python/wheelegg", "python/requirements"},
},
{
desc: "Remove duplicates",
names: []string{"python", "python"},
wantExts: []string{"python/pdmlock", "python/Pipfilelock", "python/poetrylock", "python/wheelegg", "python/requirements"},
wantExts: []string{"python/pdmlock", "python/Pipfilelock", "python/poetrylock", "python/condameta", "python/wheelegg", "python/requirements"},
},
{
desc: "Nonexistent plugin",
Expand Down

0 comments on commit 4ae5d2e

Please sign in to comment.