Skip to content

Commit

Permalink
Merge pull request #58 from jacebrowning/double-pipe
Browse files Browse the repository at this point in the history
Switch to double pipe for separating versions
  • Loading branch information
jacebrowning committed Apr 25, 2019
2 parents 520f165 + d8e5dcb commit c27fb6c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Unreleased

- Deprecated `versions` in favor of `version` option.
- Deprecated `|` in favor of `||` for checking multiple versions.

# 1.6.2 (2019-02-15)

- Fixed handling of programs that produce output with file paths.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ version = 1.2
[Newer Working Program]

cli = working-program
versions = 4.1 | 4.2
version = 4.1 || 4.2
message = Version 4.x is required to get the special features.

[Broken Program]
Expand Down Expand Up @@ -77,7 +77,7 @@ Checking for Newer Working Program...
$ working-program --version
1.2.3
✘ EXPECTED: 4.1 | 4.2
✘ EXPECTED: 4.1 || 4.2
⭑ MESSAGE: Version 4.x is required to get the special features.
Checking for Broken Program...
Expand Down
4 changes: 2 additions & 2 deletions docs/cli/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ version = 16

# Multiple Versions

If your project can use multiple versions of a system dependency, use the `versions` setting and separate versions with the pipe character (`|`):
If your project can work with more than one version of a system dependency, separate them with a double pipe (`||`) symbol:

```ini
[Python]

cli = python
versions = Python 2 | Python 3
version = Python 2 || Python 3
```

# Optional Programs
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
$ working-program --version
1.2.3
✘ EXPECTED: 4.1 | 4.2
✘ EXPECTED: 4.1 || 4.2
⭑ MESSAGE: Version 4.x is required to get the special features.
Checking for Broken Program...
Expand Down Expand Up @@ -68,7 +68,7 @@
$ working-program --version
sh: command not found: working-program
x EXPECTED: 4.1 | 4.2
x EXPECTED: 4.1 || 4.2
* MESSAGE: Version 4.x is required to get the special features.
Checking for Broken Program...
Expand Down
30 changes: 23 additions & 7 deletions verchew/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import os
import re
import sys
import warnings
from collections import OrderedDict
from subprocess import PIPE, STDOUT, Popen

Expand All @@ -58,7 +59,7 @@
[Python]
cli = python
versions = Python 3.5 | Python 3.6
version = Python 3.5 || Python 3.6
[Legacy Python]
Expand Down Expand Up @@ -198,9 +199,24 @@ def parse_config(path):
data[section][name] = value

for name in data:
versions = data[name].get('versions', data[name].pop('version', ""))
data[name]['versions'] = versions
data[name]['patterns'] = [v.strip() for v in versions.split('|')]
if 'versions' in data[name]:
warnings.warn(
"'versions' is deprecated, use 'version' instead",
DeprecationWarning
)
version = data[name].pop('versions') or ""
else:
version = data[name].get('version') or ""

if ' | ' in version:
warnings.warn(
"'|' is deprecated, use '||' to separate multiple versions",
DeprecationWarning
)
version = version.replace(' | ', ' || ')

data[name]['version'] = version
data[name]['patterns'] = [v.strip() for v in version.split('||')]

return data

Expand All @@ -219,15 +235,15 @@ def check_dependencies(config):
break
else:
if settings.get('optional'):
show(_("?") + " EXPECTED: {0}".format(settings['versions']))
show(_("?") + " EXPECTED: {0}".format(settings['version']))
success.append(_("?"))
else:
if QUIET:
print("Unmatched {0} version: {1}".format(
name,
settings['versions'],
settings['version'],
))
show(_("x") + " EXPECTED: {0}".format(settings['versions']))
show(_("x") + " EXPECTED: {0}".format(settings['version']))
success.append(_("x"))
if settings.get('message'):
show(_("*") + " MESSAGE: {0}".format(settings['message']))
Expand Down
41 changes: 36 additions & 5 deletions verchew/tests/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def with_an_empty_section(config):

expect(parse_config(str(config))) == {
'Foobar': {
'versions': '',
'version': '',
'patterns': [''],
},
}
Expand All @@ -76,7 +76,7 @@ def with_a_filled_section(config):
expect(parse_config(str(config))) == {
'Foobar': {
'cli': 'foobar',
'versions': 'v1.2.3',
'version': 'v1.2.3',
'patterns': ['v1.2.3'],
},
}
Expand All @@ -85,17 +85,48 @@ def with_multiple_versions(config):
write(config, """
[Foobar]
version = 1
versions = 2 | 3 | 4
version = 2 || 3 || 4
""")

expect(parse_config(str(config))) == {
'Foobar': {
'versions': '2 | 3 | 4',
'version': '2 || 3 || 4',
'patterns': ['2', '3', '4'],
},
}

def with_legacy_versions_option(config):
write(config, """
[Foobar]
cli = foobar
versions = v1.2.3
""")

expect(parse_config(str(config))) == {
'Foobar': {
'cli': 'foobar',
'version': 'v1.2.3',
'patterns': ['v1.2.3'],
},
}

def with_legacy_versions_separator(config):
write(config, """
[Foobar]
cli = foobar
version = v1.2.3 | v1.2.4
""")

expect(parse_config(str(config))) == {
'Foobar': {
'cli': 'foobar',
'version': 'v1.2.3 || v1.2.4',
'patterns': ['v1.2.3', 'v1.2.4'],
},
}


def describe_get_version():

Expand Down

0 comments on commit c27fb6c

Please sign in to comment.