Skip to content
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

{core} Fix #17170: Replace distutils.version.LooseVersion with packaging.version.parse #17667

Merged
merged 5 commits into from
Apr 27, 2021

Conversation

Jing-song
Copy link
Contributor

Description

Replace distutils.version.LooseVersion with packaging.version.Version
Testing Guide

History Notes

[Component Name 1] BREAKING CHANGE: az command a: Make some customer-facing breaking change.
[Component Name 2] az command b: Add some customer-facing feature.


This checklist is used to make sure that common guidelines for a pull request are followed.

Replace distutils.version.LooseVersion with packaging.version.Version
@yonzhan
Copy link
Collaborator

yonzhan commented Apr 13, 2021

@jiasli for awareness

@fengzhou-msft
Copy link
Member

fengzhou-msft commented Apr 14, 2021

You need to add packaging as a dependency package to use it in CLI packages. You can refer to this PR.

@Jing-song Jing-song requested a review from msyyc as a code owner April 14, 2021 06:12
@Jing-song Jing-song changed the title {core} Fix #17170: Replace distutils.version.LooseVersion with packaging.version.Version {core} Fix #17170: Replace distutils.version.LooseVersion with packaging.version.parse Apr 14, 2021
@qwordy
Copy link
Member

qwordy commented Apr 15, 2021

What are the differences among distutils.version.LooseVersion, distutils.version.StrictVersion and packaging.version.Version?

@Jing-song
Copy link
Contributor Author

What are the differences among distutils.version.LooseVersion, distutils.version.StrictVersion and packaging.version.Version?

distutils.version.LooseVersion use re.compile(r'(\d+ | [a-z]+ | \.)', re.VERBOSE) to match,distutils.version.StrictVersion use re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$',re.VERBOSE | re.ASCII) to match,they are using PEP 386.
packaging.version.Version use re.compile(r"^\s*" + VERSION_PATTERN + r"\s*$", re.VERBOSE | re.IGNORECASE) to match,it using PEP 440.
packaging.version.parse parse the given version string and return either a :class:Version object or a :class:LegacyVersion object depending on if the given version is a valid PEP 440 version or a legacy version.

Use flexible compatible version range in setup.py

Co-authored-by: Feng Zhou <[email protected]>
@fengzhou-msft fengzhou-msft merged commit 3d14ca2 into Azure:dev Apr 27, 2021
@@ -352,10 +352,10 @@ def _print(val=''):
print(val, file=output)

def _get_version_string(name, version_dict):
from distutils.version import LooseVersion # pylint: disable=import-error,no-name-in-module
from packaging.version import parse # pylint: disable=import-error,no-name-in-module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 632 also mentions:

distutils.version — use the packaging package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

distutils.version.LooseVersion should be replaced by packaging.version.Version
6 participants