@@ -11,9 +11,9 @@ are met.
11
11
Knowing the Implemented semver.org Version
12
12
------------------------------------------
13
13
14
- The semver.org page is the authorative specification of how semantical
15
- versioning is definied .
16
- To know which version of semver.org is implemented in the semver libary ,
14
+ The semver.org page is the authoritative specification of how semantic
15
+ versioning is defined .
16
+ To know which version of semver.org is implemented in the semver library ,
17
17
use the following constant::
18
18
19
19
>>> semver.SEMVER_SPEC_VERSION
@@ -445,7 +445,11 @@ To compare two versions depends on your type:
445
445
446
446
Other types cannot be compared.
447
447
448
- If you need to convert some types into other, refer to :ref: `sec.convert.versions `.
448
+ If you need to convert some types into others, refer to :ref: `sec.convert.versions `.
449
+
450
+ The use of these comparison operators also implies that you can use builtin
451
+ functions that leverage this capability; builtins including, but not limited to: :func: `max `, :func: `min `
452
+ (for examples, see :ref: `sec_max_min `) and :func: `sorted `.
449
453
450
454
451
455
@@ -476,9 +480,47 @@ That gives you the following possibilities to express your condition:
476
480
>> > semver.match(" 1.0.0" , " >1.0.0" )
477
481
False
478
482
483
+ .. _sec_max_min :
484
+
485
+ Getting Minimum and Maximum of Multiple Versions
486
+ ------------------------------------------------
487
+ .. versionchanged :: 2.10.2
488
+ The functions :func: `semver.max_ver ` and :func: `semver.min_ver ` are deprecated in
489
+ favor of their builtin counterparts :func: `max ` and :func: `min `.
490
+
491
+ Since :class: `semver.VersionInfo ` implements :func: `__gt__() ` and :func: `__lt__() `, it can be used with builtins requiring
492
+
493
+ .. code-block :: python
494
+
495
+ >> > max ([semver.VersionInfo(0 , 1 , 0 ), semver.VersionInfo(0 , 2 , 0 ), semver.VersionInfo(0 , 1 , 3 )])
496
+ VersionInfo(major = 0 , minor = 2 , patch = 0 , prerelease = None , build = None )
497
+ >> > min ([semver.VersionInfo(0 , 1 , 0 ), semver.VersionInfo(0 , 2 , 0 ), semver.VersionInfo(0 , 1 , 3 )])
498
+ VersionInfo(major = 0 , minor = 1 , patch = 0 , prerelease = None , build = None )
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 , None , None )
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 , None , None )
479
520
480
- Getting Minimum and Maximum of two Versions
481
- -------------------------------------------
521
+ For dictionaries, it is very similar to finding the max version tuple: see :ref: `sec.convert.versions `.
522
+
523
+ The "old way" with :func: `semver.max_ver ` or :func: `semver.min_ver ` is still available, but not recommended:
482
524
483
525
.. code-block :: python
484
526
@@ -575,6 +617,28 @@ them with code which is compatible for future versions:
575
617
>> > s1 == s2
576
618
True
577
619
620
+ * :func: `semver.max_ver `
621
+
622
+ Replace it with ``max(version1, version2, ...) `` or ``max([version1, version2, ...]) ``:
623
+
624
+ .. code-block :: python
625
+
626
+ >> > s1 = semver.max_ver(" 1.2.3" , " 1.2.4" )
627
+ >> > s2 = str (max (map (semver.VersionInfo.parse, (" 1.2.3" , " 1.2.4" ))))
628
+ >> > s1 == s2
629
+ True
630
+
631
+ * :func: `semver.min_ver `
632
+
633
+ Replace it with ``min(version1, version2, ...) `` or ``min([version1, version2, ...]) ``:
634
+
635
+ .. code-block :: python
636
+
637
+ >> > s1 = semver.min_ver(" 1.2.3" , " 1.2.4" )
638
+ >> > s2 = str (min (map (semver.VersionInfo.parse, (" 1.2.3" , " 1.2.4" ))))
639
+ >> > s1 == s2
640
+ True
641
+
578
642
* :func: `semver.parse `
579
643
580
644
Replace it with :func: `semver.VersionInfo.parse ` and
0 commit comments