-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.ps1
146 lines (130 loc) · 3.32 KB
/
make.ps1
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Parameter definition
param(
[switch]$docs = $false,
[switch]$run = $false,
[switch]$act = $false,
[switch]$type = $false,
[switch]$no_rebuild = $false,
[switch]$format = $false,
[switch]$clean = $false,
[switch]$test = $false,
[switch]$pub = $false,
[switch]$to_pypi = $false,
[switch]$h = $false)
# Builds the documentation. Use `rebuild` = true, if a module has been
# added, or conf.py changed.
function make_docs ($rebuild = $true) {
Set-Location docs
if ($rebuild) {
Remove-Item sphinx -Force -Recurse -ErrorAction Ignore
mkdir sphinx
Set-Location sphinx
sphinx-apidoc -F -H 'Story Time' -A 'Chris' -o . '../../' "../../setup.py"
Copy-Item ../conf.py .
Set-Location ..
python doc_helper.py
}
Set-Location sphinx
./make html SPHINXBUILD='python $(shell which sphinx-build)'
Set-Location ../..
}
# Aborts script if previous command failed
function abort_failure {
if (-Not $?) {
Write-Host("ERROR: Publishing failed!")
Break
}
}
# Runs the tests using pytest
function run{
activate_env
python .\story_time\main.py
}
# Runs the tests using pytest
function activate_env {
venv/Scripts/activate.ps1
}
# Runs the tests using pytest
function run_tests ($abort = $false) {
activate_env
pytest tests --cov=story_time --cov-report html -v
if ($abort){
abort_failure
}
}
# Publish changes to PyPI. Checks if the tests are run successfully
# and if the code formatting is fine.
function publish_to_pypi {
# Remove old stuff
Remove-Item dist -Recurse -ErrorAction Ignore
Remove-Item build -Recurse -ErrorAction Ignore
Remove-Item *.egg-info -Recurse -ErrorAction Ignore
# Install stuff
pip install twine keyring
pip install setuptools
pip install wheel
# Check formatting and style
black --check .
abort_failure
flake8 tests --max-line-length=90
abort_failure
flake8 story_time --max-line-length=90
abort_failure
# Run tests
venv/Scripts/activate.ps1
run_tests($true)
# Handle version
$version = ((Get-Content -Path version.txt) | Out-String).Trim()
Write-Host("Previous version is: $version")
$new_vers = Read-Host -Prompt 'New version'
$new_vers | Set-Content 'version.txt'
# Upload to PyPI
python setup.py sdist bdist_wheel
$username = "chbauman"
$pw = (keyring get https://upload.pypi.org/legacy/ $username) | Out-String
if($to_pypi){
twine upload dist/* -u $username -p $pw.Trim()
} else {
twine upload dist/* --repository-url https://test.pypi.org/legacy/ -u $username -p $pw.Trim()
}
}
# Run type checker
function typecheck {
mypy story_time --ignore-missing-imports --disallow-untyped-defs
}
# Cleans up some files
function clean {
Remove-Item Info.txt -Recurse -ErrorAction Ignore
Remove-Item .pytest_cache -Force -Recurse -ErrorAction Ignore
Remove-Item *__pycache__* -Force -Recurse -ErrorAction Ignore
}
# Do the actual stuff
if ($h) {
Get-Help .\make.ps1
}
if ($docs) {
make_docs(-Not $no_rebuild)
}
if ($run) {
run
}
if ($type) {
typecheck
}
if ($pub) {
publish_to_pypi
}
if ($format) {
black .
flake8 tests --max-line-length=90
flake8 story_time --max-line-length=90
}
if ($clean) {
clean
}
if ($act) {
activate_env
}
if ($test) {
run_tests
}