Skip to content

Commit fe538fd

Browse files
authored
Merge pull request #27 from mbdevpl/feature/fix-linting-issues
fix linting issues
2 parents a99ac98 + c048770 commit fe538fd

File tree

7 files changed

+186
-138
lines changed

7 files changed

+186
-138
lines changed

.github/workflows/python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- run: python -m pip install -e .
5555
- run: python -m coverage run --append --branch --source . -m pip install --no-build-isolation --no-binary ebrains-drive ebrains-drive==0.6.0
5656
- run: python -m coverage report --show-missing
57-
- run: codecov
57+
- run: python -m codecov --token ${{ secrets.CODECOV_TOKEN }}
5858
publish:
5959
if: startsWith(github.ref, 'refs/tags/v')
6060
needs: build

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ Incrementing any version component clears all existing following components.
308308
Examples of how version is incremented:
309309

310310
* for ``1.5``, incrementing ``<major>`` results in ``2.0``;
311-
* for ``1.5.1-2.4``, ``<minor>``++ results in ``1.6``;
312-
* ``1.5.1-2.4``, ``<patch>``++, ``1.5.2``;
313-
* ``1.5.1``, ``<major>``+=3, ``4.0.0``.
311+
* for ``1.5.1-2.4``, ``<minor>`` ++ results in ``1.6``;
312+
* ``1.5.1-2.4``, ``<patch>`` ++, ``1.5.2``;
313+
* ``1.5.1``, ``<major>`` += 3, ``4.0.0``.
314314

315315

316316
API details

test/test_version.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@ def test_from_str(self):
2525
with self.subTest(version_str=version_str, version_tuple=version_tuple):
2626

2727
py_version = \
28-
pkg_resources.parse_version(version_str) # type: packaging.version.Version
29-
# self.assertIsInstance(
30-
# py_version, packaging.version.Version, msg=(type(py_version), py_version))
28+
pkg_resources.parse_version(version_str)
3129
_LOG.debug('packaging parsed version string %s into %s: %s',
3230
repr(version_str), type(py_version), py_version)
31+
# self.assertIsInstance(
32+
# py_version, packaging.version.Version, msg=(type(py_version), py_version))
3333

3434
try:
35-
sem_version = semver.VersionInfo.parse(version_str) # type: semver.VersionInfo
35+
sem_version = semver.VersionInfo.parse(version_str)
3636
except ValueError:
3737
_LOG.debug('semver could not parse version string %s', repr(version_str))
3838
else:
3939
_LOG.debug('semver parsed version string %s into %s: %s',
4040
repr(version_str), type(sem_version), sem_version)
41+
# self.assertIsInstance(
42+
# sem_version, semver.VersionInfo, msg=(type(sem_version), sem_version))
4143

4244
self.assertEqual(Version.from_str(version_str).to_tuple(), version_tuple)
4345

@@ -76,7 +78,7 @@ def test_from_sem_version(self):
7678
version_tuple = case_to_version_tuple(args, kwargs)
7779
with self.subTest(version_str=version_str, version_tuple=version_tuple):
7880
try:
79-
sem_version = semver.VersionInfo.parse(version_str) # type: semver.VersionInfo
81+
sem_version = semver.VersionInfo.parse(version_str)
8082
except ValueError:
8183
continue
8284
else:
@@ -123,6 +125,7 @@ def test_init(self):
123125
self.assertIsInstance(version.local, tuple)
124126

125127
def test_init_bad(self):
128+
# pylint: disable = redefined-variable-type
126129
for (args, kwargs), exception in BAD_INIT_CASES.items():
127130
with self.subTest(args=args, kwargs=kwargs, exception=exception):
128131
with self.assertRaises(exception):

version_query/git_query.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ def _git_version_tags(repo: git.Repo) -> t.Mapping[git.Tag, Version]:
4040
return versions
4141

4242

