-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.venv.mk
227 lines (187 loc) · 5.31 KB
/
Makefile.venv.mk
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# file generated by <https://github.com/g3w-suite/makefiles/>
# don't change, don't track in version control
##
# USAGE: include it your main Makefile as follows:
##
# install: Makefile.venv.mk
#
# Makefile.venv.mk:
# wget https://raw.githubusercontent.com/g3w-suite/makefiles/master/$@
#
# include Makefile.venv.mk
##
PKG_NAME ?= $(CURDIR_NAME)
PKG_DESC ?= Insert project description here
CURDIR_NAME ?= $(notdir $(CURDIR))
# ANSI color codes
H1__ ?= "\n\n\033[0;32m\#\#\# "
__H1 ?= " \#\#\# \033[0m\n"
# Python command used to create the venv.
GLOBAL_PYTHON ?= python3
# Python commands used within the venv.
VENV_ROOT ?= venv
VENV_BIN ?= $(VENV_ROOT)/bin
VENV_PIP ?= $(VENV_BIN)/pip3
VENV_PYTHON ?= $(VENV_BIN)/python
# pyproject.toml
define PYPROJECT_TEMPLATE
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools>=67",
"setuptools_scm[toml]>=7.1"
]
[project]
name = "$(PKG_NAME)"
dynamic = [
"version", # retrieve package version from git tags
"dependencies", # retrieve package dependencies from requirements.txt
"optional-dependencies" # retrieve development dependencies from requirements_dev.txt
]
authors = [ { name = "Gis3w snc", email = "[email protected]" } ]
description = "$(PKG_DESC)"
readme = "README.md"
license = { text = "Mozilla Public License 2.0 (MPL 2.0)" }
classifiers = [
"Development Status :: 3 - Beta",
"Environment :: Web Environment",
"Framework :: Django",
"Intended Audience :: Developers",
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Libraries",
]
# requires-python = ">=3.10"
[project.urls]
"Homepage" = "https://github.com/g3w-suite/$(PKG_NAME)"
"Bug Tracker" = "https://github.com/g3w-suite/$(PKG_NAME)/issues"
[tool.setuptools]
# Manual package discovery
# packages = ["$(PKG_NAME)"]
# package-dir = { $(PKG_NAME) = "$(PKG_NAME)" }
#
# https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#automatic-discovery
#
# NB: see also: MANIFEST.in
[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }
[tool.setuptools.dynamic.optional-dependencies]
dev = { file = ["requirements_dev.txt"] }
[tool.setuptools_scm]
fallback_version = "0.0.0-alpha.0"
write_to = "_version.py" # hardcode version number in a file
#
# Or alternatively retrieve it at runtime:
# https://github.com/pypa/setuptools_scm/#retrieving-package-version-at-runtime
endef
export PYPROJECT_TEMPLATE
# MANIFEST.in
define MANIFEST_TEMPLATE
include LICENSE
include README.md
recursive-include $(PKG_NAME)/static *
recursive-include $(PKG_NAME)/templates *
endef
export MANIFEST_TEMPLATE
# .gitignore
define GITIGNORE_TEMPLATE
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# Python setuptools
*.egg
*.egg-info/
*.eggs
# Python virtualenv
.venv/
venv/
# PyPi related files
.coverage
dist/
build/
_version.py
endef
export GITIGNORE_TEMPLATE
##
# Initialize a new python virtual env
##
venv: clean-venv pkg-files
@echo $(H1__)Creating a new Python environment: $(VENV_ROOT) $(__H1)
$(GLOBAL_PYTHON) -m venv --system-site-packages --prompt $(PKG_NAME) $(VENV_ROOT)
@echo
@echo done.
@echo
@echo To active it manually, run:
@echo
@echo " . $(VENV_BIN)/activate"
@echo
@echo '(learn more: https://docs.python.org/3/library/venv.html)'
@echo
@$(MAKE) install-reqs
##
# Install python package dependencies:
#
# - required for publishing to the Python Package Index (pip3, build, twine)
# - required for local development (requirements_dev.txt and requirements.txt)
# - and the package itself in editable mode for local development
##
install-reqs:
@echo $(H1__)Updating packaging tools$(__H1)
$(VENV_PIP) install --upgrade build twine
@echo $(H1__)Installing dev requirements$(__H1)
-$(VENV_PIP) install --upgrade '.[dev]'
@echo $(H1__)Installing $(PKG_NAME) package$(__H1)
$(VENV_PIP) install --upgrade --editable .
@echo
##
# Uninstall current package (disable editable mode)
##
uninstall:
@echo $(H1__)Uninstalling $(PKG_NAME) package$(__H1)
- $(VENV_PIP) uninstall --yes $(PKG_NAME)
@echo
@echo "Verifying…"
cd .. && ! $(VENV_PYTHON) -m $(PKG_NAME) --version
@echo
@echo "Done"
@echo
.PHONY: build
##
# Generate python files for PyPi
##
build:
rm -rf build/ dist/
$(VENV_PYTHON) -m build
##
# Publish python package to PyPi
##
publish: build
$(VENV_BIN)/twine check dist/*
$(VENV_BIN)/twine upload dist/*
##
# Clear python virtual env
##
clean-venv:
@echo $(H1__)Clearing $(VENV_ROOT) $(__H1)
rm -rf $(VENV_ROOT)
rm -rf *.egg dist build .coverage .cache .pytest_cache $(PKG_NAME).egg-info _version.py
find . -name '__pycache__' -delete -o -name '*.pyc' -delete
@echo "Done"
@echo
##
# Ensure that all the files needed for a PyPi package are there
##
pkg-files: requirements.txt requirements_dev.txt pyproject.toml MANIFEST.in README.md .gitignore LICENSE
@:
requirements.txt requirements_dev.txt README.md:
touch $@
pyproject.toml:
echo "$$PYPROJECT_TEMPLATE" > $@
MANIFEST.in:
echo "$$MANIFEST_TEMPLATE" > $@
.gitignore:
echo "$$GITIGNORE_TEMPLATE" > $@
LICENSE:
wget https://raw.githubusercontent.com/g3w-suite/makefiles/master/$@