Skip to content

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 <55177366+fengzhou-msft@users.noreply.github.com>
@fengzhou-msft fengzhou-msft merged commit 3d14ca2 into Azure:dev Apr 27, 2021

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