forked from bennylope/django-organizations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
113 lines (85 loc) · 2.91 KB
/
noxfile.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""
nox configuration to systematize release and pre-release tasks
Several nox tasks copied from the pipx project, Copyright (c) 2018 Chad Smith
"""
import os
import subprocess
import nox
NOX_DIR = os.path.abspath(os.path.dirname(__file__))
DEFAULT_INTERPRETER = "3.8"
ALL_INTERPRETERS = (DEFAULT_INTERPRETER,)
DEV_INSTALL_REQUIREMENTS = ("six", "django-autoslug")
def get_path(*names):
return os.path.join(NOX_DIR, *names)
@nox.session(python=DEFAULT_INTERPRETER, reuse_venv=True)
def manage(session, *args):
"""
Runs management commands in a nox environment
The use for this command is primarily here for running
migrations, but it can be used to run any Django command,
e.g. running a quick dev server (though that much is
expected to be of little benefit).
Args:
session: nox's session
*args: either direct arguments from the command line
or passed through from another command. This
makes the command function reusable from more
explicitly named commands
Returns:
None
"""
session.install("six")
session.install("django-autoslug")
session.install("Django==3.1")
session.install('-e', '.')
args = args if args else session.posargs
session.run("python", "manage.py", *args)
@nox.session
def clean(session):
"""Removes build artifacts"""
for rmdir in ["build/", "dist/", "*.egg-info"]:
session.run("rm", "-rf", rmdir, external=True)
@nox.session(python=DEFAULT_INTERPRETER)
def build(session):
session.install("setuptools")
session.install("wheel")
session.install("docutils")
session.install("twine")
clean(session)
session.run("python", "setup.py", "--quiet", "sdist", "bdist_wheel")
def has_changes():
status = (
subprocess.run(
"git status --porcelain", shell=True, check=True, stdout=subprocess.PIPE
)
.stdout.decode()
.strip()
)
return len(status) > 0
def get_branch():
return (
subprocess.run(
"git rev-parse --abbrev-ref HEAD",
shell=True,
check=True,
stdout=subprocess.PIPE,
)
.stdout.decode()
.strip()
)
@nox.session(python=DEFAULT_INTERPRETER)
def publish(session):
if has_changes():
session.error("All changes must be committed or removed before publishing")
branch = get_branch()
if branch != "master":
session.error(f"Must be on 'master' branch. Currently on {branch!r} branch")
build(session)
session.run("twine", "check", "dist/*")
print("REMINDER: Has the changelog been updated?")
session.run("python", "-m", "twine", "upload", "dist/*")
@nox.session(python=DEFAULT_INTERPRETER, reuse_venv=True)
def docs(session):
session.run("make", "-C", "docs", "clean")
session.run("make", "-C", "docs", "html")
session.run("open", "docs/_build/html/index.html")