|
1 | 1 | """ |
2 | 2 | Make Coiled software environments for stackstac in multiple regions, |
3 | 3 | 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. |
4 | 6 | """ |
5 | 7 |
|
6 | 8 | import asyncio |
|
9 | 11 | from pathlib import Path |
10 | 12 | import sys |
11 | 13 | from typing import List |
| 14 | +import warnings |
12 | 15 |
|
13 | 16 | import aiotools |
14 | 17 | import coiled |
@@ -79,23 +82,35 @@ async def make_coiled_stuff( |
79 | 82 | print(f"Created notebook {name}") |
80 | 83 |
|
81 | 84 |
|
| 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 | + |
82 | 91 | 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" |
91 | 94 |
|
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] |
98 | 113 |
|
99 | 114 | 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) |
101 | 116 | ) |
0 commit comments