Making exclusions more strict (#1054)

diff --git a/gazelle/python/configure.go b/gazelle/python/configure.go
index 901c226..32f9ab0 100644
--- a/gazelle/python/configure.go
+++ b/gazelle/python/configure.go
@@ -103,7 +103,7 @@
 		case "exclude":
 			// We record the exclude directive for coarse-grained packages
 			// since we do manual tree traversal in this mode.
-			config.AddExcludedPattern(strings.TrimSpace(d.Value))
+			config.AddExcludedPattern(filepath.Join(rel, strings.TrimSpace(d.Value)))
 		case pythonconfig.PythonExtensionDirective:
 			switch d.Value {
 			case "enabled":
diff --git a/gazelle/python/generate.go b/gazelle/python/generate.go
index 3d63124..26ffeda 100644
--- a/gazelle/python/generate.go
+++ b/gazelle/python/generate.go
@@ -161,13 +161,14 @@
 				}
 				if filepath.Ext(path) == ".py" {
 					if cfg.CoarseGrainedGeneration() || !isEntrypointFile(path) {
-						f, _ := filepath.Rel(args.Dir, path)
+						srcPath, _ := filepath.Rel(args.Dir, path)
+						repoPath := filepath.Join(args.Rel, srcPath)
 						excludedPatterns := cfg.ExcludedPatterns()
 						if excludedPatterns != nil {
 							it := excludedPatterns.Iterator()
 							for it.Next() {
 								excludedPattern := it.Value().(string)
-								isExcluded, err := doublestar.Match(excludedPattern, f)
+								isExcluded, err := doublestar.Match(excludedPattern, repoPath)
 								if err != nil {
 									return err
 								}
@@ -178,9 +179,9 @@
 						}
 						baseName := filepath.Base(path)
 						if strings.HasSuffix(baseName, "_test.py") || strings.HasPrefix(baseName, "test_") {
-							pyTestFilenames.Add(f)
+							pyTestFilenames.Add(srcPath)
 						} else {
-							pyLibraryFilenames.Add(f)
+							pyLibraryFilenames.Add(srcPath)
 						}
 					}
 				}
diff --git a/gazelle/python/python_test.go b/gazelle/python/python_test.go
index e8edf89..51e0101 100644
--- a/gazelle/python/python_test.go
+++ b/gazelle/python/python_test.go
@@ -23,7 +23,6 @@
 	"bytes"
 	"context"
 	"errors"
-	"fmt"
 	"os"
 	"os/exec"
 	"path/filepath"
@@ -33,7 +32,6 @@
 
 	"github.com/bazelbuild/bazel-gazelle/testtools"
 	"github.com/bazelbuild/rules_go/go/tools/bazel"
-	"github.com/emirpasic/gods/lists/singlylinkedlist"
 	"github.com/ghodss/yaml"
 )
 
@@ -161,31 +159,23 @@
 				t.Fatal(err)
 			}
 		}
-		errs := singlylinkedlist.New()
+
 		actualExitCode := cmd.ProcessState.ExitCode()
 		if config.Expect.ExitCode != actualExitCode {
-			errs.Add(fmt.Errorf("expected gazelle exit code: %d\ngot: %d",
-				config.Expect.ExitCode, actualExitCode,
-			))
+			t.Errorf("expected gazelle exit code: %d\ngot: %d",
+				config.Expect.ExitCode, actualExitCode)
 		}
 		actualStdout := stdout.String()
 		if strings.TrimSpace(config.Expect.Stdout) != strings.TrimSpace(actualStdout) {
-			errs.Add(fmt.Errorf("expected gazelle stdout: %s\ngot: %s",
-				config.Expect.Stdout, actualStdout,
-			))
+			t.Errorf("expected gazelle stdout: %s\ngot: %s",
+				config.Expect.Stdout, actualStdout)
 		}
 		actualStderr := stderr.String()
 		if strings.TrimSpace(config.Expect.Stderr) != strings.TrimSpace(actualStderr) {
-			errs.Add(fmt.Errorf("expected gazelle stderr: %s\ngot: %s",
-				config.Expect.Stderr, actualStderr,
-			))
+			t.Errorf("expected gazelle stderr: %s\ngot: %s",
+				config.Expect.Stderr, actualStderr)
 		}
-		if !errs.Empty() {
-			errsIt := errs.Iterator()
-			for errsIt.Next() {
-				err := errsIt.Value().(error)
-				t.Log(err)
-			}
+		if t.Failed() {
 			t.FailNow()
 		}
 
diff --git a/gazelle/python/testdata/monorepo/a/BUILD.in b/gazelle/python/testdata/monorepo/a/BUILD.in
new file mode 100644
index 0000000..265129e
--- /dev/null
+++ b/gazelle/python/testdata/monorepo/a/BUILD.in
@@ -0,0 +1 @@
+# gazelle:exclude bar/baz/hue.py
\ No newline at end of file
diff --git a/gazelle/python/testdata/monorepo/a/BUILD.out b/gazelle/python/testdata/monorepo/a/BUILD.out
new file mode 100644
index 0000000..265129e
--- /dev/null
+++ b/gazelle/python/testdata/monorepo/a/BUILD.out
@@ -0,0 +1 @@
+# gazelle:exclude bar/baz/hue.py
\ No newline at end of file
diff --git a/gazelle/python/testdata/monorepo/a/README.md b/gazelle/python/testdata/monorepo/a/README.md
new file mode 100644
index 0000000..84d3bff
--- /dev/null
+++ b/gazelle/python/testdata/monorepo/a/README.md
@@ -0,0 +1,3 @@
+# Exclusions
+* Intentionally make the directory "a" so Gazelle visit this before "coarse_grained"
+* Making sure that the exclusion here doesn't affect coarse_grained/bar/baz/hue.py
\ No newline at end of file