Repository navigation
Expand file tree
/
Copy pathMakefile.am
More file actions
168 lines (140 loc) · 6.31 KB
/
Copy pathMakefile.am
File metadata and controls
168 lines (140 loc) · 6.31 KB
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
160
161
162
163
164
165
166
167
168
# Network UPS Tools: scripts/python/module (PyNUTClient)
# See also: .github/workflows/PyNUTClient.yml
# Note: this Makefile is focused on PyPI publication
# The usual autotools stuff including clean-up is in parent dir
# (to allow easier mixing of the module and app, if/when desired)
#
# NOTE: Due to PEP-0625, the versioned tarball and directory names
# must be normalized to lower-case, as achieved by setup.py(.in).
# The module name remains camel-cased as it always was.
# Non-maintainers can at most generate the source layout for python setuptools
# (having only shell scripting as a prerequisite suffices for that)
all: PyNUTClient
check-local:
@if test -n "$(PYTHON_DEFAULT)" && test "$(PYTHON_DEFAULT)" != no; then \
$(PYTHON_DEFAULT) "$(builddir)/test_nutclient.py" --disconnect ; \
else \
echo "Skipping Python disconnect tests: no Python interpreter configured" ; \
fi
@echo "You may want to set up a NUT data server and run 'make tox' here: `pwd`"
# NOT tying into "make check" because a lot of stars must align for this test:
tox: dist .pypi-tools-tox
tox
EXTRA_DIST = tox.ini MANIFEST.in
NUT_SOURCE_GITREV_NUMERIC = @NUT_SOURCE_GITREV_NUMERIC@
PYTHON_DEFAULT = @PYTHON_DEFAULT@
GENERATED_DIST = dist build *.egg-info
GENERATED_SRC = PyNUTClient README.txt LICENSE-GPL3
# These are normally generated by a NUT build, but if we want to iterate
# specifically PyNUTClient packaging - `make veryclean dist` should do it here:
GENERATED_PY = test_nutclient.py PyNUT.py setup.py
# (Re-)generate files normally made by `configure` from .in templates
# No touch-files here, intended for manual use in developer iterations
py-in: $(GENERATED_PY)
redist: clean py-in dist
$(GENERATED_DIST): .pypi-dist
# NOTE: We only clean .pypi-tools* in MAINTAINERCLEANFILES to avoid regular
# re-detection of the probably unchanging environment!
clean-local:
rm -rf $(GENERATED_SRC) $(GENERATED_DIST)
rm -f .pypi-src .pypi-dist*
veryclean: clean
rm -f $(GENERATED_PY)
# Python test envs take a while to populate, so maybe better not clean
# them too enthusiastically. Can revise (move to "clean-local") later,
# if this choice proves a problem.
distclean-local:
rm -rf .tox
rm -f $(GENERATED_PY)
MAINTAINERCLEANFILES = Makefile.in .dirstamp .pypi-tools*
PyNUTClient: .pypi-src
# Tagged releases should only have three blocks of digits separated by dots
upload publish: @dotMAKE@
+@echo " PYPI Checking upload type for module version '$(NUT_SOURCE_GITREV_NUMERIC)'" ; \
case x"`echo '$(NUT_SOURCE_GITREV_NUMERIC)' | tr -d '[0-9]'`" in \
x..) echo " PYPI ...release"; $(MAKE) $(AM_MAKEFLAGS) upload-pypi ;; \
x*) echo " PYPI ...testing"; $(MAKE) $(AM_MAKEFLAGS) upload-testpypi ;; \
esac
# README.txt is also a part of module standard expectations
.pypi-src: test_nutclient.py.in PyNUT.py.in setup.py.in README.adoc Makefile $(top_srcdir)/LICENSE-GPL3
@echo " PYPI Generate PyPI module source"
@rm -rf $(GENERATED_SRC) '$@'
@mkdir -p PyNUTClient
@for S in '$(srcdir)'/*.py.in ; do \
B="`basename \"$${S}\" .in`" ; \
if test x"$${B}" = xsetup.py ; then \
if test ! -s "$${B}" ; then \
sed -e "s/[@]NUT_SOURCE_GITREV_NUMERIC[@]/$(NUT_SOURCE_GITREV_NUMERIC)/" < "$(srcdir)/$${B}.in" > "$${B}" || exit ; \
fi ; \
continue; \
fi; \
if test -s "$${B}" ; then \
cp -f "$${B}" PyNUTClient/ || exit ; \
continue; \
fi ; \
sed -e "s,[@]PYTHON_DEFAULT[@],@PYTHON_DEFAULT@," < "$(srcdir)/$${B}.in" > "PyNUTClient/$${B}" || exit ; \
if test -x "$(srcdir)/$${B}.in" ; then chmod +x "PyNUTClient/$${B}"; fi ; \
done ; \
cp -f "$(srcdir)/README.adoc" README.txt || exit ; \
cp -f "$(top_srcdir)/LICENSE-GPL3" . || exit ; \
echo "from . import PyNUT" > PyNUTClient/__init__.py || exit
@touch '$@'
.pypi-tools-python:
@echo " PYPI Checking that PYTHON_DEFAULT variable is defined and usable: $(PYTHON_DEFAULT)"
@test -n "$(PYTHON_DEFAULT)" && command -v $(PYTHON_DEFAULT)
@touch '$@'
.pypi-tools-dist-wheel: .pypi-tools-python
@echo " PYPI Prepare PyPI tools to generate a distribution (wheel)"
@$(PYTHON_DEFAULT) -m pip install wheel
@touch '$@'
.pypi-tools-dist-build: .pypi-tools-python
@echo " PYPI Prepare PyPI tools to generate a distribution (build)"
@$(PYTHON_DEFAULT) -m pip install build
@touch '$@'
.pypi-tools-tox: .pypi-tools-python
@echo " PYPI Prepare Python multi-environment testing tools (tox)"
@$(PYTHON_DEFAULT) -m pip install tox
@touch '$@'
# Install via OS packaging or pip?
# https://twine.readthedocs.io/en/stable/
.pypi-tools-upload: .pypi-tools-python
@echo " PYPI Prepare PyPI tools and resources to upload a distribution (twine)"
@$(PYTHON_DEFAULT) -m pip install twine
@command -v twine
@test -s $(HOME)/.pypirc
@touch '$@'
# Using pypa/setuptools
.pypi-dist: .pypi-src @dotMAKE@
+@$(MAKE) $(AM_MAKEFLAGS) .pypi-dist-pip-build || \
$(MAKE) $(AM_MAKEFLAGS) .pypi-dist-obsolete || \
$(MAKE) $(AM_MAKEFLAGS) .pypi-dist-pip-wheel
@touch '$@'
# The most modern approach as of 2023
.pypi-dist-pip-build: .pypi-tools-dist-build .pypi-src
@echo " PYPI Generate PyPI module distribution (using 'build' module)"
@rm -rf $(GENERATED_DIST) '$@'
@$(PYTHON_DEFAULT) -m build --skip-dependency-check --no-isolation
@touch '$@'
# Using "setup.py" directly causes warnings about its deprecation
# While "pip" distribution generator also uses it internally,
# it "knows what it's doing" and goes quietly about its work :)
# Does not support "sdist" though. Oh well.
.pypi-dist-pip-wheel: .pypi-tools-dist-wheel .pypi-src
@echo " PYPI Generate PyPI module distribution (using 'pip wheel'; note no 'sdist' here)"
@rm -rf $(GENERATED_DIST) '$@'
@$(PYTHON_DEFAULT) -m pip wheel --no-deps -w dist .
@touch '$@'
.pypi-dist-obsolete: .pypi-tools-dist-wheel .pypi-src
@echo " PYPI Generate PyPI module distribution (using setup.py directly)"
@rm -rf $(GENERATED_DIST) '$@'
@$(PYTHON_DEFAULT) setup.py sdist bdist_wheel
@touch '$@'
# These need $HOME/.pypirc prepared with credentials (API tokens) from
# https://pypi.org/manage/account/ and https://test.pypi.org/manage/account/
# TODO: .asc/.sig files for releases?
upload-pypi: .pypi-dist .pypi-tools-upload
@echo " PYPI Upload PyPI module distribution to production/release PyPI repository"
@twine upload dist/*
upload-testpypi: .pypi-dist .pypi-tools-upload
@echo " PYPI Upload PyPI module distribution to testing/staging PyPI repository"
@twine upload -r testpypi dist/*