-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtasks.py
63 lines (44 loc) · 1.45 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
import json
import os
import toml
from invoke import task
@task
def install_hooks(c):
"""Install git hooks."""
c.run("pre-commit install")
c.run("pre-commit install -t pre-push")
@task(aliases=["format"])
def black(c):
"""Format modules using black."""
c.run("black klaxon/ tests/ tasks.py")
@task(aliases=["check-black"])
def check_formatting(c):
"""Check that files conform to black standards."""
c.run("black --check klaxon/ tests/ tasks.py")
@task
def mypy(c):
"""Type-check code."""
c.run("mypy klaxon/ tests/ tasks.py --ignore-missing-imports")
@task
def unit_tests(c):
"""Run unit tests via pytest."""
c.run("pytest tests/")
@task(check_formatting, mypy, unit_tests)
def publish(c, username=None, password=None):
"""Publish to pypi."""
username = username or os.getenv("PYPI_USERNAME")
password = password or os.getenv("PYPI_PASSWORD")
*_, latest_release = json.loads(c.run("qypi releases klaxon", hide=True).stdout)[
"klaxon"
]
latest_release_version = latest_release["version"]
local_version = toml.load("pyproject.toml")["tool"]["poetry"]["version"]
if local_version == latest_release_version:
print("local and release version are identical -- skipping publish")
else:
print(f"publishing klaxon v{local_version}")
c.run(
f"poetry publish -u {username} -p '{password}' --build",
pty=True,
hide=True,
)