From a67421228d25ef3333c674a367fd10b076167c07 Mon Sep 17 00:00:00 2001 From: Bill Little Date: Wed, 10 Aug 2016 14:31:37 +0100 Subject: [PATCH 1/2] Configure url and summary of a taggedenv and env. --- conda_rpms/build_rpm_structure.py | 10 +++++++-- conda_rpms/config.yaml.example | 8 +++++++ conda_rpms/generate.py | 35 ++++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/conda_rpms/build_rpm_structure.py b/conda_rpms/build_rpm_structure.py index 4826e98..219986c 100644 --- a/conda_rpms/build_rpm_structure.py +++ b/conda_rpms/build_rpm_structure.py @@ -58,12 +58,18 @@ def __getitem__(self, key): except KeyError: emsg = 'The YAML file {!r} does not contain key [{}].' full_key = ']['.join(self._key + [key]) - raise ValueError(emsg.format(os.path.basename(self.fname), - full_key)) + raise KeyError(emsg.format(os.path.basename(self.fname), + full_key)) if isinstance(result, dict): result = Config(self.fname, result, self._key + [key]) return result + def get(self, key, default=None): + return self._store.get(key, default) + + def __contains__(self, key): + return key in self._store + def __iter__(self): return iter(self._store) diff --git a/conda_rpms/config.yaml.example b/conda_rpms/config.yaml.example index 8d062dc..e2ac367 100644 --- a/conda_rpms/config.yaml.example +++ b/conda_rpms/config.yaml.example @@ -3,3 +3,11 @@ rpm: install: prefix: '/opt/scitools' + +taggedenv: + url: 'http://link/to/gh' + summary: 'The {{ name }}-{{ tag }} environment.' + +env: + url: 'http://link/to/gh' + summary: 'The {{ name }}-{{ label }} to {{ name }}-{{ tag }} environment.' diff --git a/conda_rpms/generate.py b/conda_rpms/generate.py index c4c44f9..be82c12 100644 --- a/conda_rpms/generate.py +++ b/conda_rpms/generate.py @@ -49,26 +49,47 @@ def render_dist_spec(dist, config): rpm_prefix=rpm_prefix, install_prefix=install_prefix) + def render_env(branch_name, label, repo, config, tag, commit_num): - env_info = {'url': 'http://link/to/gh', - 'name': branch_name, + url, summary = None, None + if 'env' in config: + config_env = config['env'] + url = config_env.get('url') + summary = config_env.get('summary') + if summary is None: + summary = 'The {{name}}-{{label}} to {{name}}-{{tag}} environment.' + labelled_tag = tag.split('-')[-1] + summary = env.from_string(summary).render(name=branch_name, label=label, + tag=labelled_tag) + env_info = {'name': branch_name, 'label' : label, - 'summary': 'A SciTools environment.', + 'summary': summary, 'version': commit_num,} + if url is not None: + env_info['url'] = url install_prefix = config['install']['prefix'] rpm_prefix = config['rpm']['prefix'] return env_spec_tmpl.render(install_prefix=install_prefix, rpm_prefix=rpm_prefix, env=env_info, - labelled_tag=tag.split('-')[-1]) + labelled_tag=labelled_tag) def render_taggedenv(env_name, tag, pkgs, config, env_spec): - env_info = {'url': 'http://link/to/gh', - 'name': env_name, + url, summary = None, None + if 'taggedenv' in config: + config_taggedenv = config['taggedenv'] + url = config_taggedenv.get('url') + summary = config_taggedenv.get('summary') + if summary is None: + summary = 'The {{ name }}-{{ tag }} environment.' + summary = env.from_string(summary).render(name=env_name, tag=tag) + env_info = {'name': env_name, 'tag': tag, - 'summary': 'An environment in which to rejoice.', + 'summary': summary, 'version': '1', 'spec': '\n'.join(env_spec)} + if url is not None: + env_info['url'] = url rpm_prefix = config['rpm']['prefix'] install_prefix = config['install']['prefix'] return taggedenv_spec_tmpl.render(install_prefix=install_prefix, From c20b176b2f29c39ab85da5c5fdace20d03bfae63 Mon Sep 17 00:00:00 2001 From: Bill Little Date: Wed, 10 Aug 2016 15:17:08 +0100 Subject: [PATCH 2/2] Remove url configuration. --- conda_rpms/config.yaml.example | 2 -- conda_rpms/generate.py | 16 ++++------------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/conda_rpms/config.yaml.example b/conda_rpms/config.yaml.example index e2ac367..8ffda31 100644 --- a/conda_rpms/config.yaml.example +++ b/conda_rpms/config.yaml.example @@ -5,9 +5,7 @@ install: prefix: '/opt/scitools' taggedenv: - url: 'http://link/to/gh' summary: 'The {{ name }}-{{ tag }} environment.' env: - url: 'http://link/to/gh' summary: 'The {{ name }}-{{ label }} to {{ name }}-{{ tag }} environment.' diff --git a/conda_rpms/generate.py b/conda_rpms/generate.py index be82c12..30956a3 100644 --- a/conda_rpms/generate.py +++ b/conda_rpms/generate.py @@ -51,11 +51,9 @@ def render_dist_spec(dist, config): def render_env(branch_name, label, repo, config, tag, commit_num): - url, summary = None, None + summary = None if 'env' in config: - config_env = config['env'] - url = config_env.get('url') - summary = config_env.get('summary') + summary = config['env'].get('summary') if summary is None: summary = 'The {{name}}-{{label}} to {{name}}-{{tag}} environment.' labelled_tag = tag.split('-')[-1] @@ -65,8 +63,6 @@ def render_env(branch_name, label, repo, config, tag, commit_num): 'label' : label, 'summary': summary, 'version': commit_num,} - if url is not None: - env_info['url'] = url install_prefix = config['install']['prefix'] rpm_prefix = config['rpm']['prefix'] return env_spec_tmpl.render(install_prefix=install_prefix, @@ -75,11 +71,9 @@ def render_env(branch_name, label, repo, config, tag, commit_num): def render_taggedenv(env_name, tag, pkgs, config, env_spec): - url, summary = None, None + summary = None if 'taggedenv' in config: - config_taggedenv = config['taggedenv'] - url = config_taggedenv.get('url') - summary = config_taggedenv.get('summary') + summary = config['taggedenv'].get('summary') if summary is None: summary = 'The {{ name }}-{{ tag }} environment.' summary = env.from_string(summary).render(name=env_name, tag=tag) @@ -88,8 +82,6 @@ def render_taggedenv(env_name, tag, pkgs, config, env_spec): 'summary': summary, 'version': '1', 'spec': '\n'.join(env_spec)} - if url is not None: - env_info['url'] = url rpm_prefix = config['rpm']['prefix'] install_prefix = config['install']['prefix'] return taggedenv_spec_tmpl.render(install_prefix=install_prefix,