|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 |
| -from packaging.version import parse, LegacyVersion |
| 15 | +from packaging.version import parse, InvalidVersion |
16 | 16 | import argparse
|
17 | 17 | import sys
|
18 | 18 |
|
| 19 | +try: |
| 20 | + from packaging.version import LegacyVersion |
| 21 | +except ImportError: |
| 22 | + LegacyVersion = () # trick isinstance! |
| 23 | + |
19 | 24 | # exit with 0 if --new is equal to --old
|
20 | 25 | # exit with 1 on errors
|
21 | 26 | # exit with 2 if --new is newer than --old
|
|
30 | 35 | parser.print_help()
|
31 | 36 | exit(1)
|
32 | 37 |
|
33 |
| -old, new = parse(args.old), parse(args.new) |
| 38 | +# packaging>=22 only supports PEP-440 version numbers, and a non-valid version |
| 39 | +# will throw InvalidVersion. Previous packaging releases would create a |
| 40 | +# LegacyVersion object if the given version string failed to parse as PEP-440, |
| 41 | +# and since we use versions closer to semver, we want to fail in that case. |
| 42 | + |
| 43 | +versions = [] |
| 44 | +for version in [args.old, args.new]: |
| 45 | + try: |
| 46 | + versions.append(parse(version)) |
| 47 | + except InvalidVersion: |
| 48 | + print("Invalid version parsed: {}".format(version)) |
| 49 | + sys.exit(1) |
34 | 50 |
|
35 |
| -# only accept versions that were correctly parsed |
| 51 | +old, new = versions[0], versions[1] |
36 | 52 | for version in [old, new]:
|
37 | 53 | if isinstance(version, LegacyVersion):
|
38 | 54 | print("Invalid version parsed: {}".format(version))
|
|
0 commit comments