Skip to content

Commit 87451a7

Browse files
feat: Add AGENTS.md and fix lint/format scripts (#4921)
This change adds a new `AGENTS.md` file to guide developers and agents through the complete setup process for this project. It also includes necessary fixes to the dependency installation and linting/formatting scripts to ensure they run correctly on modern systems and in CI/agent environments. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent b4915f8 commit 87451a7

File tree

4 files changed

+100
-4
lines changed

4 files changed

+100
-4
lines changed

AGENTS.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Agent Instructions
2+
3+
This document provides instructions for agents on how to perform common development tasks in this repository.
4+
5+
## Initial Setup
6+
7+
This project uses `asdf` to manage tool versions. Before you can install the project's dependencies, you need to install and configure `asdf`.
8+
9+
### 1. Install `asdf`
10+
11+
First, make sure you have `git` and `curl` installed. Then, clone the `asdf` repository:
12+
13+
```bash
14+
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
15+
```
16+
17+
### 2. Configure Your Shell
18+
19+
Add `asdf` to your shell's startup file. For `bash`, run:
20+
21+
```bash
22+
echo -e "\n. \"$HOME/.asdf/asdf.sh\"" >> ~/.bashrc
23+
```
24+
25+
Then, source your `.bashrc` to apply the changes to your current session:
26+
27+
```bash
28+
source ~/.bashrc
29+
```
30+
31+
### 3. Install `asdf` Plugins and Tools
32+
33+
Now, from the root of this project, run the following commands to install the necessary `asdf` plugins and the tools specified in the `.tool-versions` file:
34+
35+
```bash
36+
asdf plugin add python
37+
asdf plugin add gcloud https://github.com/jthegedus/asdf-gcloud
38+
asdf install
39+
```
40+
41+
### 4. Install `pipenv`
42+
43+
Once `asdf` has installed the correct python version, you need to install `pipenv`:
44+
45+
```bash
46+
python -m pip install pipenv
47+
```
48+
49+
### 5. Install Project Dependencies
50+
51+
Now you are ready to install the project's dependencies. Run the following command from the root of the repository:
52+
53+
```bash
54+
./local/install_deps.bash
55+
```
56+
57+
## Testing
58+
59+
To run all unit tests, execute the following commands:
60+
61+
```bash
62+
python butler.py py_unittest -t appengine -m
63+
python butler.py py_unittest -t core -m
64+
```
65+
66+
The `-m` flag runs the tests in parallel, which is recommended.
67+
68+
## Linting
69+
70+
To check the code for style and linting issues, run the following command:
71+
72+
```bash
73+
python butler.py lint
74+
```
75+
76+
This will lint the changed code in your current branch.
77+
78+
## Formatting
79+
80+
To automatically format the code to match the project's style guidelines, run:
81+
82+
```bash
83+
python butler.py format
84+
```
85+
86+
This will format the changed code in your current branch.

local/install_deps_linux.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fi
5454
# Check if the distro is supported.
5555
distro_codename=$(lsb_release --codename --short)
5656
distro_id=$(lsb_release --id --short)
57-
supported_codenames="(xenial|artful|bionic|cosmic|focal)"
57+
supported_codenames="(xenial|artful|bionic|cosmic|focal|noble)"
5858
supported_ids="(Debian)"
5959
if [[ ! $distro_codename =~ $supported_codenames &&
6060
! $distro_id =~ $supported_ids ]]; then

src/local/butler/format.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@
3030

3131
def execute(_):
3232
"""Format changed code."""
33-
_, output = common.execute('git diff --name-only FETCH_HEAD')
33+
if os.path.exists('.git/FETCH_HEAD'):
34+
diff_command = 'git diff --name-only FETCH_HEAD'
35+
else:
36+
# If not, fall back to diffing against HEAD.
37+
diff_command = 'git diff --name-only HEAD'
3438

39+
_, output = common.execute(diff_command)
3540
file_paths = [
3641
f.decode('utf-8') for f in output.splitlines() if os.path.exists(f)
3742
]

src/local/butler/lint.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,15 @@ def execute(args):
178178

179179
if 'GOOGLE_CLOUDBUILD' in os.environ:
180180
# Explicitly compare against master if we're running on the CI
181-
_, output = common.execute('git diff --name-only master FETCH_HEAD')
181+
diff_command = 'git diff --name-only master FETCH_HEAD'
182182
else:
183-
_, output = common.execute('git diff --name-only FETCH_HEAD')
183+
if os.path.exists('.git/FETCH_HEAD'):
184+
diff_command = 'git diff --name-only FETCH_HEAD'
185+
else:
186+
# If not, fall back to diffing against HEAD.
187+
diff_command = 'git diff --name-only HEAD'
184188

189+
_, output = common.execute(diff_command)
185190
file_paths = [
186191
f.decode('utf-8') for f in output.splitlines() if os.path.exists(f)
187192
]

0 commit comments

Comments
 (0)