Skip to content

Commit aa69bde

Browse files
committed
finalize improvements
1 parent cae1560 commit aa69bde

File tree

6 files changed

+306
-254
lines changed

6 files changed

+306
-254
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
## 1.2.1 (2025-06-23)
44

55
- Fix test-script to not end with backslash if there is no `testpaths` (which is valid).
6+
Improve tests to cover more edge cases, i.e. above and multi-line.
7+
- Fix Python check for global UV and use PRIMARY_PYTHON for UV as version definition.
8+
- Improve test to read large amount of output from file (Makefile template check).
69

710
## 1.2.0 (2025-06-04)
811

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ EXTRA_PATH?=
4747

4848
# Primary Python interpreter to use. It is used to create the
4949
# virtual environment if `VENV_ENABLED` and `VENV_CREATE` are set to `true`.
50+
# If global `uv` is used, this value is passed as `--python VALUE` to the venv creation.
51+
# uv then downloads the Python interpreter if it is not available.
52+
# for more on this feature read the [uv python documentation](https://docs.astral.sh/uv/concepts/python-versions/)
5053
# Default: python3
5154
PRIMARY_PYTHON?=python3
5255

@@ -229,7 +232,7 @@ $(SENTINEL): $(firstword $(MAKEFILE_LIST))
229232
# mxenv
230233
##############################################################################
231234

232-
export OS:=$(OS)
235+
OS?=
233236

234237
# Determine the executable path
235238
ifeq ("$(VENV_ENABLED)", "true")
@@ -254,8 +257,12 @@ endif
254257

255258
MXENV_TARGET:=$(SENTINEL_FOLDER)/mxenv.sentinel
256259
$(MXENV_TARGET): $(SENTINEL)
260+
ifneq ("$(PYTHON_PACKAGE_INSTALLER)$(MXENV_UV_GLOBAL)","uvfalse")
257261
@$(PRIMARY_PYTHON) -c "import sys; vi = sys.version_info; sys.exit(1 if (int(vi[0]), int(vi[1])) >= tuple(map(int, '$(PYTHON_MIN_VERSION)'.split('.'))) else 0)" \
258262
&& echo "Need Python >= $(PYTHON_MIN_VERSION)" && exit 1 || :
263+
else
264+
@echo "Use Python $(PYTHON_MIN_VERSION) over uv"
265+
endif
259266
@[[ "$(VENV_ENABLED)" == "true" && "$(VENV_FOLDER)" == "" ]] \
260267
&& echo "VENV_FOLDER must be configured if VENV_ENABLED is true" && exit 1 || :
261268
@[[ "$(VENV_ENABLED)$(PYTHON_PACKAGE_INSTALLER)" == "falseuv" ]] \
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
{% extends "env.sh" %}
22

33
{% block env_content %}
4-
5-
pytest {% if testpaths %}\{% endif %}
4+
pytest {% if testpaths %}\{%+ endif +%}
65
{% for path in testpaths %}
7-
{{ path }}{% if not loop.last %} \{% endif %}
6+
{{ path }}{% if not loop.last %} \ {%+ endif +%}
87

98
{% endfor %}
109

11-
12-
1310
{% endblock %}

