Skip to content

Commit

Permalink
Use python -m pip all over the place instead of pip executable. I…
Browse files Browse the repository at this point in the history
…ntroduce `MXENV_PYTHON`. It defines the Python binary used for all mxmake operations. Remove ruff cache when running `make ruff-clean` target.
  • Loading branch information
rnixx committed Feb 9, 2024
1 parent 9c181c0 commit 511affd
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 77 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## 1.0a4 (unreleased)

- Use `python -m pip` all over the place instead of `pip` executable.

- Introduce `MXENV_PYTHON`. It defines the Python binary used for all
mxmake operations.

- Remove ruff cache when running `make ruff-clean` target.

- Add `wtr` (Web test runner) domain to `js` topic.


Expand Down
50 changes: 28 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ endif
# determine the executable path
ifeq ("$(VENV_ENABLED)", "true")
MXENV_PATH=$(VENV_FOLDER)/bin/
MXENV_PYTHON=$(MXENV_PATH)python
else
MXENV_PATH=
MXENV_PYTHON=$(PYTHON_BIN)
endif

MXENV_TARGET:=$(SENTINEL_FOLDER)/mxenv.sentinel
Expand All @@ -205,9 +207,10 @@ ifeq ("$(VENV_CREATE)", "true")
@$(PYTHON_BIN) -m venv $(VENV_FOLDER)
endif
endif
@$(MXENV_PATH)pip install -U pip setuptools wheel
@$(MXENV_PATH)pip install -U $(MXDEV)
@$(MXENV_PATH)pip install -U $(MXMAKE)
@$(MXENV_PYTHON) -m ensurepip -U
@$(MXENV_PYTHON) -m pip install -U pip setuptools wheel
@$(MXENV_PYTHON) -m pip install -U $(MXDEV)
@$(MXENV_PYTHON) -m pip install -U $(MXMAKE)
@touch $(MXENV_TARGET)

.PHONY: mxenv
Expand All @@ -224,8 +227,8 @@ ifeq ("$(VENV_CREATE)", "true")
@rm -rf $(VENV_FOLDER)
endif
else
@$(MXENV_PATH)pip uninstall -y $(MXDEV)
@$(MXENV_PATH)pip uninstall -y $(MXMAKE)
@$(MXENV_PYTHON) -m pip uninstall -y $(MXDEV)
@$(MXENV_PYTHON) -m pip uninstall -y $(MXMAKE)
endif

INSTALL_TARGETS+=mxenv
Expand All @@ -239,7 +242,7 @@ CLEAN_TARGETS+=mxenv-clean
RUFF_TARGET:=$(SENTINEL_FOLDER)/ruff.sentinel
$(RUFF_TARGET): $(MXENV_TARGET)
@echo "Install Ruff"
@$(MXENV_PATH)pip install ruff
@$(MXENV_PYTHON) -m pip install ruff
@touch $(RUFF_TARGET)

.PHONY: ruff-check
Expand All @@ -258,7 +261,8 @@ ruff-dirty:

.PHONY: ruff-clean
ruff-clean: ruff-dirty
@test -e $(MXENV_PATH)pip && $(MXENV_PATH)pip uninstall -y ruff || :
@test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y ruff || :
@rm -rf .ruff_cache

INSTALL_TARGETS+=$(RUFF_TARGET)
CHECK_TARGETS+=ruff-check
Expand All @@ -273,7 +277,7 @@ CLEAN_TARGETS+=ruff-clean
ISORT_TARGET:=$(SENTINEL_FOLDER)/isort.sentinel
$(ISORT_TARGET): $(MXENV_TARGET)
@echo "Install isort"
@$(MXENV_PATH)pip install isort
@$(MXENV_PYTHON) -m pip install isort
@touch $(ISORT_TARGET)

.PHONY: isort-check
Expand All @@ -292,7 +296,7 @@ isort-dirty:

.PHONY: isort-clean
isort-clean: isort-dirty
@test -e $(MXENV_PATH)pip && $(MXENV_PATH)pip uninstall -y isort || :
@test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y isort || :

