Last active
June 2, 2024 01:15
-
-
Save dotysan/b38e8b5760218d2c99d88f49cf37291a to your computer and use it in GitHub Desktop.
Install Node.js in a Python virtual environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SHELL:= /usr/bin/env bash | |
PY:= python3.12 | |
NOW:= $(shell date -Is) | |
venv:= .venv | |
# TODO: prevent empty $(venv)!! or leading / from causing havoc in really-clean! | |
vb:= $(venv)/bin/ | |
vN:= $(venv).$(NOW) | |
define vrun | |
@source $(vb)activate && $(1) | |
endef | |
.PHONY: clean really-clean | |
$(vb)npm: $(vb)nodeenv | |
$(call vrun, \ | |
nodeenv --python-virtualenv --node=lts && \ | |
touch --reference $(vb)activate.csh $(vb)activate && \ | |
npm install --global npm && npm --global list && \ | |
echo "Installed Node.js $$(node --version)" && \ | |
ls -o --human-readable --color=always $(vb)) | |
# Note that nodeenv --python-virtualenv above modifies activate, | |
# so we must reset the mtime to prevent successive runs of make | |
# from re-installing everything below. | |
$(vb)nodeenv: $(vb)wheel | |
$(call vrun, pip install nodeenv && pip list) | |
$(vb)wheel: $(vb)activate | |
$(call vrun, pip install --upgrade pip wheel) | |
$(vb)activate: | |
$(PY) -m venv $(venv) | |
clean: | |
@test -d $(venv) && \ | |
mv --verbose $(venv) $(vN) && \ | |
if hash pzstd 2>/dev/null; then ZC=pzstd; ZE=zst; \ | |
elif hash pixz 2>/dev/null; then ZC=pixz; ZE=xz; \ | |
elif hash pbzip2 2>/dev/null; then ZC=pbzip2; ZE=bz2; \ | |
elif hash pigz 2>/dev/null; then ZC=pigz; ZE=gz; \ | |
elif hash xz 2>/dev/null; then ZC=xz; ZE=xz; \ | |
elif hash bzip2 2>/dev/null; then ZC=bzip2; ZE=bz2; \ | |
elif hash gzip 2>/dev/null; then ZC=gzip; ZE=gz; \ | |
else echo 'No suitable compression program found.'; exit 1; fi >&2 && \ | |
tar --use-compress-program=$$ZC --create --file=./$(vN).tar.$$ZE $(vN) && \ | |
ls -oh $(vN).tar.$$ZE && \ | |
rm --force --recursive $(vN) || \ | |
echo 'No $(venv) venv to clean.' | |
really-clean: | |
@rm --force --recursive --verbose $(venv)* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Type
make
to build the environment. Typemake clean
to remove it.And finally
source .venv/bin/activate
to use it.