|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import json |
| 4 | +import subprocess |
| 5 | + |
| 6 | +from setupbase import get_version |
| 7 | + |
| 8 | +def buildBundle(): |
| 9 | + subprocess.run(['jlpm', 'clean:slate']) |
| 10 | + subprocess.run(['jlpm', 'build:labextension']) |
| 11 | + |
| 12 | +def tag(version, kind=None): |
| 13 | + """git tagging |
| 14 | + """ |
| 15 | + kw = {'version': version, 'kind': kind} |
| 16 | + tag = "{kind}_v{version}".format(**kw) if kind else "v{version}".format(**kw) |
| 17 | + |
| 18 | + subprocess.run(['git', 'tag', tag]) |
| 19 | + subprocess.run(['git', 'push', 'origin', tag]) |
| 20 | + |
| 21 | +def pypi(bdist=True, test=False): |
| 22 | + """release on pypi |
| 23 | + """ |
| 24 | + if bdist: |
| 25 | + # build the source (sdist) and binary wheel (bdist) releases |
| 26 | + subprocess.run(['python', 'setup.py', 'sdist', 'bdist_wheel']) |
| 27 | + else: |
| 28 | + # build just the source release |
| 29 | + subprocess.run(['python', 'setup.py', 'sdist']) |
| 30 | + |
| 31 | + if test: |
| 32 | + # release to the test server |
| 33 | + subprocess.run(['twine', 'upload', '--repository-url', 'https://test.pypi.org/legacy/', 'dist/*']) |
| 34 | + else: |
| 35 | + # release to the production server |
| 36 | + subprocess.run(['twine', 'upload', 'dist/*']) |
| 37 | + |
| 38 | +def npmjs(dryRun=False): |
| 39 | + """release on npmjs |
| 40 | + """ |
| 41 | + if dryRun: |
| 42 | + # dry run build and release |
| 43 | + subprocess.run(['npm', 'publish', '--access', 'public', '--dry-run']) |
| 44 | + else: |
| 45 | + # build and release |
| 46 | + subprocess.run(['npm', 'publish', '--access', 'public']) |
| 47 | + |
| 48 | +def labExtensionVersion(version=None): |
| 49 | + if version: |
| 50 | + # force the labextension version to match the supplied version |
| 51 | + subprocess.run(['npm', '--no-git-tag-version', 'version', version, '--force', '--allow-same-version']) |
| 52 | + else: |
| 53 | + # get single source of truth from the Typescript labextension |
| 54 | + with open('package.json') as f: |
| 55 | + info = json.load(f) |
| 56 | + |
| 57 | + version = info['version'] |
| 58 | + |
| 59 | + return version |
| 60 | + |
| 61 | +def serverExtensionVersion(): |
| 62 | + # get single source of truth from the Python serverextension |
| 63 | + return get_version('jupyterlab_hdf/_version.py') |
| 64 | + |
| 65 | +def doRelease(): |
| 66 | + # do a clean build of the bundle |
| 67 | + buildBundle() |
| 68 | + |
| 69 | + # treat the serverextension version as the "real" single source of truth |
| 70 | + version = serverExtensionVersion() |
| 71 | + # force the labextension version to agree with the serverextension version |
| 72 | + labExtensionVersion(version=version) |
| 73 | + |
| 74 | + # tag with version and push the tag |
| 75 | + tag(version=version) |
| 76 | + |
| 77 | + # release to pypi and npmjs |
| 78 | + pypi() |
| 79 | + npmjs() |
| 80 | + |
| 81 | +if __name__=="__main__": |
| 82 | + doRelease() |
0 commit comments