|
14 | 14 | import subprocess
|
15 | 15 | import sys
|
16 | 16 | import zipfile
|
| 17 | +import hashlib |
| 18 | +import urllib.request as request |
17 | 19 |
|
18 | 20 | from datetime import date
|
19 | 21 | from os import chdir, makedirs
|
|
24 | 26 |
|
25 | 27 | PY2 = sys.version_info[0] < 3
|
26 | 28 | TMP_PATH = r"c:\tmp\larray_new_release"
|
27 |
| - |
| 29 | +TMP_PATH_CONDA = r"c:\tmp\larray_conda_new_release" |
| 30 | +LARRAY_REP = 'https://github.com/liam2/larray' |
| 31 | +CONDA_LARRAY_FEEDSTOCK_REP = 'https://github.com/larray-project/larray-feedstock.git' |
28 | 32 |
|
29 | 33 | try:
|
30 | 34 | input = raw_input
|
@@ -411,6 +415,47 @@ def update_changelog(context):
|
411 | 415 | call('git commit -m "update release date in changes.rst" {}'.format(fpath))
|
412 | 416 |
|
413 | 417 |
|
| 418 | +def update_conda_forge_package(context): |
| 419 | + create_tmp_directory(context) |
| 420 | + |
| 421 | + try: |
| 422 | + # compute sha256 |
| 423 | + url = LARRAY_REP + '/archive/{version}.tar.gz'.format(version=short(context['release_name'])) |
| 424 | + print('Computing SHA256 from archive {}'.format(url), end=' ') |
| 425 | + with request.urlopen(url) as response: |
| 426 | + sha256 = hashlib.sha256(response.read()).hexdigest() |
| 427 | + print('done.') |
| 428 | + print('SHA256: ', sha256) |
| 429 | + |
| 430 | + # clone repository |
| 431 | + clone_repository(context) |
| 432 | + |
| 433 | + chdir(context['build_dir']) |
| 434 | + |
| 435 | + # set version and sha256 in meta.yml file |
| 436 | + meta_file = r'recipe\meta.yaml' |
| 437 | + with open(meta_file, 'r') as f: |
| 438 | + lines = open(meta_file, 'r').readlines() |
| 439 | + lines[1] = '{{% set version = "{release_name}" %}}\n'.format(**context) |
| 440 | + lines[2] = '{{% set sha256 = "{sha256}" %}}\n'.format(sha256=sha256) |
| 441 | + with open(meta_file, 'w') as f: |
| 442 | + f.writelines(lines) |
| 443 | + # add, commit and push |
| 444 | + print(call('git status -s')) |
| 445 | + print(call('git diff {meta_file}'.format(meta_file=meta_file))) |
| 446 | + if no('Does that last changes look right?'): |
| 447 | + exit(1) |
| 448 | + do('Adding', call, 'git add {}'.format(meta_file)) |
| 449 | + do('Commiting', call, 'git commit -m "bump to version {release_name}"'.format(**context)) |
| 450 | + print(call('git log -1')) |
| 451 | + do('Pushing to GitHub', call, 'git push origin {branch}'.format(**context)) |
| 452 | + # delete temporary directory |
| 453 | + cleanup(context) |
| 454 | + except Exception as e: |
| 455 | + cleanup(context) |
| 456 | + raise e |
| 457 | + |
| 458 | + |
414 | 459 | def build_doc(context):
|
415 | 460 | chdir(context['build_dir'])
|
416 | 461 | chdir('doc')
|
@@ -480,6 +525,7 @@ def cleanup(context):
|
480 | 525 | (create_archives, 'Creating archives'),
|
481 | 526 | (final_confirmation, ''),
|
482 | 527 | (tag_release, 'Tagging release'),
|
| 528 | + (update_conda_forge_package, ''), |
483 | 529 | # We used to push from /tmp to the local repository but you cannot push
|
484 | 530 | # to the currently checked out branch of a repository, so we need to
|
485 | 531 | # pull changes instead. However pull (or merge) add changes to the
|
@@ -530,20 +576,27 @@ def make_release(release_name='dev', steps=':', branch='master'):
|
530 | 576 | 'tmp_dir': TMP_PATH,
|
531 | 577 | 'build_dir': os.path.join(TMP_PATH, 'build'),
|
532 | 578 | 'public_release': public_release}
|
| 579 | + context_conda = {'branch': branch, |
| 580 | + 'release_name': release_name, |
| 581 | + 'rev': rev, |
| 582 | + 'repository': CONDA_LARRAY_FEEDSTOCK_REP, |
| 583 | + 'tmp_dir': TMP_PATH_CONDA, |
| 584 | + 'build_dir': os.path.join(TMP_PATH, 'build'), |
| 585 | + 'public_release': public_release} |
| 586 | + |
533 | 587 | for step_func, step_desc in steps_funcs[start:stop]:
|
| 588 | + ctx = context_conda if step_func == update_conda_forge_package else context |
534 | 589 | if step_desc:
|
535 |
| - do(step_desc, step_func, context) |
| 590 | + do(step_desc, step_func, ctx) |
536 | 591 | else:
|
537 |
| - step_func(context) |
| 592 | + step_func(ctx) |
538 | 593 |
|
539 | 594 |
|
540 | 595 | if __name__ == '__main__':
|
541 | 596 | argv = sys.argv
|
542 |
| - # if len(argv) < 2: |
543 |
| - # print("Usage: {} release_name|dev [step|startstep:stopstep] [branch]".format(argv[0])) |
544 |
| - # print("steps:", ', '.join(f.__name__ for f, _ in steps_funcs)) |
545 |
| - # sys.exit() |
546 |
| - # |
547 |
| - # make_release(*argv[1:]) |
548 |
| - |
549 |
| - run_tests() |
| 597 | + if len(argv) < 2: |
| 598 | + print("Usage: {} release_name|dev [step|startstep:stopstep] [branch]".format(argv[0])) |
| 599 | + print("steps:", ', '.join(f.__name__ for f, _ in steps_funcs)) |
| 600 | + sys.exit() |
| 601 | + |
| 602 | + make_release(*argv[1:]) |
0 commit comments