Skip to content

Commit 6395435

Browse files
committed
Detect Invoke as a task runner via tasks.py
1 parent 056d9c9 commit 6395435

2 files changed

Lines changed: 55 additions & 5 deletions

File tree

detect/detect_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,46 @@ func TestDetectSelfNotTriggeredOnOtherGoProjects(t *testing.T) {
548548
}
549549
}
550550

551+
func TestInvokeDetection(t *testing.T) {
552+
dir := t.TempDir()
553+
if err := os.WriteFile(filepath.Join(dir, "foo.py"), []byte("x = 1\n"), 0o644); err != nil {
554+
t.Fatal(err)
555+
}
556+
tasks := "from invoke import task\n\n@task\ndef build(c):\n c.run('true')\n"
557+
if err := os.WriteFile(filepath.Join(dir, "tasks.py"), []byte(tasks), 0o644); err != nil {
558+
t.Fatal(err)
559+
}
560+
561+
r, err := New(loadKB(t), dir).Run()
562+
if err != nil {
563+
t.Fatalf("unexpected error: %v", err)
564+
}
565+
566+
assertToolDetected(t, r, "build", "Invoke")
567+
for _, d := range r.Tools["build"] {
568+
if d.Name == "Invoke" {
569+
if d.Command == nil || d.Command.Run != "invoke --list" {
570+
t.Errorf("expected 'invoke --list' command, got %v", d.Command)
571+
}
572+
}
573+
}
574+
575+
// A tasks.py that doesn't import invoke should not trigger detection.
576+
celery := "from celery import shared_task\n\n@shared_task\ndef foo():\n pass\n"
577+
if err := os.WriteFile(filepath.Join(dir, "tasks.py"), []byte(celery), 0o644); err != nil {
578+
t.Fatal(err)
579+
}
580+
r, err = New(loadKB(t), dir).Run()
581+
if err != nil {
582+
t.Fatalf("unexpected error: %v", err)
583+
}
584+
for _, d := range r.Tools["build"] {
585+
if d.Name == "Invoke" {
586+
t.Error("tasks.py without invoke import should not trigger Invoke detection")
587+
}
588+
}
589+
}
590+
551591
func assertToolDetected(t *testing.T, r *brief.Report, category, name string) {
552592
t.Helper()
553593
tools, ok := r.Tools[category]

knowledge/python/invoke.toml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,28 @@
22
name = "Invoke"
33
category = "build"
44
homepage = "https://www.pyinvoke.org"
5-
docs = "https://www.pyinvoke.org"
5+
docs = "https://docs.pyinvoke.org"
66
repo = "https://github.com/pyinvoke/invoke"
7-
description = "Task execution and command running"
7+
description = "Pythonic task execution, like Make or Rake"
88

99
[detect]
10+
files = ["invoke.yaml", "invoke.yml", "invoke.json"]
1011
dependencies = ["invoke"]
1112
ecosystems = ["python"]
13+
[detect.file_contains]
14+
"tasks.py" = ["from invoke", "import invoke"]
15+
"tasks/__init__.py" = ["from invoke", "import invoke"]
16+
17+
[commands]
18+
run = "invoke --list"
19+
alternatives = ["inv --list"]
20+
21+
[config]
22+
files = ["tasks.py", "invoke.yaml", "invoke.yml", "invoke.json"]
1223

1324
[taxonomy]
14-
role = ["library"]
15-
function = ["process-execution", "automation"]
16-
layer = ["backend"]
25+
role = ["build-tool"]
26+
function = ["automation", "process-execution"]
1727

1828
[[security.sinks]]
1929
symbol = "Context.run"

0 commit comments

Comments
 (0)