Skip to content

Commit

Permalink
Parse numeric version inputs using RE parser
Browse files Browse the repository at this point in the history
- Uses existing parser built for handling complex versions
- Is sufficiently robust, should handle most circumstances
- Fixes #59
- Closes and supersedes #57

Signed-off-by: Dan Ryan <dan@danryan.co>
  • Loading branch information
techalchemy committed Jan 22, 2019
1 parent bac7b43 commit 6e4d5c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions news/59.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug which prevented parsing of numeric versions as inputs to pythonfinder.
25 changes: 15 additions & 10 deletions src/pythonfinder/pythonfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from . import environment
from .exceptions import InvalidPythonVersion
from .models import path
from .utils import Iterable, filter_pythons
from .utils import Iterable, filter_pythons, version_re


if environment.MYPY_RUNNING:
Expand Down Expand Up @@ -174,14 +174,20 @@ def find_python_version(
name = "%s" % major
major = None
else:
version_dict = {
"major": major,
"minor": minor,
"patch": patch,
"pre": pre,
"dev": dev,
"arch": arch
}
if "." in major and all(part.isdigit() for part in major.split(".")[:2]):
match = version_re.match(major)
version_dict = match.groupdict()
version_dict["is_prerelease"] = bool(version_dict.get("prerel", False))
version_dict["is_devrelease"] = bool(version_dict.get("dev", False))
else:
version_dict = {
"major": major,
"minor": minor,
"patch": patch,
"pre": pre,
"dev": dev,
"arch": arch
}
if version_dict.get("minor") is not None:
minor = int(version_dict["minor"])
if version_dict.get("patch") is not None:
Expand All @@ -199,7 +205,6 @@ def find_python_version(
)
if match:
return match
secho("Using name: %s" % name, fg="white")
return self.system_path.find_python_version(
major=major, minor=minor, patch=patch, pre=pre, dev=dev, arch=arch, name=name
)
Expand Down

0 comments on commit 6e4d5c9

Please sign in to comment.