From fd61e194a283b0300b3d7fcd99548b04dff1dada Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Thu, 2 Dec 2021 13:39:56 -0700 Subject: [PATCH] [internal] `tailor` doesn't add `go_package` for `testdata` folder # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- src/python/pants/backend/go/goals/tailor.py | 6 +++++- src/python/pants/backend/go/goals/tailor_test.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/python/pants/backend/go/goals/tailor.py b/src/python/pants/backend/go/goals/tailor.py index c4bae3111af..fdd7b0c1ff9 100644 --- a/src/python/pants/backend/go/goals/tailor.py +++ b/src/python/pants/backend/go/goals/tailor.py @@ -6,6 +6,7 @@ import os import re from dataclasses import dataclass +from pathlib import PurePath from pants.backend.go.target_types import ( GoBinaryMainPackage, @@ -69,11 +70,14 @@ async def find_putative_go_targets( # Add `go_package` targets. unowned_go_files = set(all_go_files.files) - set(all_owned_sources) for dirname, filenames in group_by_dir(unowned_go_files).items(): + dir_path = PurePath(dirname) + if "testdata" in dir_path.parts: + continue putative_targets.append( PutativeTarget.for_target_type( GoPackageTarget, path=dirname, - name=os.path.basename(dirname), + name=dir_path.name, triggering_sources=sorted(filenames), ) ) diff --git a/src/python/pants/backend/go/goals/tailor_test.py b/src/python/pants/backend/go/goals/tailor_test.py index c0330e3167f..2aaa16e9fdc 100644 --- a/src/python/pants/backend/go/goals/tailor_test.py +++ b/src/python/pants/backend/go/goals/tailor_test.py @@ -76,6 +76,9 @@ def test_find_go_package_targets(rule_runner: RuleRunner) -> None: "unowned/f1.go": "", "owned/f.go": "", "owned/BUILD": "go_package()", + # Any `.go` files under a `testdata` folder should be ignored. + "unowned/testdata/f.go": "", + "unowned/testdata/subdir/f.go": "", } ) putative_targets = rule_runner.request(