43+
def _git_version_tag_commits(
44+
version_tags: t.Iterable[git.Tag]) -> t.Mapping[git.objects.Commit, t.Set[git.Tag]]:
45+
version_tag_commits: t.Dict[git.objects.Commit, t.Set[git.Tag]] = {}
46+
for tag in version_tags:
47+
_commit = tag.commit
48+
if _commit not in version_tag_commits:
49+
version_tag_commits[_commit] = set()
50+
version_tag_commits[_commit].add(tag)
51+
return version_tag_commits
52+
53+
4354
def _latest_git_version_tag_on_branches(
4455
repo: git.Repo, assume_if_none: bool, commit: git.objects.Commit, commit_distance: int,
4556
skip_commits: t.Set[git.objects.Commit]) -> t.Union[int, t.Tuple[
@@ -80,12 +91,7 @@ def _latest_git_version_tag(
8091
t.Optional[git.objects.Commit], t.Optional[git.TagReference], t.Optional[Version], int]:
8192
"""Return (commit, tag at that commit if any, latest version, distance from the version)."""
8293
version_tags = _git_version_tags(repo)
83-
version_tag_commits: t.Dict[git.objects.Commit, set] = {}
84-
for tag, version in version_tags.items():
85-
_commit = tag.commit
86-
if _commit not in version_tag_commits:
87-
version_tag_commits[_commit] = set()
88-
version_tag_commits[_commit].add(tag)
94+
version_tag_commits = _git_version_tag_commits(version_tags.keys())
8995
current_version_tags = {}
9096
commit = None
9197
if skip_commits is None:

version_query/parser.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Functions for parsing version strings into their components and verifying the format."""
2+
3+
import logging
4+
import typing as t
5+
6+
from . import patterns
7+
8+
_LOG = logging.getLogger(__name__)
9+
10+
11+
def parse_release_str(release: str) -> tuple:
12+
"""Parse a release string into major, minor, and patch version numbers."""
13+
match = patterns.RELEASE.fullmatch(release)
14+
assert match is not None
15+
major_match = match.group('major')
16+
assert major_match is not None
17+
major = int(major_match)
18+
minor_match = match.group('minor')
19+
if minor_match is not None:
20+
minor = int(minor_match)
21+
else:
22+
minor = None
23+
patch_match = match.group('patch')
24+
if patch_match is not None:
25+
patch = int(patch_match)
26+
else:
27+
patch = None
28+
return major, minor, patch
29+
30+
31+
def parse_pre_release_str(pre_release: str) -> t.Sequence[
32+
t.Tuple[t.Optional[str], t.Optional[str], t.Optional[int]]]:
33+
"""Parse a pre-release string into a sequence of tuples."""
34+
parts = patterns.PRE_RELEASE.findall(pre_release)
35+
_LOG.debug('parsed pre-release string %s into %s', repr(pre_release), parts)
36+
tuples = []
37+
for part in parts:
38+
match = patterns.PRE_RELEASE_PART.fullmatch(part)
39+
assert match is not None
40+
pre_patch_match = match.group('prepatch')
41+
if pre_patch_match is not None:
42+
pre_patch = int(pre_patch_match)
43+
else:
44+
pre_patch = None
45+
tuples.append((match.group('preseparator'), match.group('pretype'), pre_patch))
46+
return tuples
47+
48+
49+
def parse_local_str(local: str) -> tuple:
50+
"""Parse a local version suffix string into a sequence."""
51+
match = patterns.LOCAL.fullmatch(local)
52+
assert match is not None
53+
return tuple(_ for _ in match.groups() if _ is not None)

version_query/patterns.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Patterns for recognising parts of version strings and parsing them."""
2+
3+
import re
4+
5+
# pylint: disable = consider-using-f-string
6+
7+
_NUMBER = r'(?:0|[123456789][0123456789]*)'
8+
# _SHA = r'[0123456789abcdef]+'
9+
_LETTERS = r'(?:[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]+)'
10+
LETTERS = re.compile(_LETTERS)
11+
_ALPHANUMERIC = r'(?:[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]+)'
12+
ALPHANUMERIC = re.compile(_ALPHANUMERIC)
13+
_SEP = r'(?:[\.-])'
14+
15+
_RELEASE_PARTS = \
16+
r'(?P<major>{n})(?:\.(?P<minor>{n}))?(?:\.(?P<patch>{n}))?'.format(n=_NUMBER)
17+
RELEASE = re.compile(_RELEASE_PARTS)
18+
19+
_PRE_SEPARATOR = rf'(?P<preseparator>{_SEP})'
20+
_PRE_TYPE = rf'(?P<pretype>{_LETTERS})'
21+
_PRE_PATCH = rf'(?P<prepatch>{_NUMBER})'
22+
_PRE_RELEASE_PART = rf'{_PRE_SEPARATOR}?{_PRE_TYPE}?{_PRE_PATCH}?'
23+
PRE_RELEASE_PART = re.compile(_PRE_RELEASE_PART)
24+
_PRE_RELEASE_PARTS = r'(?:{0}{2})|(?:{0}?{1}{2}?)'.format(_SEP, _LETTERS, _NUMBER)
25+
PRE_RELEASE = re.compile(_PRE_RELEASE_PARTS)
26+
# PRE_RELEASE_CHECK = re.compile(rf'(?:{_PRE_RELEASE_PARTS})+')
27+
28+
_LOCAL_SEPARATOR = rf'({_SEP})'
29+
_LOCAL_PART = rf'({_ALPHANUMERIC})'
30+
_LOCAL_PARTS = rf'\+{_LOCAL_PART}(?:{_LOCAL_SEPARATOR}{_LOCAL_PART})*'
31+
LOCAL = re.compile(_LOCAL_PARTS)
32+
33+
34+
_RELEASE = r'(?P<release>{n}(?:\.{n})?(?:\.{n})?)'.format(n=_NUMBER)
35+
_PRE_RELEASE = r'(?P<prerelease>(?:(?:{0}{2})|(?:{0}?{1}{2}?))+)'.format(_SEP, _LETTERS, _NUMBER)
36+
_LOCAL = r'(?P<local>\+{0}([\.-]{0})*)'.format(_ALPHANUMERIC)
37+
# _NAMED_PARTS_COUNT = 3 + 3
38+
_VERSION = rf'{_RELEASE}{_PRE_RELEASE}?{_LOCAL}?'
39+
VERSION = re.compile(_VERSION)

0 commit comments

Comments
 (0)