forked from matthewdeanmartin/jiggle_version
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjiggle_version_self.py
More file actions
75 lines (67 loc) · 2.53 KB
/
jiggle_version_self.py
File metadata and controls
75 lines (67 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
Stupider version of jiggle version that jiggle_version depends on.
I didn't want a weird circular dependency.
"""
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
import os.path
from semantic_version import Version
PROJECT = "jiggle_version"
SRC = ""
files = ["/__init__.py", "/_version.py"]
DEBUG = False
version = None
for file_name in files:
to_write = []
with open(SRC + PROJECT + file_name, "r") as infile:
for line in infile:
if line.strip().startswith("__version__"):
if '"' not in line:
print(file_name)
print(line)
raise TypeError("Please format your code with Black.")
else:
parts = line.split('"')
if len(parts) != 3:
raise TypeError(
'Version must be of form __version__ = "1.1.1" with no comments'
)
if version is None:
version = Version(parts[1])
next_version = version.next_patch()
to_write.append('__version__ = "{0}"'.format(str(next_version)))
else:
to_write.append(line)
if DEBUG:
for line in to_write:
print(line, end="")
else:
with open(SRC + PROJECT + file_name, "w") as outfile:
outfile.writelines(to_write)
# setup.py related. setup.py itself should read __init__.py or __version__.py
to_write = []
other_files = ["setup.cfg"]
for file_name in other_files:
filepath = SRC + file_name
if os.path.isfile(filepath):
with open(filepath, "r") as infile:
for line in infile:
if "version =" in line or "version=" in line:
parts = line.split("=")
if len(parts) != 2:
print(line)
print(parts)
raise TypeError("Must be of form version = 1.1.1")
if version is None:
version = Version(parts[1].strip(" "))
next_version = version.next_patch()
to_write.append("version={0}\n".format(str(next_version)))
else:
to_write.append(line)
if DEBUG:
for line in to_write:
print(line, end="")
else:
with open(SRC + file_name, "w") as outfile:
outfile.writelines(to_write)