| 1 | package Versioning::Scheme::Python; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | our $DATE = '2018-11-18'; # DATE | |||||||||||||||||||||||||||
| 4 | 2 | our $VERSION = '0.001'; # VERSION | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Role::Tiny::With; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | with 'Role::Versioning::Scheme'; | |||||||||||||||||||||||||||
| 13 | 2 | ▶ | use PerlX::Maybe; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Python::Version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | sub is_valid_version { | ||||||||||||||||||||||||||
|
Subroutine
is_valid_version: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 3 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 18 | 3 | eval { Python::Version->parse($v) }; | |||||||||||||||||||||||||||
| 19 | 3 | ▶ | $@ ? 0:1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | sub parse_version { | ||||||||||||||||||||||||||
|
Subroutine
parse_version: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 2 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | my $vp; | |||||||||||||||||||||||||||
| 26 | 2 | eval { $vp = Python::Version->parse($v) }; | |||||||||||||||||||||||||||
| 27 | 2 | ▶ | return undef if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | +{ | ||||||||||||||||||||||||||||
| 29 | maybe epoch => $vp->{_epoch}, | ||||||||||||||||||||||||||||
| 30 | maybe base => $vp->{_base_version}, | ||||||||||||||||||||||||||||
| 31 | maybe prerelease => $vp->{_prerelease}, | ||||||||||||||||||||||||||||
| 32 | maybe postrelease => $vp->{_postrelease}, | ||||||||||||||||||||||||||||
| 33 | maybe devrelease => $vp->{_devrelease}, | ||||||||||||||||||||||||||||
| 34 | maybe local => $vp->{_local_version}, | ||||||||||||||||||||||||||||
| 35 | 1 | }; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | ▶ | sub normalize_version { | ||||||||||||||||||||||||||
|
Subroutine
normalize_version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 2 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 40 | 2 | Python::Version->parse($v)->normal; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 4 | ▶ | sub cmp_version { | ||||||||||||||||||||||||||
|
Subroutine
cmp_version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 4 | my ($self, $v1, $v2) = @_; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 4 | Python::Version->parse($v1) <=> Python::Version->parse($v2); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 14 | ▶ | sub bump_version { | ||||||||||||||||||||||||||
|
Subroutine
bump_version: called CC=30 SCAR=44.0
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 14 | my ($self, $v, $opts) = @_; | |||||||||||||||||||||||||||
| 51 | 14 | ▶ | $opts //= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts //= {}
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
| |||||||||||||||||||||||||||||
| 52 | 14 | ▶ | $opts->{num} //= 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"num"} //= 1
MC/DC100%1/1
$opts->{"num"} //= 1
$opts->{"num"}
Truth table100%2/2
A
A= $opts->{"num"}
| |||||||||||||||||||||||||||||
| 53 | 14 | ▶ | $opts->{part} //= -1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"part"} //= -1
MC/DC100%1/1
$opts->{"part"} //= -1
$opts->{"part"}
Truth table100%2/2
A
A= $opts->{"part"}
| |||||||||||||||||||||||||||||
| 54 | 14 | ▶ | $opts->{reset_smaller} //= 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"reset_smaller"} //= 1
MC/DC100%1/1
$opts->{"reset_smaller"} //= 1
$opts->{"reset_smaller"}
Truth table100%2/2
A
A= $opts->{"reset_smaller"}
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 14 | my $vp = Python::Version->parse($v); | |||||||||||||||||||||||||||
| 57 | 13 | ▶ | die "Invalid 'num', must be non-zero" unless $opts->{num} != 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 12 | ▶ | if ($opts->{part} =~ /\A-?\d+\z/) { | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 60 | 1 | die "Invalid 'part', must not be smaller than -".@{$vp->{_base_version}} | |||||||||||||||||||||||||||
| 61 | 10 | ▶ | if $opts->{part} < -@{ $vp->{_base_version} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | die "Invalid 'part', must not be larger than ".$#{$vp->{_base_version}} | |||||||||||||||||||||||||||
| 63 | 9 | ▶ | if $opts->{part} > $#{$vp->{_base_version}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 9 | ▶ | my $idx = $opts->{part}; $idx = @{$vp->{_base_version}} + $idx if $idx < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | # for now, we do not allow decreasing that overflow to the next more | ||||||||||||||||||||||||||||
| 67 | # significant part | ||||||||||||||||||||||||||||
| 68 | die "Cannot decrease version, would result in a negative part" | ||||||||||||||||||||||||||||
| 69 | 9 | ▶ | if $vp->{_base_version}[$idx] + $opts->{num} < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 8 | my $i = $idx; | |||||||||||||||||||||||||||
| 71 | 8 | my $left = $opts->{num}; | |||||||||||||||||||||||||||
| 72 | 8 | while (1) { | |||||||||||||||||||||||||||
| 73 | 8 | ▶ | if ($i == 0 || $vp->{_base_version}[$i]+$left < 1000) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$i == 0 or $vp->{"_base_version"}[$i] + $left < 1000
MC/DC0%0/2
$i == 0 or $vp->{"_base_version"}[$i] + $left < 1000
$i == 0
$vp->{"_base_version"}[$i] + $left < 1000
Truth table66%2/3
A or B
A= $i == 0B= $vp->{"_base_version"}[$i] + $left < 1000
| |||||||||||||||||||||||||||||
| 74 | 8 | $vp->{_base_version}[$i] += $left; | |||||||||||||||||||||||||||
| 75 | 8 | $left = 0; | |||||||||||||||||||||||||||
| 76 | 8 | last; | |||||||||||||||||||||||||||
| 77 | } else { | ||||||||||||||||||||||||||||
| 78 | 0 | my $tmp = $vp->{_base_version}[$i] + $left; | |||||||||||||||||||||||||||
| 79 | 0 | $vp->{_base_version}[$i] = $tmp % 1000; | |||||||||||||||||||||||||||
| 80 | 0 | $left = int($tmp / 1000); | |||||||||||||||||||||||||||
| 81 | 0 | $i--; | |||||||||||||||||||||||||||
| 82 | 0 | next; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 8 | ▶ | if ($opts->{reset_smaller} && $opts->{num} > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opts->{"reset_smaller"} and $opts->{"num"} > 0
MC/DC100%2/2
$opts->{"reset_smaller"} and $opts->{"num"} > 0
$opts->{"reset_smaller"}
$opts->{"num"} > 0
Truth table100%3/3
A and B
A= $opts->{"reset_smaller"}B= $opts->{"num"} > 0
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $idx = @{$vp->{_base_version}} + $idx if $idx < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 4 | for my $i ($idx+1 .. $#{$vp->{_base_version}}) { | |||||||||||||||||||||||||||
| 88 | 3 | $vp->{_base_version}[$i] = 0; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } elsif ($opts->{part} =~ /\A(a|b|rc)\z/) { | ||||||||||||||||||||||||||||
| 92 | die "Can't bump version: no $opts->{part} part" | ||||||||||||||||||||||||||||
| 93 | 2 | ▶ | unless $vp->{_prerelease} && $vp->{_prerelease}[0] eq $opts->{part}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$vp->{"_prerelease"} and $vp->{"_prerelease"}[0] eq $opts->{"part"}
MC/DC50%1/2
$vp->{"_prerelease"} and $vp->{"_prerelease"}[0] eq $opts->{"part"}
$vp->{"_prerelease"}
$vp->{"_prerelease"}[0] eq $opts->{"part"}
Truth table66%2/3
A and B
A= $vp->{"_prerelease"}B= $vp->{"_prerelease"}[0] eq $opts->{"part"}
| |||||||||||||||||||||||||||||
| 94 | die "Cannot decrease version, would result in a negative $opts->{part} part" | ||||||||||||||||||||||||||||
| 95 | 1 | ▶ | if $vp->{_prerelease}[1] + $opts->{num} < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 1 | $vp->{_prerelease}[1] += $opts->{num}; | |||||||||||||||||||||||||||
| 97 | } elsif ($opts->{part} eq 'post') { | ||||||||||||||||||||||||||||
| 98 | die "Can't bump version: no $opts->{part} part" | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | unless $vp->{_postrelease}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | die "Cannot decrease version, would result in a negative $opts->{part} part" | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if $vp->{_postrelease}[1] + $opts->{num} < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | $vp->{_postrelease}[1] += $opts->{num}; | |||||||||||||||||||||||||||
| 103 | } elsif ($opts->{part} eq 'dev') { | ||||||||||||||||||||||||||||
| 104 | die "Can't bump version: no $opts->{part} part" | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | unless $vp->{_devrelease}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | die "Cannot decrease version, would result in a negative $opts->{part} part" | ||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if $vp->{_devrelease}[1] + $opts->{num} < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | $vp->{_devrelease}[1] += $opts->{num}; | |||||||||||||||||||||||||||
| 109 | } elsif ($opts->{part} eq 'epoch') { | ||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $vp->{_epoch} //= 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$vp->{"_epoch"} //= 0
MC/DC0%0/1
$vp->{"_epoch"} //= 0
$vp->{"_epoch"}
Truth table0%0/2
A
A= $vp->{"_epoch"}
| |||||||||||||||||||||||||||||
| 111 | die "Cannot decrease version, would result in a negative $opts->{part} part" | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if $vp->{_epoch} + $opts->{num} < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | $vp->{_epoch} += $opts->{num}; | |||||||||||||||||||||||||||
| 114 | } else { | ||||||||||||||||||||||||||||
| 115 | 0 | die "Invalid part '$opts->{part}'"; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | 9 | $vp->normal; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 2 | 1; | |||||||||||||||||||||||||||
| 121 | # ABSTRACT: Python (PEP 440) version numbering | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||