Skip to content

Commit 9fc276a

Browse files
committed
Add blacken script and format fixes
blacken.sh can be used by developers to run format on the python source files in the repo. The scope of files it runs on is limited at the moment since running black on the jax files results in large diffs which makes it hard to track changes from upstream. Eventually when the PJRT stuff is fully integrated to the repo we can run it on those. The jaxlib kernels is still an open question. The script will pass any args it receives to the inner black command so args like --diff and --check work.
1 parent bb43aa2 commit 9fc276a

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

build/ci_build

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ def test(image_name, test_cmd=None):
153153
cmd.extend(mounts)
154154
cmd.extend(gpu_args)
155155

156-
container_cmd = (
157-
"cd /jax && %s" % test_cmd
158-
)
156+
container_cmd = "cd /jax && %s" % test_cmd
159157

160158
cmd.append(image_name)
161159
cmd.extend(
@@ -229,7 +227,9 @@ def parse_args():
229227
bdp = subp.add_parser("build_dockers")
230228

231229
testp = subp.add_parser("test")
232-
testp.add_argument("--test-cmd", help="Command which will be run inside the test container")
230+
testp.add_argument(
231+
"--test-cmd", help="Command which will be run inside the test container"
232+
)
233233
testp.add_argument("image_name")
234234

235235
return p.parse_args()

stack.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ def setup_development(jax_ref: str, xla_ref: str, rebuild_makefile: bool = False
112112
mf.write(makefile_content)
113113

114114

115-
116115
def dev_docker():
117116
cur_abs_path = os.path.abspath(os.curdir)
118117
image_name = "ubuntu:22.04"
@@ -128,17 +127,20 @@ def dev_docker():
128127
"--device=/dev/dri",
129128
"--ipc=host",
130129
"--shm-size=16G",
131-
"--group-add", "video",
130+
"--group-add",
131+
"video",
132132
"--cap-add=SYS_PTRACE",
133-
"--security-opt", "seccomp=unconfined",
133+
"--security-opt",
134+
"seccomp=unconfined",
134135
"-v",
135136
"%s:/rocm-jax" % cur_abs_path,
136-
"--env", "ROCM_JAX_DIR=/rocm-jax",
137-
"--env", "_IS_ENTRYPOINT=1",
138-
"--entrypoint=%s" % ep
137+
"--env",
138+
"ROCM_JAX_DIR=/rocm-jax",
139+
"--env",
140+
"_IS_ENTRYPOINT=1",
141+
"--entrypoint=%s" % ep,
139142
]
140143

141-
142144
cmd.append(image_name)
143145

144146
p = subprocess.Popen(cmd)
@@ -147,6 +149,7 @@ def dev_docker():
147149

148150
# build mode setup
149151

152+
150153
# install jax/jaxlib from known versions
151154
# setup build/install/test script
152155
def setup_build():
@@ -159,14 +162,27 @@ def parse_args():
159162
subp = p.add_subparsers(dest="action", required=True)
160163

161164
dev = subp.add_parser("develop")
162-
dev.add_argument("--rebuild-makefile", help="Force rebuild of Makefile from template.", action="store_true")
163-
dev.add_argument("--xla-ref", help="XLA commit reference to checkout on clone", default=XLA_REPO_REF)
164-
dev.add_argument("--jax-ref", help="JAX commit reference to checkout on clone", default=JAX_REPO_REF)
165+
dev.add_argument(
166+
"--rebuild-makefile",
167+
help="Force rebuild of Makefile from template.",
168+
action="store_true",
169+
)
170+
dev.add_argument(
171+
"--xla-ref",
172+
help="XLA commit reference to checkout on clone",
173+
default=XLA_REPO_REF,
174+
)
175+
dev.add_argument(
176+
"--jax-ref",
177+
help="JAX commit reference to checkout on clone",
178+
default=JAX_REPO_REF,
179+
)
165180

166181
docker = subp.add_parser("docker")
167182

168183
return p.parse_args()
169184

185+
170186
def main():
171187
args = parse_args()
172188
if args.action == "docker":

tools/blacken.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
FILES=(
4+
build/ci_build
5+
stack.py
6+
)
7+
8+
FILES+=($(find build -name "*.py"))
9+
FILES+=($(find tools -name "*.py"))
10+
11+
black -t py36 $* ${FILES[@]}

0 commit comments

Comments
 (0)