INSTALL_TARGETS+=$(ISORT_TARGET)
CHECK_TARGETS+=isort-check
Expand All @@ -313,7 +317,7 @@ SPHINX_AUTOBUILD_BIN=$(MXENV_PATH)sphinx-autobuild
DOCS_TARGET:=$(SENTINEL_FOLDER)/sphinx.sentinel
$(DOCS_TARGET): $(MXENV_TARGET)
@echo "Install Sphinx"
@$(MXENV_PATH)pip install -U sphinx sphinx-autobuild $(DOCS_REQUIREMENTS)
@$(MXENV_PYTHON) -m pip install -U sphinx sphinx-autobuild $(DOCS_REQUIREMENTS)
@touch $(DOCS_TARGET)

.PHONY: docs
Expand All @@ -332,6 +336,8 @@ docs-dirty:

.PHONY: docs-clean
docs-clean: docs-dirty
@test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y \
sphinx sphinx-autobuild $(DOCS_REQUIREMENTS) || :
@rm -rf $(DOCS_TARGET_FOLDER)

INSTALL_TARGETS+=$(DOCS_TARGET)
Expand Down Expand Up @@ -407,8 +413,8 @@ INSTALLED_PACKAGES=$(MXMAKE_FILES)/installed.txt
PACKAGES_TARGET:=$(INSTALLED_PACKAGES)
$(PACKAGES_TARGET): $(FILES_TARGET) $(ADDITIONAL_SOURCES_TARGETS)
@echo "Install python packages"
@$(MXENV_PATH)pip install -r $(FILES_TARGET)
@$(MXENV_PATH)pip freeze > $(INSTALLED_PACKAGES)
@$(MXENV_PYTHON) -m pip install -r $(FILES_TARGET)
@$(MXENV_PYTHON) -m pip freeze > $(INSTALLED_PACKAGES)
@touch $(PACKAGES_TARGET)

.PHONY: packages
Expand All @@ -421,8 +427,8 @@ packages-dirty:
.PHONY: packages-clean
packages-clean:
@test -e $(FILES_TARGET) \
&& test -e $(MXENV_PATH)pip \
&& $(MXENV_PATH)pip uninstall -y -r $(FILES_TARGET) \
&& test -e $(MXENV_PYTHON) \
&& $(MXENV_PYTHON) -m pip uninstall -y -r $(FILES_TARGET) \
|| :
@rm -f $(PACKAGES_TARGET)

Expand All @@ -437,7 +443,7 @@ CLEAN_TARGETS+=packages-clean
TEST_TARGET:=$(SENTINEL_FOLDER)/test.sentinel
$(TEST_TARGET): $(MXENV_TARGET)
@echo "Install $(TEST_REQUIREMENTS)"
@$(MXENV_PATH)pip install $(TEST_REQUIREMENTS)
@$(MXENV_PYTHON) -m pip install $(TEST_REQUIREMENTS)
@touch $(TEST_TARGET)

.PHONY: test
Expand All @@ -452,7 +458,7 @@ test-dirty:

.PHONY: test-clean
test-clean: test-dirty
@test -e $(MXENV_PATH)pip && $(MXENV_PATH)pip uninstall -y $(TEST_REQUIREMENTS) || :
@test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y $(TEST_REQUIREMENTS) || :
@rm -rf .pytest_cache

INSTALL_TARGETS+=$(TEST_TARGET)
Expand All @@ -466,7 +472,7 @@ DIRTY_TARGETS+=test-dirty
COVERAGE_TARGET:=$(SENTINEL_FOLDER)/coverage.sentinel
$(COVERAGE_TARGET): $(TEST_TARGET)
@echo "Install Coverage"
@$(MXENV_PATH)pip install -U coverage
@$(MXENV_PYTHON) -m pip install -U coverage
@touch $(COVERAGE_TARGET)

.PHONY: coverage
Expand All @@ -481,7 +487,7 @@ coverage-dirty:

