@@ -483,27 +483,53 @@ That gives you the following possibilities to express your condition:
483
483
.. _sec_max_min :
484
484
485
485
Getting Minimum and Maximum of Multiple Versions
486
- -------------------------------------------
486
+ ------------------------------------------------
487
487
.. versionchanged :: 2.10.2
488
488
The functions :func: `semver.max_ver ` and :func: `semver.min_ver ` are deprecated in
489
489
favor of their builtin counterparts :func: `max ` and :func: `min `.
490
490
491
491
Since :class: `semver.VersionInfo ` implements :func: `__gt__() ` and :func: `__lt__() `, it can be used with builtins requiring
492
492
493
- .. code-block :: python
494
-
495
- >> > str (max (semver.VersionInfo.parse(" 1.0.0" ), semver.VersionInfo.parse(" 2.0.0" )))
496
- ' 2.0.0'
497
- >> > str (min (semver.VersionInfo.parse(" 1.0.0" ), semver.VersionInfo.parse(" 2.0.0" )))
498
- ' 1.0.0'
499
-
500
493
.. code-block :: python
501
494
502
495
>> > max ([semver.VersionInfo(0 , 1 , 0 ), semver.VersionInfo(0 , 2 , 0 ), semver.VersionInfo(0 , 1 , 3 )])
503
496
VersionInfo(major = 0 , minor = 2 , patch = 0 , prerelease = None , build = None )
504
497
>> > min ([semver.VersionInfo(0 , 1 , 0 ), semver.VersionInfo(0 , 2 , 0 ), semver.VersionInfo(0 , 1 , 3 )])
505
498
VersionInfo(major = 0 , minor = 1 , patch = 0 , prerelease = None , build = None )
506
499
500
+ Incidentally, using :func: `map `, you can get the min or max version of any number of versions of the same type
501
+ (convertible to :class: `semver.VersionInfo `).
502
+
503
+ For example, here are the maximum and minimum versions of a list of version strings:
504
+
505
+ .. code-block :: python
506
+
507
+ >> > str (max (map (semver.VersionInfo.parse, [' 1.1.0' , ' 1.2.0' , ' 2.1.0' , ' 0.5.10' , ' 0.4.99' ])))
508
+ ' 2.1.0'
509
+ >> > str (min (map (semver.VersionInfo.parse, [' 1.1.0' , ' 1.2.0' , ' 2.1.0' , ' 0.5.10' , ' 0.4.99' ])))
510
+ ' 0.4.99'
511
+
512
+ And the same can be done with tuples:
513
+
514
+ .. code-block :: python
515
+
516
+ >> > max (map (lambda v : semver.VersionInfo(* v), [(1 , 1 , 0 ), (1 , 2 , 0 ), (2 , 1 , 0 ), (0 , 5 , 10 ), (0 , 4 , 99 )]))).to_tuple()
517
+ (2 , 1 , 0 )
518
+ >> > min (map (lambda v : semver.VersionInfo(* v), [(1 , 1 , 0 ), (1 , 2 , 0 ), (2 , 1 , 0 ), (0 , 5 , 10 ), (0 , 4 , 99 )]))).to_tuple()
519
+ (0 , 4 , 99 )
520
+
521
+ For dictionaries, it is very similar to finding the max version tuple: see :ref: `_sec.convert.versions `.
522
+
523
+ The Old Way
524
+ ^^^^^^^^^^^
525
+
526
+ .. code-block :: python
527
+
528
+ >> > semver.max_ver(" 1.0.0" , " 2.0.0" )
529
+ ' 2.0.0'
530
+ >> > semver.min_ver(" 1.0.0" , " 2.0.0" )
531
+ ' 1.0.0'
532
+
507
533
508
534
Dealing with Invalid Versions
509
535
-----------------------------
0 commit comments