comparison env/lib/python3.9/site-packages/galaxy/tool_util/deps/mulled/mulled_build_channel.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 #!/usr/bin/env python
2 """Build a mulled images for all recent conda recipe updates that don't have existing images.
3
4 Examples:
5
6 Build mulled images for recent bioconda changes with:
7
8 mulled-build-channel build
9
10 Build, test, and publish images with the follow command:
11
12 mulled-build-channel all
13
14 See recent changes that would be built with:
15
16 mulled-build-channel list
17
18 """
19
20 import os
21 import subprocess
22 import sys
23 import time
24
25 import requests
26
27 from ._cli import arg_parser
28 from .mulled_build import (
29 add_build_arguments,
30 args_to_mull_targets_kwds,
31 build_target,
32 conda_versions,
33 get_affected_packages,
34 mull_targets,
35 )
36 from .util import quay_versions, version_sorted
37
38
39 def _fetch_repo_data(args):
40 repo_data = args.repo_data
41 channel = args.channel
42 if not os.path.exists(repo_data):
43 platform_tag = 'osx-64' if sys.platform == 'darwin' else 'linux-64'
44 subprocess.check_call([
45 'wget', '--quiet', f'https://conda.anaconda.org/{channel}/{platform_tag}/repodata.json.bz2',
46 '-O', '%s.bz2' % repo_data
47 ])
48 subprocess.check_call([
49 'bzip2', '-d', '%s.bz2' % repo_data
50 ])
51 return repo_data
52
53
54 def _new_versions(quay, conda):
55 """Calculate the versions that are in conda but not on quay.io."""
56 sconda = set(conda)
57 squay = set(quay) if quay else set()
58 return sconda - squay # sconda.symmetric_difference(squay)
59
60
61 def run_channel(args, build_last_n_versions=1):
62 """Build list of involucro commands (as shell snippet) to run."""
63 session = requests.session()
64 for pkg_name, pkg_tests in get_affected_packages(args):
65 repo_data = _fetch_repo_data(args)
66 c = conda_versions(pkg_name, repo_data)
67 # only package the most recent N versions
68 c = version_sorted(c)[:build_last_n_versions]
69
70 if not args.force_rebuild:
71 time.sleep(1)
72 q = quay_versions(args.namespace, pkg_name, session)
73 versions = _new_versions(q, c)
74 else:
75 versions = c
76
77 for tag in versions:
78 target = build_target(pkg_name, tag=tag)
79 targets = [target]
80 mull_targets(targets, test=pkg_tests, **args_to_mull_targets_kwds(args))
81
82
83 def get_pkg_names(args):
84 """Print package names that would be affected."""
85 print('\n'.join(pkg_name for pkg_name, pkg_tests in get_affected_packages(args)))
86
87
88 def add_channel_arguments(parser):
89 """Add arguments only used if running mulled over a whole conda channel."""
90 parser.add_argument('--repo-data', dest='repo_data', required=True,
91 help='Published repository data. If you want to build all containers for bioconda, this parameter needs to be set to "bioconda"')
92 parser.add_argument('--diff-hours', dest='diff_hours', default="25",
93 help='If finding all recently changed recipes, use this number of hours.')
94 parser.add_argument('--recipes-dir', dest="recipes_dir", default="./bioconda-recipes")
95 parser.add_argument('--force-rebuild', dest="force_rebuild", action="store_true",
96 help="Rebuild package even if already published.")
97
98
99 def main(argv=None):
100 """Main entry-point for the CLI tool."""
101 parser = arg_parser(argv, globals())
102 add_channel_arguments(parser)
103 add_build_arguments(parser)
104 parser.add_argument('command', metavar='COMMAND', help='Command (list, build-and-test, build, all)')
105 parser.add_argument('--targets', dest="targets", default=None, help="Build a single container with specific package(s).")
106 parser.add_argument('--repository-name', dest="repository_name", default=None, help="Name of a single container (leave blank to auto-generate based on packages).")
107 args = parser.parse_args()
108 if args.command == "list":
109 get_pkg_names(args)
110 else:
111 run_channel(args)
112
113
114 __all__ = ("main", )
115
116
117 if __name__ == '__main__':
118 main()