.PHONY: coverage-clean
coverage-clean: coverage-dirty
@test -e $(MXENV_PATH)pip && $(MXENV_PATH)pip uninstall -y coverage || :
@test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y coverage || :
@rm -rf .coverage htmlcov

INSTALL_TARGETS+=$(COVERAGE_TARGET)
Expand All @@ -495,7 +501,7 @@ CLEAN_TARGETS+=coverage-clean
MYPY_TARGET:=$(SENTINEL_FOLDER)/mypy.sentinel
$(MYPY_TARGET): $(MXENV_TARGET)
@echo "Install mypy"
@$(MXENV_PATH)pip install mypy $(MYPY_REQUIREMENTS)
@$(MXENV_PYTHON) -m pip install mypy $(MYPY_REQUIREMENTS)
@touch $(MYPY_TARGET)

.PHONY: mypy
Expand All @@ -509,7 +515,7 @@ mypy-dirty:

.PHONY: mypy-clean
mypy-clean: mypy-dirty
@test -e $(MXENV_PATH)pip && $(MXENV_PATH)pip uninstall -y mypy || :
@test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y mypy || :
@rm -rf .mypy_cache

INSTALL_TARGETS+=$(MYPY_TARGET)
Expand All @@ -524,7 +530,7 @@ DIRTY_TARGETS+=mypy-dirty
ZEST_RELEASER_TARGET:=$(SENTINEL_FOLDER)/zest-releaser.sentinel
$(ZEST_RELEASER_TARGET): $(MXENV_TARGET)
@echo "Install zest.releaser"
@$(MXENV_PATH)pip install zest.releaser
@$(MXENV_PYTHON) -m pip install zest.releaser
@touch $(ZEST_RELEASER_TARGET)

.PHONY: zest-releaser-prerelease
Expand Down Expand Up @@ -553,7 +559,7 @@ zest-releaser-dirty:

.PHONY: zest-releaser-clean
zest-releaser-clean: zest-releaser-dirty
@test -e $(MXENV_PATH)pip && $(MXENV_PATH)pip uninstall -y zest.releaser || :
@test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y zest.releaser || :

