Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/planemo/deps.py @ 5:9b1c78e6ba9c draft default tip
"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author | shellac |
---|---|
date | Mon, 01 Jun 2020 08:59:25 -0400 |
parents | 79f47841a781 |
children |
comparison
equal
deleted
inserted
replaced
4:79f47841a781 | 5:9b1c78e6ba9c |
---|---|
1 import tempfile | |
2 from string import Template | |
3 | |
4 import click | |
5 from six import iteritems | |
6 | |
7 from planemo.conda import build_conda_context | |
8 | |
9 CONDA_DEPENDENCY_RESOLUTION_CONF = """<dependency_resolvers> | |
10 <conda ${attributes} /> | |
11 <conda versionless="true" ${attributes} /> | |
12 </dependency_resolvers> | |
13 """ | |
14 | |
15 # Like Conda resolution above, but allow tool shed packages to be used for | |
16 # shed_serve and shed_test. | |
17 DEFAULT_DEPENDENCY_RESOLUTION_CONF = """<dependency_resolvers> | |
18 <tool_shed_packages /> | |
19 <conda ${attributes} /> | |
20 <conda versionless="true" ${attributes} /> | |
21 </dependency_resolvers> | |
22 """ | |
23 | |
24 NO_DEPENDENCY_RESOLUTION_CONF = """<dependency_resolvers> | |
25 </dependency_resolvers> | |
26 """ | |
27 | |
28 BREW_DEPENDENCY_RESOLUTION_CONF = """<dependency_resolvers> | |
29 <homebrew /> | |
30 <!-- | |
31 <homebrew versionless="true" /> | |
32 --> | |
33 </dependency_resolvers> | |
34 """ | |
35 | |
36 SHED_DEPENDENCY_RESOLUTION_CONF = """<dependency_resolvers> | |
37 <tool_shed_tap /> | |
38 </dependency_resolvers> | |
39 """ | |
40 | |
41 # Provide some shortcuts for simple/common dependency resolutions strategies. | |
42 STOCK_DEPENDENCY_RESOLUTION_STRATEGIES = { | |
43 "brew_dependency_resolution": BREW_DEPENDENCY_RESOLUTION_CONF, | |
44 "shed_dependency_resolution": SHED_DEPENDENCY_RESOLUTION_CONF, | |
45 "conda_dependency_resolution": CONDA_DEPENDENCY_RESOLUTION_CONF, | |
46 "no_dependency_resolution": NO_DEPENDENCY_RESOLUTION_CONF, | |
47 "default_dependency_resolution": DEFAULT_DEPENDENCY_RESOLUTION_CONF, | |
48 } | |
49 | |
50 | |
51 def ensure_dependency_resolvers_conf_configured(ctx, kwds, resolvers_conf=None): | |
52 """Use supplied CLI options (kwds) to find or build a dependency resolvers file. | |
53 | |
54 Set new path in kwds if needed. | |
55 """ | |
56 _validate_dependency_resolution_options(kwds) | |
57 always_specify_attribute = object() | |
58 | |
59 dependency_attribute_kwds = { | |
60 'conda_prefix': None, | |
61 'conda_exec': None, | |
62 'conda_debug': False, | |
63 'conda_copy_dependencies': False, | |
64 'conda_auto_init': always_specify_attribute, | |
65 'conda_auto_install': always_specify_attribute, | |
66 'conda_ensure_channels': '', | |
67 'conda_use_local': False, | |
68 } | |
69 attributes = [] | |
70 | |
71 def add_attribute(key, value): | |
72 attributes.append('%s="%s"' % (key, value)) | |
73 | |
74 conda_prefix_specified = False | |
75 for key, default_value in iteritems(dependency_attribute_kwds): | |
76 value = kwds.get(key, default_value) | |
77 if value != default_value: | |
78 conda_prefix_specified = conda_prefix_specified or (key == "conda_prefix") | |
79 # Strip leading prefix (conda_) off attributes | |
80 attribute_key = "_".join(key.split("_")[1:]) | |
81 add_attribute(attribute_key, value) | |
82 | |
83 conda_context = build_conda_context(ctx, **kwds) | |
84 if not conda_prefix_specified: | |
85 add_attribute("prefix", conda_context.conda_prefix) | |
86 add_attribute("condarc_override", conda_context.condarc_override) | |
87 | |
88 attribute_str = " ".join(attributes) | |
89 | |
90 if kwds.get("dependency_resolvers_config_file", None): | |
91 resolution_type = "__explicit__" | |
92 else: | |
93 resolution_type = "default_dependency_resolution" | |
94 for key in STOCK_DEPENDENCY_RESOLUTION_STRATEGIES: | |
95 if kwds.get(key): | |
96 resolution_type = key | |
97 | |
98 if resolution_type != "__explicit__": | |
99 # Planemo manages the dependency resolve conf file. | |
100 template_str = STOCK_DEPENDENCY_RESOLUTION_STRATEGIES[resolution_type] | |
101 conf_contents = Template(template_str).safe_substitute({ | |
102 'attributes': attribute_str | |
103 }) | |
104 if resolvers_conf is None: | |
105 resolvers_conf = tempfile.NamedTemporaryFile(delete=False).name | |
106 with open(resolvers_conf, "w") as fh: | |
107 fh.write(conf_contents) | |
108 ctx.vlog( | |
109 "Writing dependency_resolvers_config_file to path %s with contents [%s]", | |
110 resolvers_conf, | |
111 conf_contents, | |
112 ) | |
113 kwds["dependency_resolvers_config_file"] = resolvers_conf | |
114 | |
115 | |
116 def _validate_dependency_resolution_options(kwds): | |
117 resolutions_strategies = [ | |
118 "brew_dependency_resolution", | |
119 "dependency_resolvers_config_file", | |
120 "shed_dependency_resolution", | |
121 "conda_dependency_resolution", | |
122 ] | |
123 | |
124 selected_strategies = 0 | |
125 for key in resolutions_strategies: | |
126 if kwds.get(key): | |
127 selected_strategies += 1 | |
128 | |
129 if selected_strategies > 1: | |
130 message = "At most one option from [%s] may be specified" | |
131 raise click.UsageError(message % resolutions_strategies) |