-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.sh
126 lines (111 loc) · 3.99 KB
/
build.sh
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
#!/bin/bash
# pyimpspec is licensed under the GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.html).
# Copyright 2024 pyimpspec developers
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# The licenses of pyimpspec's dependencies and/or sources of portions of code are included in
# the LICENSES folder.
# Stop when a non-zero exit code is encountered
set -e
docs_html(){
sphinx-build "./docs/source" "./docs/build/html"
}
docs_test(){
sphinx-build -b doctest "./docs/source" "./docs/build/html"
}
docs_latex(){
sphinx-build -M latexpdf "./docs/source" "./docs/build/latex"
}
validate_tar(){
echo
echo "Listing licenses that were bundled in *.tar.gz:"
# Check if the package license was included
tar --list -f ./dist/*.tar.gz | grep "LICENSE$"
# Check if the other licenses were included
dist="$(tar --list -f ./dist/*.tar.gz | grep "LICENSE-.*\.txt" | sort)"
repo="$(ls LICENSES | grep "LICENSE-.*.txt" | sort)"
python -c "from sys import argv; from os.path import basename; dist = set(list(map(basename, argv[1].split('\n')))); repo = set(list(map(basename, argv[2].split('\n')))); assert dist == repo, 'Incorrect set of bundled licenses!'; list(map(print, sorted(dist)))" "$dist" "$repo"
}
validate_wheel(){
echo
echo "Listing licenses that were bundled in *.whl:"
# Check if the package license was included
unzip -Z1 ./dist/*.whl | grep "LICENSE$"
# Check if the other licenses were included
dist="$(unzip -Z1 ./dist/*.whl | grep "LICENSE-.*\.txt" | sort)"
repo="$(ls LICENSES | grep "LICENSE-.*.txt" | sort)"
python -c "from sys import argv; from os.path import basename; dist = set(list(map(basename, argv[1].split('\n')))); repo = set(list(map(basename, argv[2].split('\n')))); assert dist == repo, 'Incorrect set of bundled licenses!'; list(map(print, sorted(dist)))" "$dist" "$repo"
}
if [ "$1" == "docs" ]; then
docs_html
docs_test
docs_latex
exit
fi
if [ "$1" == "docs-html" ]; then
docs_html
exit
fi
if [ "$1" == "docs-test" ]; then
docs_test
exit
fi
if [ "$1" == "docs-latex" ]; then
docs_latex
exit
fi
# Check for uncommitted changes and untracked files
if [ "$(git status --porcelain=v1 | wc -l)" -ne 0 ]; then
echo "Detected uncommitted changes and/or untracked files!"
if ! [ "$1" == "override" ]; then
echo "Continue with the build process anyway by providing 'override' as an argument to this script."
exit
fi
fi
# Check for major issues
# NOTE: May need to skip flake8 in some cases when trying to build. Currently
# (2024-08-29) raising exceptions when running flake8 v7.1.1 on:
# 'Python 3.12.4 (main, Jun 7 2024, 06:33:07) [GCC 14.1.1 20240522] on linux'
flake8 . --select=E9,F63,F7,F82 --show-source --statistics
echo "flake8 didn't find any issues..."
echo
# Update non-source code files that should be included
python3 ./pre-build.py
# Build wheel
python3 -m build
# Validate the source and wheel distributions
validate_tar
validate_wheel
if [ "$1" == "distros" ]; then
exit
fi
# Update documentation
# - The contents of ./dist/html should be committed to the gh-pages branch
# - Run the reset.sh script found in gh-pages
# - Copy the files from ./dist/html
# - Commit
# - Force push
# - ./dist/pyimpspec-X-Y-Z.pdf should be uploaded as an attachment to a release
echo
echo "Generating documentation..."
# Generate HTML, run tests, and finally generate PDF
docs_html
docs_test
docs_latex
# Copy documentation assets
python3 ./post-build.py
# Everything should be okay
echo
echo "Finished!!!"