Coverage for /Users/OORDCOR/Documents/code/bump-my-version/bumpversion/versioning/conventions.py: 0%

1"""Standard version conventions."""

2

3 from bumpversion.versioning.models import VersionComponentSpec, VersionSpec

4

5# Adapted from https://packaging.python.org/en/latest/specifications/version-specifiers/

6 PEP440_PATTERN = r"""

7 v?

8 (?:

9 (?P<major>0|[1-9]\d*)\.

10 (?P<minor>0|[1-9]\d*)\.

11 (?P<patch>0|[1-9]\d*)

12 (?: # pre-release

13 [-_\.]?

14 (?P<pre>

15 (?P<pre_l>a|b|c|rc|alpha|beta|pre|preview)

16 [-_\.]?

17 (?P<pre_n>[0-9]+)?

18 )

19 )?

20 (?: # post release

21 [-_\.]?

22 (?P<post>

23 post

24 [-_\.]?

25 [0-9]+

26 )

27 )?

28 (?: # dev release

29 [-_\.]?

30 (?P<dev>

31 dev

32 [-_\.]?

33 [0-9]+

34 )

35 )?

36 )

37 (?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))? # local version

38"""

39 PEP440_SERIALIZE_PATTERNS = [

40 "{major}.{minor}.{patch}{pre_l}{pre_n}.{post}.{dev}+{local}",

41 "{major}.{minor}.{patch}{pre_l}{pre_n}.{post}.{dev}",

42 "{major}.{minor}.{patch}{pre_l}{pre_n}.{post}+{local}",

43 "{major}.{minor}.{patch}{pre_l}{pre_n}.{dev}+{local}",

44 "{major}.{minor}.{patch}.{post}.{dev}+{local}",

45 "{major}.{minor}.{patch}{pre_l}{pre_n}.{post}",

46 "{major}.{minor}.{patch}{pre_l}{pre_n}.{dev}",

47 "{major}.{minor}.{patch}{pre_l}{pre_n}+{local}",

48 "{major}.{minor}.{patch}.{post}.{dev}",

49 "{major}.{minor}.{patch}.{post}+{local}",

50 "{major}.{minor}.{patch}.{dev}+{local}",

51 "{major}.{minor}.{patch}.{pre_l}{pre_n}",

52 "{major}.{minor}.{patch}.{post}",

53 "{major}.{minor}.{patch}.{dev}",

54 "{major}.{minor}.{patch}+{local}",

55 "{major}.{minor}.{patch}",

56]

57 PEP440_COMPONENT_CONFIGS = {

58 "major": VersionComponentSpec(),

59 "minor": VersionComponentSpec(),

60 "patch": VersionComponentSpec(),

61 "pre_l": VersionComponentSpec(values=["", "a", "b", "rc"]),

62 "pre_n": VersionComponentSpec(),

63 "post": VersionComponentSpec(depends_on="patch"),

64 "dev": VersionComponentSpec(depends_on="patch"),

65 "local": VersionComponentSpec(depends_on="patch", optional_value=""),

66}

67

68

69 def pep440_version_spec() -> VersionSpec:

70 """Return a VersionSpec for PEP 440."""

71 return VersionSpec(components=PEP440_COMPONENT_CONFIGS)

72

73

74# Adapted from https://regex101.com/r/Ly7O1x/3/

75 SEMVER_PATTERN = r"""

76 (?P<major>0|[1-9]\d*)\.

77 (?P<minor>0|[1-9]\d*)\.

78 (?P<patch>0|[1-9]\d*)

79 (?:

80 - # dash seperator for pre-release section

81 (?P<pre_l>[a-zA-Z-]+) # pre-release label

82 (?P<pre_n>0|[1-9]\d*) # pre-release version number

83 )? # pre-release section is optional

84 (?:

85 \+ # plus seperator for build metadata section

86 (?P<buildmetadata>

87 [0-9a-zA-Z-]+

88 (?:\.[0-9a-zA-Z-]+)*

89 )

90 )? # build metadata section is optional

91"""

92 SEMVER_SERIALIZE_PATTERNS = [

93 "{major}.{minor}.{patch}-{pre_l}{pre_n}+{buildmetadata}",

94 "{major}.{minor}.{patch}-{pre_l}{pre_n}",

95 "{major}.{minor}.{patch}+{buildmetadata}",

96 "{major}.{minor}.{patch}",

97]

98 SEMVER_COMPONENT_CONFIGS = {

99 "major": VersionComponentSpec(),

100 "minor": VersionComponentSpec(),

101 "patch": VersionComponentSpec(),

102 "pre_l": VersionComponentSpec(values=["", "a", "b", "rc"]),

103 "pre_n": VersionComponentSpec(),

104 "buildmetadata": VersionComponentSpec(independent=True),

105}

106

107

108 def semver_spec() -> VersionSpec:

109 """Return a VersionSpec for SEMVER."""

110 return VersionSpec(components=SEMVER_COMPONENT_CONFIGS)