|
| 1 | +#!/usr/bin/env python |
| 2 | +import argparse as argpar |
| 3 | +import json |
| 4 | +import subprocess |
| 5 | + |
| 6 | +from setupbase import get_version |
| 7 | + |
| 8 | +VERSION_PY = 'jupyterlab_git/_version.py' |
| 9 | + |
| 10 | +def prepLabextensionBundle(): |
| 11 | + subprocess.run(['jlpm', 'clean:slate']) |
| 12 | + |
| 13 | +def tag(version, dryrun=False, kind=None): |
| 14 | + """git tagging |
| 15 | + """ |
| 16 | + kw = {'version': version, 'kind': kind} |
| 17 | + tag = '{kind}_v{version}'.format(**kw) if kind else 'v{version}'.format(**kw) |
| 18 | + |
| 19 | + if dryrun: |
| 20 | + print("Would tag: {}".format(tag)) |
| 21 | + else: |
| 22 | + subprocess.run(['git', 'tag', tag]) |
| 23 | + subprocess.run(['git', 'push', 'origin', tag]) |
| 24 | + |
| 25 | +def pypi(wheel=True, test=False): |
| 26 | + """release on pypi |
| 27 | + """ |
| 28 | + if wheel: |
| 29 | + # build the source (sdist) and binary wheel (bdist_wheel) releases |
| 30 | + subprocess.run(['python', 'setup.py', 'sdist', 'bdist_wheel']) |
| 31 | + else: |
| 32 | + # build just the source release |
| 33 | + subprocess.run(['python', 'setup.py', 'sdist']) |
| 34 | + |
| 35 | + if test: |
| 36 | + # release to the test server |
| 37 | + subprocess.run(['twine', 'upload', '--repository-url', 'https://test.pypi.org/legacy/', 'dist/*']) |
| 38 | + else: |
| 39 | + # release to the production server |
| 40 | + subprocess.run(['twine', 'upload', 'dist/*']) |
| 41 | + |
| 42 | +def npmjs(dryrun=False): |
| 43 | + """release on npmjs |
| 44 | + """ |
| 45 | + if dryrun: |
| 46 | + # dry run build and release |
| 47 | + subprocess.run(['npm', 'publish', '--access', 'public', '--dry-run']) |
| 48 | + else: |
| 49 | + # build and release |
| 50 | + subprocess.run(['npm', 'publish', '--access', 'public']) |
| 51 | + |
| 52 | +def labExtensionVersion(dryrun=False, version=None): |
| 53 | + if version: |
| 54 | + force_ver_cmd = ['npm', '--no-git-tag-version', 'version', version, '--force', '--allow-same-version'] |
| 55 | + if dryrun: |
| 56 | + print("Would force npm version with: {}".format(' '.join(force_ver_cmd))) |
| 57 | + else: |
| 58 | + # force the labextension version to match the supplied version |
| 59 | + subprocess.run(force_ver_cmd) |
| 60 | + else: |
| 61 | + # get single source of truth from the Typescript labextension |
| 62 | + with open('package.json') as f: |
| 63 | + info = json.load(f) |
| 64 | + |
| 65 | + version = info['version'] |
| 66 | + |
| 67 | + return version |
| 68 | + |
| 69 | +def serverExtensionVersion(): |
| 70 | + # get single source of truth from the Python serverextension |
| 71 | + return get_version(VERSION_PY) |
| 72 | + |
| 73 | +def doRelease(test=False): |
| 74 | + # prep the build area for the labextension bundle |
| 75 | + prepLabextensionBundle() |
| 76 | + |
| 77 | + # treat the serverextension version as the "real" single source of truth |
| 78 | + version = serverExtensionVersion() |
| 79 | + # force the labextension version to agree with the serverextension version |
| 80 | + labExtensionVersion(dryrun=test, version=version) |
| 81 | + |
| 82 | + # tag with version and push the tag |
| 83 | + tag(dryrun=test, version=version) |
| 84 | + |
| 85 | + # release to pypi and npmjs |
| 86 | + pypi(test=test) |
| 87 | + npmjs(dryrun=test) |
| 88 | + |
| 89 | +def main(): |
| 90 | + parser = argpar.ArgumentParser() |
| 91 | + |
| 92 | + parser.add_argument('--test', action='store_true', |
| 93 | + help='Release to Pypi test server; performs a dryrun of all other release actions') |
| 94 | + |
| 95 | + parsed = vars(parser.parse_args()) |
| 96 | + |
| 97 | + doRelease(test=parsed['test']) |
| 98 | + |
| 99 | +if __name__=='__main__': |
| 100 | + main() |
0 commit comments