Skip to content

Commit b161aa2

Browse files
committed
dev flag for coiled script
1 parent 710eafc commit b161aa2

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

scripts/coiled-envs.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
Make Coiled software environments for stackstac in multiple regions,
33
and upload all notebook files into a Coiled notebook (aka Job).
4+
5+
Pass --dev to build off the latest commit on `origin/main` instead.
46
"""
57

68
import asyncio
@@ -9,6 +11,7 @@
911
from pathlib import Path
1012
import sys
1113
from typing import List
14+
import warnings
1215

1316
import aiotools
1417
import coiled
@@ -79,23 +82,35 @@ async def make_coiled_stuff(
7982
print(f"Created notebook {name}")
8083

8184

85+
def run(cmd: str, **kwargs) -> str:
86+
return subprocess.run(
87+
cmd, shell=True, check=True, capture_output=True, text=True, **kwargs
88+
).stdout.strip()
89+
90+
8291
if __name__ == "__main__":
83-
proc = subprocess.run(
84-
"poetry export --without-hashes -E binder -E viz",
85-
shell=True,
86-
check=True,
87-
capture_output=True,
88-
text=True,
89-
)
90-
deps = proc.stdout.splitlines()
92+
# TODO use click or something to make an actual CLI.
93+
dev = len(sys.argv) == 2 and sys.argv[-1] == "--dev"
9194

92-
# TODO single-source the version! this is annoying
93-
version = subprocess.run(
94-
"poetry version -s", shell=True, check=True, capture_output=True, text=True
95-
).stdout.strip()
96-
print(f"Version: {version}")
97-
deps += [f"stackstac[binder,viz]=={version}"]
95+
deps = run("poetry export --without-hashes -E binder -E viz").splitlines()
96+
97+
if dev:
98+
name = "stackstac-dev"
99+
subprocess.run("git fetch", shell=True, check=True)
100+
main = run("git rev-parse main")
101+
origin_main = run("git rev-parse origin/main")
102+
if main != origin_main:
103+
warnings.warn("Your local main branch is not up to date with origin/main")
104+
print(f"Commit (origin/main): {origin_main}")
105+
stackstac_dep = f"git+https://github.com/gjoseph92/stackstac.git@{origin_main}#egg=stackstac[binder,viz]"
106+
else:
107+
name = "stackstac"
108+
# TODO single-source the version! this is annoying
109+
version = run("poetry version -s")
110+
print(f"Version: {version}")
111+
stackstac_dep = f"stackstac[binder,viz]=={version}"
112+
deps += [stackstac_dep]
98113

99114
asyncio.run(
100-
make_coiled_stuff(deps, regions=["us-west-2", "eu-central-1"], name="stackstac")
115+
make_coiled_stuff(deps, regions=["us-west-2", "eu-central-1"], name=name)
101116
)

0 commit comments

Comments
 (0)