INSTALL_TARGETS+=$(ZEST_RELEASER_TARGET)
DIRTY_TARGETS+=zest-releaser-dirty
Expand Down
44 changes: 23 additions & 21 deletions src/mxmake/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ def test_Makefile(self, tempdir):
SENTINEL_FOLDER?=$(MXMAKE_FOLDER)/sentinels
SENTINEL?=$(SENTINEL_FOLDER)/about.txt
$(SENTINEL):
@mkdir -p $(SENTINEL_FOLDER)
@echo "Sentinels for the Makefile process." > $(SENTINEL)
@mkdir -p $(SENTINEL_FOLDER)
@echo "Sentinels for the Makefile process." > $(SENTINEL)
##############################################################################
# mxenv
Expand All @@ -665,39 +665,42 @@ def test_Makefile(self, tempdir):
# determine the executable path
ifeq ("$(VENV_ENABLED)", "true")
MXENV_PATH=$(VENV_FOLDER)/bin/
MXENV_PYTHON=$(MXENV_PATH)python
else
MXENV_PATH=
MXENV_PYTHON=$(PYTHON_BIN)
endif
MXENV_TARGET:=$(SENTINEL_FOLDER)/mxenv.sentinel
$(MXENV_TARGET): $(SENTINEL)
ifeq ("$(VENV_ENABLED)", "true")
ifeq ("$(VENV_CREATE)", "true")
@echo "Setup Python Virtual Environment under '$(VENV_FOLDER)'"
@$(PYTHON_BIN) -m venv $(VENV_FOLDER)
@echo "Setup Python Virtual Environment under '$(VENV_FOLDER)'"
@$(PYTHON_BIN) -m venv $(VENV_FOLDER)
endif
endif
@$(MXENV_PATH)pip install -U pip setuptools wheel
@$(MXENV_PATH)pip install -U $(MXDEV)
@$(MXENV_PATH)pip install -U $(MXMAKE)
@touch $(MXENV_TARGET)
@$(MXENV_PYTHON) -m ensurepip -U
@$(MXENV_PYTHON) -m pip install -U pip setuptools wheel
@$(MXENV_PYTHON) -m pip install -U $(MXDEV)
@$(MXENV_PYTHON) -m pip install -U $(MXMAKE)
@touch $(MXENV_TARGET)
.PHONY: mxenv
mxenv: $(MXENV_TARGET)
.PHONY: mxenv-dirty
mxenv-dirty:
@rm -f $(MXENV_TARGET)
@rm -f $(MXENV_TARGET)
.PHONY: mxenv-clean
mxenv-clean: mxenv-dirty
ifeq ("$(VENV_ENABLED)", "true")
ifeq ("$(VENV_CREATE)", "true")
@rm -rf $(VENV_FOLDER)
@rm -rf $(VENV_FOLDER)
endif
else
@$(MXENV_PATH)pip uninstall -y $(MXDEV)
@$(MXENV_PATH)pip uninstall -y $(MXMAKE)
@$(MXENV_PYTHON) -m pip uninstall -y $(MXDEV)
@$(MXENV_PYTHON) -m pip uninstall -y $(MXMAKE)
endif
INSTALL_TARGETS+=mxenv
Expand All @@ -712,11 +715,11 @@ def test_Makefile(self, tempdir):
INSTALL_TARGET:=$(SENTINEL_FOLDER)/install.sentinel
$(INSTALL_TARGET): $(INSTALL_TARGETS)
@touch $(INSTALL_TARGET)
@touch $(INSTALL_TARGET)
.PHONY: install
install: $(INSTALL_TARGET)
@touch $(INSTALL_TARGET)
@touch $(INSTALL_TARGET)
.PHONY: run
run: $(RUN_TARGET)
Expand All @@ -726,22 +729,21 @@ def test_Makefile(self, tempdir):
.PHONY: dirty
dirty: $(DIRTY_TARGETS)
@rm -f $(INSTALL_TARGET)
@rm -f $(INSTALL_TARGET)
.PHONY: clean
clean: dirty $(CLEAN_TARGETS)
@rm -rf $(CLEAN_TARGETS) $(MXMAKE_FOLDER) $(CLEAN_FS)
@rm -rf $(CLEAN_TARGETS) $(MXMAKE_FOLDER) $(CLEAN_FS)
.PHONY: purge
purge: clean $(PURGE_TARGETS)
.PHONY: runtime-clean
runtime-clean:
@echo "Remove runtime artifacts, like byte-code and caches."
@find . -name '*.py[c|o]' -delete
@find . -name '*~' -exec rm -f {} +
@find . -name '__pycache__' -exec rm -fr {} +
@echo "Remove runtime artifacts, like byte-code and caches."
@find . -name '*.py[c|o]' -delete
@find . -name '*~' -exec rm -f {} +
@find . -name '__pycache__' -exec rm -fr {} +
""",
f.read(),
)
Expand Down
4 changes: 2 additions & 2 deletions src/mxmake/topics/applications/cookiecutter.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
COOKIECUTTER_TARGET:=$(SENTINEL_FOLDER)/cookiecutter.sentinel
$(COOKIECUTTER_TARGET): $(MXENV_TARGET)
@echo "Install cookiecutter"
@$(MXENV_PATH)pip install "cookiecutter>=2.1.1"
@$(MXENV_PYTHON) -m pip install "cookiecutter>=2.1.1"
@touch $(COOKIECUTTER_TARGET)

.PHONY: cookiecutter-dirty
Expand All @@ -29,7 +29,7 @@ cookiecutter-dirty:

.PHONY: cookiecutter-clean
cookiecutter-clean: cookiecutter-dirty
@test -e $(MXENV_PATH)pip && $(MXENV_PATH)pip uninstall -y cookiecutter || :
@test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y cookiecutter || :
@rm -f $(COOKIECUTTER_TARGET)

DIRTY_TARGETS+=cookiecutter-dirty
Expand Down
4 changes: 2 additions & 2 deletions src/mxmake/topics/applications/twisted.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
TWISTED_TARGET:=$(SENTINEL_FOLDER)/twisted.sentinel
$(TWISTED_TARGET): $(MXENV_TARGET)
@echo "Install twisted"
@$(MXENV_PATH)pip install Twisted
@$(MXENV_PYTHON) -m pip install Twisted
@touch $(TWISTED_TARGET)

.PHONY: twisted-start
Expand All @@ -35,7 +35,7 @@ twisted-dirty:

.PHONY: twisted-clean
twisted-clean: twisted-dirty
@test -e $(MXENV_PATH)pip && $(MXENV_PATH)pip uninstall -y Twisted || :
@test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y Twisted || :

INSTALL_TARGETS+=$(TWISTED_TARGET)
CLEAN_TARGETS+=twisted-clean
Expand Down
4 changes: 2 additions & 2 deletions src/mxmake/topics/applications/zest-releaser.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
ZEST_RELEASER_TARGET:=$(SENTINEL_FOLDER)/zest-releaser.sentinel
$(ZEST_RELEASER_TARGET): $(MXENV_TARGET)
@echo "Install zest.releaser"
@$(MXENV_PATH)pip install zest.releaser
@$(MXENV_PYTHON) -m pip install zest.releaser
@touch $(ZEST_RELEASER_TARGET)

.PHONY: zest-releaser-prerelease
Expand Down Expand Up @@ -58,7 +58,7 @@ zest-releaser-dirty:

.PHONY: zest-releaser-clean
zest-releaser-clean: zest-releaser-dirty
@test -e $(MXENV_PATH)pip && $(MXENV_PATH)pip uninstall -y zest.releaser || :
@test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y zest.releaser || :

INSTALL_TARGETS+=$(ZEST_RELEASER_TARGET)
DIRTY_TARGETS+=zest-releaser-dirty
Expand Down
13 changes: 8 additions & 5 deletions src/mxmake/topics/core/mxenv.mk
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ endif
# determine the executable path
ifeq ("$(VENV_ENABLED)", "true")
MXENV_PATH=$(VENV_FOLDER)/bin/
MXENV_PYTHON=$(MXENV_PATH)python
else
MXENV_PATH=
MXENV_PYTHON=$(PYTHON_BIN)
endif

MXENV_TARGET:=$(SENTINEL_FOLDER)/mxenv.sentinel
Expand All @@ -91,9 +93,10 @@ ifeq ("$(VENV_CREATE)", "true")
@$(PYTHON_BIN) -m venv $(VENV_FOLDER)
endif
endif
@$(MXENV_PATH)pip install -U pip setuptools wheel
@$(MXENV_PATH)pip install -U $(MXDEV)
@$(MXENV_PATH)pip install -U $(MXMAKE)
@$(MXENV_PYTHON) -m ensurepip -U
@$(MXENV_PYTHON) -m pip install -U pip setuptools wheel
@$(MXENV_PYTHON) -m pip install -U $(MXDEV)
@$(MXENV_PYTHON) -m pip install -U $(MXMAKE)
@touch $(MXENV_TARGET)

.PHONY: mxenv
Expand All @@ -110,8 +113,8 @@ ifeq ("$(VENV_CREATE)", "true")
@rm -rf $(VENV_FOLDER)
endif
else
@$(MXENV_PATH)pip uninstall -y $(MXDEV)
@$(MXENV_PATH)pip uninstall -y $(MXMAKE)
@$(MXENV_PYTHON) -m pip uninstall -y $(MXDEV)
@$(MXENV_PYTHON) -m pip uninstall -y $(MXMAKE)
endif

INSTALL_TARGETS+=mxenv
Expand Down
Loading

0 comments on commit 511affd

Please sign in to comment.