-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtasks.py
More file actions
47 lines (36 loc) · 1.23 KB
/
tasks.py
File metadata and controls
47 lines (36 loc) · 1.23 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
from pathlib import Path
import re
import sys
from typing import Tuple
from invoke import task
TOP_DIR = Path(__file__).parent.resolve()
def update_file(filename: str, sub_line: Tuple[str, str], strip: str = None):
"""Utility function for tasks to read, update, and write files"""
with open(filename, "r") as handle:
lines = [
re.sub(sub_line[0], sub_line[1], line.rstrip(strip)) for line in handle
]
with open(filename, "w") as handle:
handle.write("\n".join(lines))
handle.write("\n")
@task
def update_version(_, version):
"""Update package version using SemVer"""
if version.startswith("v"):
version = version[1:]
if re.match(r"[0-9]+(\.[0-9]+){2}.*", version) is None:
sys.exit(
f"Error: Passed version ({version}) does to match semantic versioning."
)
update_file(
TOP_DIR.joinpath("ipywidgets_extended/version.py"),
(
r"version_info = .+",
f"version_info = {tuple([int(_) for _ in version.split('.')[:3]])}",
),
)
update_file(
TOP_DIR.joinpath("package.json"),
(r'"version": ".+"', f'"version": "{version}"'),
)
print(f"Bumped version to {version} !")