Skip to content

Commit

Permalink
Merge pull request #89 from jacebrowning/match-any-line
Browse files Browse the repository at this point in the history
Match the version in any line
  • Loading branch information
jacebrowning authored Jun 3, 2023
2 parents 8c0e68f + e8c55e4 commit 345a3cf
Show file tree
Hide file tree
Showing 8 changed files with 759 additions and 708 deletions.
8 changes: 2 additions & 6 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ environment:
global:
RANDOM_SEED: 0
matrix:
- PYTHON_MAJOR: 3
PYTHON_MINOR: 6
- PYTHON_MAJOR: 3
PYTHON_MINOR: 7
- PYTHON_MAJOR: 3
PYTHON_MINOR: 8

Expand All @@ -19,8 +15,8 @@ install:
- set PATH=C:\Python%PYTHON_MAJOR%%PYTHON_MINOR%;%PATH%
- set PATH=C:\Python%PYTHON_MAJOR%%PYTHON_MINOR%\Scripts;%PATH%
# Install system dependencies
- curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
- set PATH=%USERPROFILE%\.poetry\bin;%PATH%
- curl -sSL https://install.python-poetry.org | python -
- set PATH=%USERPROFILE%\AppData\Roaming\Python\Scripts;%PATH%
- make doctor
# Install project dependencies
- make install
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
3.8.8
3.9.16
2.7.16
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"cSpell.words": [
"DIRENV",
"printenv",
"pyenv",
"USERPROFILE"
]
}
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mkdocs==1.2.4; python_version >= "3.6"
pygments==2.7.4; python_version >= "3.5"
mkdocs==1.2.4 ; python_version >= "3.6" and python_version < "4.0"
pygments==2.7.4 ; python_version >= "3.6" and python_version < "4.0"
1,409 changes: 719 additions & 690 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "verchew"
version = "3.3" # also update verchew/script.py
version = "3.4" # also update verchew/script.py
description = "System dependency version checker."

license = "MIT"
Expand Down Expand Up @@ -32,6 +32,7 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Software Development",
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Testing",
Expand Down
30 changes: 22 additions & 8 deletions verchew/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import configparser
from urllib.request import urlretrieve

__version__ = '3.3'
__version__ = '3.4'

SCRIPT_URL = (
"https://raw.githubusercontent.com/jacebrowning/verchew/main/verchew/script.py"
Expand Down Expand Up @@ -295,23 +295,37 @@ def get_version(program, argument=None):
show("$ {0}".format(" ".join(args)))
output = call(args)
lines = output.splitlines()
show(lines[0] if lines else "<nothing>")

if lines:
for line in lines:
if any(char.isdigit() for char in line):
show(line)
break
else:
show(lines[0])
else:
show("<nothing>")

return output


def match_version(pattern, output):
if "not found" in output.split('\n')[0]:
lines = output.splitlines()
if "not found" in lines[0]:
return False

regex = pattern.replace('.', r'\.') + r'(\b|/)'

log.debug("Matching %s: %s", regex, output)
match = re.match(regex, output)
if match is None:
match = re.match(r'.*[^\d.]' + regex, output)
for line in lines:
log.debug("Matching %s: %s", regex, line)
match = re.match(regex, line)
if match is None:
log.debug("Matching %s: %s", regex, line)
match = re.match(r'.*[^\d.]' + regex, line)
if match:
return True

return bool(match)
return False


def call(args):
Expand Down
3 changes: 3 additions & 0 deletions verchew/tests/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ def when_mismatch_with_missing_program():
expect(match_version("", "program not found")) == False
expect(match_version("", "v1.2.3\nother not found")) == True

def when_match_with_multiple_lines():
expect(match_version("1.2", "Foobar\nVersion 1.2.3")) == True


def describe_format():
def default():
Expand Down

0 comments on commit 345a3cf

Please sign in to comment.