src/mxmake/tests/expected/Makefile

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
##############################################################################
2+
# THIS FILE IS GENERATED BY MXMAKE
3+
#
4+
# DOMAINS:
5+
#: core.base
6+
#: core.mxenv
7+
#
8+
# SETTINGS (ALL CHANGES MADE BELOW SETTINGS WILL BE LOST)
9+
##############################################################################
10+
11+
## core.base
12+
13+
# `deploy` target dependencies.
14+
# No default value.
15+
DEPLOY_TARGETS?=
16+
17+
# target to be executed when calling `make run`
18+
# No default value.
19+
RUN_TARGET?=
20+
21+
# Additional files and folders to remove when running clean target
22+
# No default value.
23+
CLEAN_FS?=
24+
25+
# Optional makefile to include before default targets. This can
26+
# be used to provide custom targets or hook up to existing targets.
27+
# Default: include.mk
28+
INCLUDE_MAKEFILE?=include.mk
29+
30+
# Optional additional directories to be added to PATH in format
31+
# `/path/to/dir/:/path/to/other/dir`. Gets inserted first, thus gets searched
32+
# first.
33+
# No default value.
34+
EXTRA_PATH?=
35+
36+
## core.mxenv
37+
38+
# Primary Python interpreter to use. It is used to create the
39+
# virtual environment if `VENV_ENABLED` and `VENV_CREATE` are set to `true`.
40+
# If global `uv` is used, this value is passed as `--python VALUE` to the venv creation.
41+
# uv then downloads the Python interpreter if it is not available.
42+
# for more on this feature read the [uv python documentation](https://docs.astral.sh/uv/concepts/python-versions/)
43+
# Default: python3
44+
PRIMARY_PYTHON?=python3
45+
46+
# Minimum required Python version.
47+
# Default: 3.9
48+
PYTHON_MIN_VERSION?=3.9
49+
50+
# Install packages using the given package installer method.
51+
# Supported are `pip` and `uv`. If uv is used, its global availability is
52+
# checked. Otherwise, it is installed, either in the virtual environment or
53+
# using the `PRIMARY_PYTHON`, dependent on the `VENV_ENABLED` setting. If
54+
# `VENV_ENABLED` and uv is selected, uv is used to create the virtual
55+
# environment.
56+
# Default: pip
57+
PYTHON_PACKAGE_INSTALLER?=pip
58+
59+
# Flag whether to use a global installed 'uv' or install
60+
# it in the virtual environment.
61+
# Default: false
62+
MXENV_UV_GLOBAL?=false
63+
64+
# Flag whether to use virtual environment. If `false`, the
65+
# interpreter according to `PRIMARY_PYTHON` found in `PATH` is used.
66+
# Default: true
67+
VENV_ENABLED?=true
68+
69+
# Flag whether to create a virtual environment. If set to `false`
70+
# and `VENV_ENABLED` is `true`, `VENV_FOLDER` is expected to point to an
71+
# existing virtual environment.
72+
# Default: true
73+
VENV_CREATE?=true
74+
75+
# The folder of the virtual environment.
76+
# If `VENV_ENABLED` is `true` and `VENV_CREATE` is true it is used as the
77+
# target folder for the virtual environment. If `VENV_ENABLED` is `true` and
78+
# `VENV_CREATE` is false it is expected to point to an existing virtual
79+
# environment. If `VENV_ENABLED` is `false` it is ignored.
80+
# Default: .venv
81+
VENV_FOLDER?=.venv
82+
83+
# mxdev to install in virtual environment.
84+
# Default: mxdev
85+
MXDEV?=mxdev
86+
87+
# mxmake to install in virtual environment.
88+
# Default: mxmake
89+
MXMAKE?=mxmake
90+
91+
##############################################################################
92+
# END SETTINGS - DO NOT EDIT BELOW THIS LINE
93+
##############################################################################
94+
95+
INSTALL_TARGETS?=
96+
DIRTY_TARGETS?=
97+
CLEAN_TARGETS?=
98+
PURGE_TARGETS?=
99+
100+
export PATH:=$(if $(EXTRA_PATH),$(EXTRA_PATH):,)$(PATH)
101+
102+
# Defensive settings for make: https://tech.davis-hansson.com/p/make/
103+
SHELL:=bash
104+
.ONESHELL:
105+
# for Makefile debugging purposes add -x to the .SHELLFLAGS
106+
.SHELLFLAGS:=-eu -o pipefail -O inherit_errexit -c
107+
.SILENT:
108+
.DELETE_ON_ERROR:
109+
MAKEFLAGS+=--warn-undefined-variables
110+
MAKEFLAGS+=--no-builtin-rules
111+
112+
# mxmake folder
113+
MXMAKE_FOLDER?=.mxmake
114+
115+
# Sentinel files
116+
SENTINEL_FOLDER?=$(MXMAKE_FOLDER)/sentinels
117+
SENTINEL?=$(SENTINEL_FOLDER)/about.txt
118+
$(SENTINEL): $(firstword $(MAKEFILE_LIST))
119+
@mkdir -p $(SENTINEL_FOLDER)
120+
@echo "Sentinels for the Makefile process." > $(SENTINEL)
121+
122+
##############################################################################
123+
# mxenv
124+
##############################################################################
125+
126+
OS?=
127+
128+
# Determine the executable path
129+
ifeq ("$(VENV_ENABLED)", "true")
130+
export VIRTUAL_ENV=$(abspath $(VENV_FOLDER))
131+
ifeq ("$(OS)", "Windows_NT")
132+
VENV_EXECUTABLE_FOLDER=$(VIRTUAL_ENV)/Scripts
133+
else
134+
VENV_EXECUTABLE_FOLDER=$(VIRTUAL_ENV)/bin
135+
endif
136+
export PATH:=$(VENV_EXECUTABLE_FOLDER):$(PATH)
137+
MXENV_PYTHON=python
138+
else
139+
MXENV_PYTHON=$(PRIMARY_PYTHON)
140+
endif
141+
142+
# Determine the package installer
143+
ifeq ("$(PYTHON_PACKAGE_INSTALLER)","uv")
144+
PYTHON_PACKAGE_COMMAND=uv pip
145+
else
146+
PYTHON_PACKAGE_COMMAND=$(MXENV_PYTHON) -m pip
147+
endif
148+
149+
MXENV_TARGET:=$(SENTINEL_FOLDER)/mxenv.sentinel
150+
$(MXENV_TARGET): $(SENTINEL)
151+
ifneq ("$(PYTHON_PACKAGE_INSTALLER)$(MXENV_UV_GLOBAL)","uvfalse")
152+
@$(PRIMARY_PYTHON) -c "import sys; vi = sys.version_info; sys.exit(1 if (int(vi[0]), int(vi[1])) >= tuple(map(int, '$(PYTHON_MIN_VERSION)'.split('.'))) else 0)" \
153+
&& echo "Need Python >= $(PYTHON_MIN_VERSION)" && exit 1 || :
154+
else
155+
@echo "Use Python $(PYTHON_MIN_VERSION) over uv"
156+
endif
157+
@[[ "$(VENV_ENABLED)" == "true" && "$(VENV_FOLDER)" == "" ]] \
158+
&& echo "VENV_FOLDER must be configured if VENV_ENABLED is true" && exit 1 || :
159+
@[[ "$(VENV_ENABLED)$(PYTHON_PACKAGE_INSTALLER)" == "falseuv" ]] \
160+
&& echo "Package installer uv does not work with a global Python interpreter." && exit 1 || :
161+
ifeq ("$(VENV_ENABLED)", "true")
162+
ifeq ("$(VENV_CREATE)", "true")
163+
ifeq ("$(PYTHON_PACKAGE_INSTALLER)$(MXENV_UV_GLOBAL)","uvtrue")
164+
@echo "Setup Python Virtual Environment using package 'uv' at '$(VENV_FOLDER)'"
165+
@uv venv -p $(PRIMARY_PYTHON) --seed $(VENV_FOLDER)
166+
else
167+
@echo "Setup Python Virtual Environment using module 'venv' at '$(VENV_FOLDER)'"
168+
@$(PRIMARY_PYTHON) -m venv $(VENV_FOLDER)
169+
@$(MXENV_PYTHON) -m ensurepip -U
170+
endif
171+
endif
172+
else
173+
@echo "Using system Python interpreter"
174+
endif
175+
ifeq ("$(PYTHON_PACKAGE_INSTALLER)$(MXENV_UV_GLOBAL)","uvfalse")
176+
@echo "Install uv"
177+
@$(MXENV_PYTHON) -m pip install uv
178+
endif
179+
@$(PYTHON_PACKAGE_COMMAND) install -U pip setuptools wheel
180+
@echo "Install/Update MXStack Python packages"
181+
@$(PYTHON_PACKAGE_COMMAND) install -U $(MXDEV) $(MXMAKE)
182+
@touch $(MXENV_TARGET)
183+
184+
.PHONY: mxenv
185+
mxenv: $(MXENV_TARGET)
186+
187+
.PHONY: mxenv-dirty
188+
mxenv-dirty:
189+
@rm -f $(MXENV_TARGET)
190+
191+
.PHONY: mxenv-clean
192+
mxenv-clean: mxenv-dirty
193+
ifeq ("$(VENV_ENABLED)", "true")
194+
ifeq ("$(VENV_CREATE)", "true")
195+
@rm -rf $(VENV_FOLDER)
196+
endif
197+
else
198+
@$(PYTHON_PACKAGE_COMMAND) uninstall -y $(MXDEV)
199+
@$(PYTHON_PACKAGE_COMMAND) uninstall -y $(MXMAKE)
200+
endif
201+
202+
INSTALL_TARGETS+=mxenv
203+
DIRTY_TARGETS+=mxenv-dirty
204+
CLEAN_TARGETS+=mxenv-clean
205+
206+
##############################################################################
207+
# Custom includes
208+
##############################################################################
209+
210+
-include $(INCLUDE_MAKEFILE)
211+
212+
##############################################################################
213+
# Default targets
214+
##############################################################################
215+
216+
INSTALL_TARGET:=$(SENTINEL_FOLDER)/install.sentinel
217+
$(INSTALL_TARGET): $(INSTALL_TARGETS)
218+
@touch $(INSTALL_TARGET)
219+
220+
.PHONY: install
221+
install: $(INSTALL_TARGET)
222+
@touch $(INSTALL_TARGET)
223+
224+
.PHONY: run
225+
run: $(RUN_TARGET)
226+
227+
.PHONY: deploy
228+
deploy: $(DEPLOY_TARGETS)
229+
230+
.PHONY: dirty
231+
dirty: $(DIRTY_TARGETS)
232+
@rm -f $(INSTALL_TARGET)
233+
234+
.PHONY: clean
235+
clean: dirty $(CLEAN_TARGETS)
236+
@rm -rf $(CLEAN_TARGETS) $(MXMAKE_FOLDER) $(CLEAN_FS)
237+
238+
.PHONY: purge
239+
purge: clean $(PURGE_TARGETS)
240+
241+
.PHONY: runtime-clean
242+
runtime-clean:
243+
@echo "Remove runtime artifacts, like byte-code and caches."
244+
@find . -name '*.py[c|o]' -delete
245+
@find . -name '*~' -exec rm -f {} +
246+
@find . -name '__pycache__' -exec rm -fr {} +
247+

0 commit comments

Comments
 (0)