-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtasks.py
80 lines (60 loc) · 1.92 KB
/
tasks.py
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
76
77
78
79
80
import sys
import shutil
from pathlib import Path
from invoke import task
@task
def test(c, nbs=False):
"""Run unit tests + flake8"""
args = "" if nbs else "--ignore=tests/test_sample_notebooks.py"
c.run(f"pytest {args}", pty=True)
c.run("flake8")
@task
def setup(c, version=None):
"""
Setup dev environment, requires conda
"""
version = version or "3.9"
suffix = "" if version == "3.9" else version.replace(".", "")
env_name = f"soorgeon{suffix}"
c.run(f"conda create --name {env_name} python={version} --yes")
c.run(
'eval "$(conda shell.bash hook)" '
f"&& conda activate {env_name} "
"&& pip install --editable .[dev]"
)
print(f"Done! Activate your environment with:\nconda activate {env_name}")
@task(aliases=["v"])
def version(c):
"""Create a new version of this project"""
from pkgmt import versioneer
versioneer.version(project_root=".", tag=True)
@task(aliases=["r"])
def release(c, tag, production=True):
"""Upload to PyPI (prod by default): inv upload {tag}"""
from pkgmt import versioneer
versioneer.upload(tag, production=production)
@task
def install_git_hook(c, force=False):
"""Installs pre-push git hook"""
path = Path(".git/hooks/pre-push")
hook_exists = path.is_file()
if hook_exists:
if force:
path.unlink()
else:
sys.exit(
"Error: pre-push hook already exists. "
'Run: "invoke install-git-hook -f" to force overwrite.'
)
shutil.copy(".githooks/pre-push", ".git/hooks")
print(f"pre-push hook installed at {str(path)}")
@task
def uninstall_git_hook(c):
"""Uninstalls pre-push git hook"""
path = Path(".git/hooks/pre-push")
hook_exists = path.is_file()
if hook_exists:
path.unlink()
print(f"Deleted {str(path)}.")
else:
print("Hook doesn't exist, nothing to delete.")