-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement] Update digit_version function #865
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,59 @@ | ||
import warnings | ||
|
||
import mmcv | ||
from mmcv import digit_version, parse_version_info | ||
from mmcv import parse_version_info | ||
from packaging.version import parse | ||
|
||
from .version import __version__, short_version | ||
|
||
mmcv_minimum_version = '1.3.8' | ||
mmcv_maximum_version = '1.4.0' | ||
MMCV_MIN = '1.3.8' | ||
MMCV_MAX = '1.5.0' | ||
|
||
|
||
def digit_version(version_str: str, length: int = 4): | ||
"""Convert a version string into a tuple of integers. | ||
|
||
This method is usually used for comparing two versions. For pre-release | ||
versions: alpha < beta < rc. | ||
Args: | ||
version_str (str): The version string. | ||
length (int): The maximum number of version levels. Default: 4. | ||
Returns: | ||
tuple[int]: The version info in digits (integers). | ||
""" | ||
version = parse(version_str) | ||
assert version.release, f'failed to parse version {version_str}' | ||
release = list(version.release) | ||
release = release[:length] | ||
if len(release) < length: | ||
release = release + [0] * (length - len(release)) | ||
if version.is_prerelease: | ||
mapping = {'a': -3, 'b': -2, 'rc': -1} | ||
val = -4 | ||
# version.pre can be None | ||
if version.pre: | ||
if version.pre[0] not in mapping: | ||
warnings.warn(f'unknown prerelease version {version.pre[0]}, ' | ||
'version checking may go wrong') | ||
else: | ||
val = mapping[version.pre[0]] | ||
release.extend([val, version.pre[-1]]) | ||
else: | ||
release.extend([val, 0]) | ||
|
||
elif version.is_postrelease: | ||
release.extend([1, version.post]) | ||
else: | ||
release.extend([0, 0]) | ||
return tuple(release) | ||
|
||
|
||
mmcv_version = digit_version(mmcv.__version__) | ||
version_info = parse_version_info(__version__) | ||
|
||
assert digit_version(mmcv_minimum_version) <= mmcv_version, \ | ||
f'MMCV=={mmcv.__version__} is used but incompatible. ' \ | ||
f'Please install mmcv>={mmcv_minimum_version}.' | ||
|
||
assert digit_version(mmcv_maximum_version) > mmcv_version, \ | ||
f'MMCV=={mmcv.__version__} is used but incompatible. ' \ | ||
f'Please install mmcv<{mmcv_maximum_version}.' | ||
assert (mmcv_version >= digit_version(MMCV_MIN) | ||
and mmcv_version <= digit_version(MMCV_MAX)), \ | ||
f'MMCV=={mmcv.__version__} is used but incompatible. ' \ | ||
f'Please install mmcv>={MMCV_MIN}, <={MMCV_MAX}.' | ||
|
||
__all__ = ['__version__', 'short_version', 'version_info'] | ||
__all__ = ['__version__', 'short_version', 'version_info', 'digit_version'] |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ matplotlib | |
munkres | ||
numpy | ||
opencv-python | ||
packaging | ||
pillow | ||
scipy | ||
torchvision | ||
|
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 |
---|---|---|
@@ -1,8 +1,28 @@ | ||
import mmpose | ||
from mmpose import digit_version | ||
|
||
|
||
def test_version(): | ||
version = mmpose.__version__ | ||
assert isinstance(version, str) | ||
assert isinstance(mmpose.short_version, str) | ||
assert mmpose.short_version in version | ||
|
||
|
||
def test_digit_version(): | ||
assert digit_version('0.2.16') == (0, 2, 16, 0, 0, 0) | ||
assert digit_version('1.2.3') == (1, 2, 3, 0, 0, 0) | ||
assert digit_version('1.2.3rc0') == (1, 2, 3, 0, -1, 0) | ||
assert digit_version('1.2.3rc1') == (1, 2, 3, 0, -1, 1) | ||
assert digit_version('1.0rc0') == (1, 0, 0, 0, -1, 0) | ||
assert digit_version('1.0') == digit_version('1.0.0') | ||
assert digit_version('1.5.0+cuda90_cudnn7.6.3_lms') == digit_version('1.5') | ||
assert digit_version('1.0.0dev') < digit_version('1.0.0a') | ||
assert digit_version('1.0.0a') < digit_version('1.0.0a1') | ||
assert digit_version('1.0.0a') < digit_version('1.0.0b') | ||
assert digit_version('1.0.0b') < digit_version('1.0.0rc') | ||
assert digit_version('1.0.0rc1') < digit_version('1.0.0') | ||
assert digit_version('1.0.0') < digit_version('1.0.0post') | ||
assert digit_version('1.0.0post') < digit_version('1.0.0post1') | ||
assert digit_version('v1') == (1, 0, 0, 0, 0, 0) | ||
assert digit_version('v1.1.5') == (1, 1, 5, 0, 0, 0) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing is good enough, and do not need to copy the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean importing from mmcv? I think the point of this PR is to avoid import this function from mmcv. Because digit_version from mmcv depends on mmcv version itself, like a circular dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually my thinking its the reverse. We will use the implementation of digit_version in mmcv, so that we will get automatic bug fixes.