|
| 1 | +############################################################################# |
| 2 | +# Copyright (c) 2018, QuantStack # |
| 3 | +# # |
| 4 | +# Distributed under the terms of the BSD 3-Clause License. # |
| 5 | +# # |
| 6 | +# The full license is in the file LICENSE, distributed with this software. # |
| 7 | +############################################################################# |
| 8 | + |
| 9 | +import json |
| 10 | +import click |
| 11 | +from pathlib import Path |
| 12 | +from jupyter_releaser.util import get_version, run |
| 13 | +from pkg_resources import parse_version |
| 14 | + |
| 15 | +def _update_version(version): |
| 16 | + HERE = Path(__file__).parent.parent.resolve() |
| 17 | + |
| 18 | + for settings in HERE.rglob("package.json"): |
| 19 | + try: |
| 20 | + with settings.open('r') as f: |
| 21 | + pckg_json = json.load(f) |
| 22 | + |
| 23 | + pckg_json['version'] = version |
| 24 | + |
| 25 | + with settings.open('w') as f: |
| 26 | + json.dump(pckg_json, f, indent=2) |
| 27 | + |
| 28 | + # Check version |
| 29 | + with settings.open('r') as f: |
| 30 | + ver = json.load(f)['version'] |
| 31 | + print("package.json version:", ver) |
| 32 | + |
| 33 | + return |
| 34 | + |
| 35 | + except FileNotFoundError: |
| 36 | + pass |
| 37 | + |
| 38 | + raise FileNotFoundError(f"Could not find package.json under dir {HERE!s}") |
| 39 | + |
| 40 | +@click.command() |
| 41 | +@click.argument("spec", nargs=1) |
| 42 | +def bump(spec): |
| 43 | + status = run("git status --porcelain").strip() |
| 44 | + if len(status) > 0: |
| 45 | + raise Exception("Must be in a clean git state with no untracked files") |
| 46 | + |
| 47 | + curr = parse_version(get_version()) |
| 48 | + |
| 49 | + if spec == 'next': |
| 50 | + spec = f"{curr.major}.{curr.minor}." |
| 51 | + if curr.pre: |
| 52 | + p, x = curr.pre |
| 53 | + spec += f"{curr.micro}{p}{x + 1}" |
| 54 | + else: |
| 55 | + spec += f"{curr.micro + 1}" |
| 56 | + |
| 57 | + elif spec == 'patch': |
| 58 | + spec = f"{curr.major}.{curr.minor}." |
| 59 | + if curr.pre: |
| 60 | + spec += f"{curr.micro}" |
| 61 | + else: |
| 62 | + spec += f"{curr.micro + 1}" |
| 63 | + |
| 64 | + |
| 65 | + version = parse_version(spec) |
| 66 | + |
| 67 | + # convert the Python version |
| 68 | + js_version = f"{version.major}.{version.minor}.{version.micro}" |
| 69 | + if version.pre: |
| 70 | + p, x = version.pre |
| 71 | + p = p.replace("a", "alpha").replace("b", "beta") |
| 72 | + js_version += f"-{p}.{x}" |
| 73 | + |
| 74 | + # bump the JS packages |
| 75 | + _update_version(js_version) |
| 76 | + |
| 77 | + |
| 78 | +if __name__ == "__main__": |
| 79 | + bump() |
0 commit comments