Skip to content
This repository was archived by the owner on Aug 29, 2021. It is now read-only.

Commit 0a53287

Browse files
committed
[version] make VersionInfo more PEP440 compliant & bump to 0.5.4
1 parent b32f2be commit 0a53287

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

disctools/__version_info__.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from typing import Dict, Literal, Optional, Protocol, Union
2+
from string import ascii_letters, digits
3+
4+
valid_identifier_chars = ascii_letters + digits + "."
25

36
class HasStr(Protocol):
47
def __str__(self) -> str:
@@ -20,12 +23,13 @@ def __repr__(self) -> str:
2023
}
2124

2225
class last_modified:
23-
day = 18
26+
day = 25
2427
month = 5
2528
year = 2021
2629

2730
@classmethod
2831
def date(cls) -> str:
32+
"""Returns date based version of format yyyy.[m]m.[d]d"""
2933
return f"{cls.year}.{cls.month}.{cls.day}"
3034

3135

@@ -37,19 +41,26 @@ class VersionInfo:
3741
patch: int
3842
status: Status
3943
serial: int
40-
post: int
41-
dev: int
44+
post: Optional[int]
45+
dev: Optional[int]
4246
build: Optional[Stringable]
4347

4448
def __init__(self, *, major: int,
4549
minor: int,
4650
patch: int,
47-
status: Status,
51+
status: Optional[Status],
4852
serial: int = 0,
49-
post: int = 0,
50-
dev: int = 0,
53+
post: Optional[int] = None,
54+
dev: Optional[int] = None,
5155
build: Optional[Stringable] = None) -> None:
5256
ver = str(major)
57+
58+
if status:
59+
if status not in status_map.values():
60+
raise ValueError(f"status can only be one of ('a', 'b', 'rc', 'f')")
61+
else:
62+
status = "f"
63+
5364
if minor:
5465
ver += f".{minor}"
5566

@@ -64,16 +75,21 @@ def __init__(self, *, major: int,
6475
elif serial != 0:
6576
raise ValueError("Final release cannot have a serial number!, use post instead.")
6677

67-
if post:
78+
if not post is None:
6879
ver += f".post{post}"
6980

70-
if dev:
81+
if not dev is None:
7182
ver += f".dev{dev}"
7283

7384
if build:
85+
build_s = str(build)
86+
for i in build_s:
87+
if i not in valid_identifier_chars:
88+
raise ValueError(
89+
f"build (Local Identifier) contains invalid character {i} at index {build_s.index(i)}")
7490
ver += f"+{build}"
7591

76-
self._ver = ver
92+
self._ver = ver.strip()
7793
self.major = major
7894
self.minor = minor
7995
self.patch = patch
@@ -93,9 +109,8 @@ def __repr__(self) -> str:
93109
version_info = VersionInfo(
94110
major = 0,
95111
minor = 5,
96-
patch = 3,
97-
status = status_map["final"],
98-
post = 1
112+
patch = 4,
113+
status = status_map["final"]
99114
)
100115

101116
__version__ = str(version_info)

version.num

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.3.post1
1+
0.5.4

0 commit comments

Comments
 (0)