Skip to content

Commit 9dd4e7b

Browse files
xuanyang15copybara-github
authored andcommitted
chore: Update check_new_py_files.sh to use absolute paths and exclude non-source directories
Co-authored-by: Xuan Yang <xygoogle@google.com> PiperOrigin-RevId: 953041397
1 parent 91038f2 commit 9dd4e7b

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

scripts/check_new_py_files.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
# limitations under the License.
1515

1616

17+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
18+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
19+
ADK_REAL_ROOT=$(dirname "$(realpath "$REPO_ROOT/src/google/adk/__init__.py")")
20+
EXCLUDE_TESTS="$ADK_REAL_ROOT/tests"
21+
EXCLUDE_WORKSPACE="$ADK_REAL_ROOT/open_source_workspace"
22+
EXCLUDE_CONTRIBUTING="$ADK_REAL_ROOT/contributing"
23+
1724
exit_code=0
1825

1926
get_added_files() {
@@ -33,11 +40,17 @@ get_added_files() {
3340
while read -r file; do
3441
# Check if file is not empty (happens if no new files)
3542
if [[ -n "$file" ]]; then
36-
# Match only files in the package source (src/google/adk/) to avoid false
37-
# positives in environments (e.g., monorepos) where the entire repository
38-
# root is nested under a 'google/adk/' directory structure.
39-
if [[ "$file" == */src/google/adk/*.py ]] || [[ "$file" == src/google/adk/*.py ]]; then
40-
filename=$(basename "$file")
43+
# Match only files in the package source (resolving symlinks to support both
44+
# open-source and internal layouts) and exclude tests/workspace to avoid
45+
# false positives.
46+
abs_file=$(realpath "$file" 2>/dev/null || echo "")
47+
if [[ -n "$abs_file" ]] && \
48+
[[ "$abs_file" == "$ADK_REAL_ROOT"/* ]] && \
49+
[[ "$abs_file" != "$EXCLUDE_TESTS"/* ]] && \
50+
[[ "$abs_file" != "$EXCLUDE_WORKSPACE"/* ]] && \
51+
[[ "$abs_file" != "$EXCLUDE_CONTRIBUTING"/* ]] && \
52+
[[ "$abs_file" == *.py ]]; then
53+
filename=$(basename "$abs_file")
4154
if [[ ! "$filename" == _* ]]; then
4255
echo "Error: New Python file '$file' must have a '_' prefix."
4356
echo "All new Python files in src/google/adk/ must be private by default."

0 commit comments

Comments
 (0)