-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.python
160 lines (121 loc) · 3.95 KB
/
Makefile.python
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
147
148
149
150
151
152
153
154
155
156
157
158
159
#SERIAL 2019011501
VIRTUALENV := virtualenv
VENV := .venv
ifdef USE_PYENV
VENV_ACTIVATE := :
else
VENV_ACTIVATE := source $(VENV)/bin/activate
endif
PREP := $(VENV_ACTIVATE)
PYTEST := env PYTHONPATH=$(PYTHONPATH) PYTEST=1 $(VENV)/bin/py.test
PYLINT := env PYTHONPATH=$(PYTHONPATH) $(VENV)/bin/pylint --disable=I0011 --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}"
PYCODESTYLE := env PYTHONPATH=$(PYTHONPATH) $(VENV)/bin/pycodestyle --repeat --ignore=E202,E501,E402
PYTHON := env PYTHONPATH=$(PYTHONPATH) $(VENV)/bin/python
PIP := $(VENV)/bin/pip
TEST_REQUIREMENTS := -r test-requirements.txt
# Base the name of the software on the spec file
PACKAGE := $(shell basename *.spec .spec)
# Override this arch if the software is arch specific
ARCH = noarch
# Variables for clean build directory tree under repository
BUILDDIR = ./build
ARTIFACTDIR = ./artifacts
SDISTDIR = ${ARTIFACTDIR}/sdist
WHEELDIR = ${ARTIFACTDIR}/wheels
RPMBUILDDIR = ${BUILDDIR}/rpm-build
RPMDIR = ${ARTIFACTDIR}/rpms
DEBBUILDDIR = ${BUILDDIR}/deb-build
DEBDIR = ${ARTIFACTDIR}/debs
# base rpmbuild command that utilizes the local buildroot
# not using the above variables on purpose.
# if you can make it work, PRs are welcome!
RPMBUILD = rpmbuild --define "_topdir %(pwd)/build" \
--define "_sourcedir %(pwd)/artifacts/sdist" \
--define "_builddir %{_topdir}/rpm-build" \
--define "_srcrpmdir %{_rpmdir}" \
--define "_rpmdir %(pwd)/artifacts/rpms"
# Allow which python to be overridden at the environment level
PYTHON := $(shell which python)
ifneq ("$(wildcard setup.py)","")
GET_SDIST = ${PYTHON} setup.py sdist -d "${SDISTDIR}"
else
GET_SDIST = spectool -g -C ${SDISTDIR} ${PACKAGE}.spec
endif
ifneq ($(origin MOCK_REPO), undefined)
MOCK_REPO_MACRO := -r ${MOCK_REPO}
endif
all: rpms
default: check-coding-style
clean:
rm -rf ${BUILDDIR}/ *~
rm -rf docs/*.gz
rm -rf *.egg-info
find . -name '*.pyc' -exec rm -f {} \;
clean_all: clean
rm -rf ${ARTIFACTDIR}/
venv:
test -d $(VENV) || $(VIRTUALENV) $(VENV) --no-site-packages
requirements:
@if [ -d wheelhouse ]; then \
$(PIP) install -q --no-index --find-links=wheelhouse $(TEST_REQUIREMENTS); \
else \
$(PIP) install -q $(TEST_REQUIREMENTS); \
fi
setup: venv requirements
check-coding-style: bootstrap
$(PYCODESTYLE) $(PYTHON_MODULES)
$(PYLINT) -E $(PYTHON_MODULES)
pylint-full: check-coding-style
$(PYLINT) $(PYTHON_MODULES)
test: check-coding-style
$(PYTEST) $(PYTHON_MODULES)
check:
$(PYTEST) $(PYTHON_MODULES)
build: clean
${PYTHON} setup.py build -f
install: build
${PYTHON} setup.py install -f --root ${DESTDIR}/
install_rpms: rpms
yum install ${RPMDIR}/${ARCH}/${PACKAGE}*.${ARCH}.rpm
reinstall: uninstall install
uninstall: clean
rm -f /usr/bin/${PACKAGE}
rm -rf /usr/lib/python*/site-packages/${PACKAGE}
uninstall_rpms: clean
rpm -e ${PACKAGE}
sdist:
mkdir -p ${SDISTDIR}
${GET_SDIST}
wheel:
mkdir -p ${WHEELDIR}
${PYTHON} setup.py bdist_wheel -d "${WHEELDIR}"
prep_rpmbuild: prep_build
mkdir -p ${RPMBUILDDIR}
mkdir -p ${RPMDIR}
-cp -p *.patch ${SDISTDIR}/
rpms: prep_rpmbuild
${RPMBUILD} -ba ${PACKAGE}.spec
srpm: prep_rpmbuild
${RPMBUILD} -bs ${PACKAGE}.spec
mock: srpm
mock ${MOCK_OPTIONS} ${MOCK_REPO_MACRO} --cleanup-after --resultdir=${RPMDIR} ${RPMDIR}/${PACKAGE}*.src.rpm
prep_build: sdist
mkdir -p ${BUILDDIR}
prep_debbuild: prep_build
mkdir -p ${DEBBUILDDIR}
mkdir -p ${DEBDIR}
SDISTPACKAGE=`ls ${SDISTDIR}`; \
BASE=`basename $$SDISTPACKAGE .tar.gz`; \
DEBBASE=`echo $$BASE | sed 's/-/_/'`; \
TARGET=${DEBBUILDDIR}/$$DEBBASE.orig.tar.gz; \
ln -f -s ../../${SDISTDIR}/$$SDISTPACKAGE $$TARGET; \
tar -xz -f $$TARGET -C ${DEBBUILDDIR}; \
rm -rf ${DEBBUILDDIR}/$$BASE/debian; \
cp -pr debian/ ${DEBBUILDDIR}/$$BASE
debs: prep_debbuild
SDISTPACKAGE=`ls ${SDISTDIR}`; \
BASE=`basename $$SDISTPACKAGE .tar.gz`; \
cd ${DEBBUILDDIR}/$$BASE; \
debuild -uc -us
mv ${DEBBUILDDIR}/*.deb ${DEBDIR}/
.PHONY: default venv requirements bootstrap check-coding-style pylint-full test check