Skip to content

Commit

Permalink
Fix problem with channel specification being wrongly exported
Browse files Browse the repository at this point in the history
fixes #62
  • Loading branch information
tadeu committed Jun 7, 2018
1 parent 6e34235 commit ea3345e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -94,3 +94,4 @@ ENV/


conda_devenv/_version.py
.pytest_cache
9 changes: 9 additions & 0 deletions HISTORY.rst
Expand Up @@ -2,6 +2,15 @@
History
=======

1.0.2 (2018-06-07)
------------------

* Fix problem with channel specification being wrongly exported (`#62`_).


.. _`#62`: https://github.com/ESSS/conda-devenv/issues/62


1.0.1 (2018-06-04)
------------------

Expand Down
19 changes: 14 additions & 5 deletions conda_devenv/devenv.py
Expand Up @@ -136,8 +136,12 @@ def merge_dependencies_version_specifications(yaml_dict, key_to_merge):
if value_to_merge is None:
return

# regex based on https://conda.io/docs/building/pkg-name-conv.html#package-naming-conventions
package_pattern = r'^([a-z0-9_\-.]+)\s*(.*)$'
package_pattern = (
r'^(?P<channel>[a-z0-9_\-/.]+::)?'
# package regex based on https://conda.io/docs/building/pkg-name-conv.html#package-naming-conventions
r'(?P<package>[a-z0-9_\-.]+)'
r'\s*(?P<version>.*)$'
)

new_dependencies = {}
new_dict_dependencies = []
Expand All @@ -151,11 +155,16 @@ def merge_dependencies_version_specifications(yaml_dict, key_to_merge):
if m is None:
raise RuntimeError('The package version specification "{}" do not follow the'
' expected format.'.format(dep))
# Consider the channel name as part of the package name. If multiple channels are specified, the package
# will be repeated.
package_name = m.group('package')
if m.group('channel'):
package_name = m.group('channel') + package_name

# OrderedDict is used as an ordered set, the value is ignored.
version_matchers = new_dependencies.setdefault(m.group(1), collections.OrderedDict())
if len(m.group(2)) > 0:
version_matchers[m.group(2)] = True
version_matchers = new_dependencies.setdefault(package_name, collections.OrderedDict())
if len(m.group('version')) > 0:
version_matchers[m.group('version')] = True
else:
raise RuntimeError("Only strings and dicts are supported, got: {!r}".format(dep))

Expand Down
6 changes: 6 additions & 0 deletions tests/test_main.py
Expand Up @@ -72,10 +72,13 @@ def test_print(tmpdir, input_name, capsys):
name: a
dependencies:
- a_dependency
- channel::another_dependency ==3.14
'''))
assert devenv.main(['--file', str(filename), '--quiet', '--print']) == 0
out, err = capsys.readouterr()
assert 'dependencies:' in out
assert '- a_dependency' in out
assert '- channel::another_dependency ==3.14' in out
assert 'name: a' in out


Expand All @@ -89,13 +92,16 @@ def test_print_full(tmpdir, capsys):
name: a
dependencies:
- a_dependency
- channel::another_dependency ==3.14
environment:
PYTHONPATH: {{ root }}/source
'''))
assert devenv.main(['--file', str(filename), '--quiet', '--print-full']) == 0
out, err = capsys.readouterr()
assert err == ''
assert 'dependencies:' in out
assert '- a_dependency' in out
assert '- channel::another_dependency ==3.14' in out
assert 'name: a' in out
assert 'environment:' in out
assert 'PYTHONPATH:' in out
Expand Down

0 comments on commit ea3345e

Please sign in to comment.