-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from mbdevpl/feature/fix-linting-issues
fix linting issues
- Loading branch information
Showing
7 changed files
with
186 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Functions for parsing version strings into their components and verifying the format.""" | ||
|
||
import logging | ||
import typing as t | ||
|
||
from . import patterns | ||
|
||
_LOG = logging.getLogger(__name__) | ||
|
||
|
||
def parse_release_str(release: str) -> tuple: | ||
"""Parse a release string into major, minor, and patch version numbers.""" | ||
match = patterns.RELEASE.fullmatch(release) | ||
assert match is not None | ||
major_match = match.group('major') | ||
assert major_match is not None | ||
major = int(major_match) | ||
minor_match = match.group('minor') | ||
if minor_match is not None: | ||
minor = int(minor_match) | ||
else: | ||
minor = None | ||
patch_match = match.group('patch') | ||
if patch_match is not None: | ||
patch = int(patch_match) | ||
else: | ||
patch = None | ||
return major, minor, patch | ||
|
||
|
||
def parse_pre_release_str(pre_release: str) -> t.Sequence[ | ||
t.Tuple[t.Optional[str], t.Optional[str], t.Optional[int]]]: | ||
"""Parse a pre-release string into a sequence of tuples.""" | ||
parts = patterns.PRE_RELEASE.findall(pre_release) | ||
_LOG.debug('parsed pre-release string %s into %s', repr(pre_release), parts) | ||
tuples = [] | ||
for part in parts: | ||
match = patterns.PRE_RELEASE_PART.fullmatch(part) | ||
assert match is not None | ||
pre_patch_match = match.group('prepatch') | ||
if pre_patch_match is not None: | ||
pre_patch = int(pre_patch_match) | ||
else: | ||
pre_patch = None | ||
tuples.append((match.group('preseparator'), match.group('pretype'), pre_patch)) | ||
return tuples | ||
|
||
|
||
def parse_local_str(local: str) -> tuple: | ||
"""Parse a local version suffix string into a sequence.""" | ||
match = patterns.LOCAL.fullmatch(local) | ||
assert match is not None | ||
return tuple(_ for _ in match.groups() if _ is not None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Patterns for recognising parts of version strings and parsing them.""" | ||
|
||
import re | ||
|
||
# pylint: disable = consider-using-f-string | ||
|
||
_NUMBER = r'(?:0|[123456789][0123456789]*)' | ||
# _SHA = r'[0123456789abcdef]+' | ||
_LETTERS = r'(?:[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]+)' | ||
LETTERS = re.compile(_LETTERS) | ||
_ALPHANUMERIC = r'(?:[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]+)' | ||
ALPHANUMERIC = re.compile(_ALPHANUMERIC) | ||
_SEP = r'(?:[\.-])' | ||
|
||
_RELEASE_PARTS = \ | ||
r'(?P<major>{n})(?:\.(?P<minor>{n}))?(?:\.(?P<patch>{n}))?'.format(n=_NUMBER) | ||
RELEASE = re.compile(_RELEASE_PARTS) | ||
|
||
_PRE_SEPARATOR = rf'(?P<preseparator>{_SEP})' | ||
_PRE_TYPE = rf'(?P<pretype>{_LETTERS})' | ||
_PRE_PATCH = rf'(?P<prepatch>{_NUMBER})' | ||
_PRE_RELEASE_PART = rf'{_PRE_SEPARATOR}?{_PRE_TYPE}?{_PRE_PATCH}?' | ||
PRE_RELEASE_PART = re.compile(_PRE_RELEASE_PART) | ||
_PRE_RELEASE_PARTS = r'(?:{0}{2})|(?:{0}?{1}{2}?)'.format(_SEP, _LETTERS, _NUMBER) | ||
PRE_RELEASE = re.compile(_PRE_RELEASE_PARTS) | ||
# PRE_RELEASE_CHECK = re.compile(rf'(?:{_PRE_RELEASE_PARTS})+') | ||
|
||
_LOCAL_SEPARATOR = rf'({_SEP})' | ||
_LOCAL_PART = rf'({_ALPHANUMERIC})' | ||
_LOCAL_PARTS = rf'\+{_LOCAL_PART}(?:{_LOCAL_SEPARATOR}{_LOCAL_PART})*' | ||
LOCAL = re.compile(_LOCAL_PARTS) | ||
|
||
|
||
_RELEASE = r'(?P<release>{n}(?:\.{n})?(?:\.{n})?)'.format(n=_NUMBER) | ||
_PRE_RELEASE = r'(?P<prerelease>(?:(?:{0}{2})|(?:{0}?{1}{2}?))+)'.format(_SEP, _LETTERS, _NUMBER) | ||
_LOCAL = r'(?P<local>\+{0}([\.-]{0})*)'.format(_ALPHANUMERIC) | ||
# _NAMED_PARTS_COUNT = 3 + 3 | ||
_VERSION = rf'{_RELEASE}{_PRE_RELEASE}?{_LOCAL}?' | ||
VERSION = re.compile(_VERSION) |
Oops, something went wrong.