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