diff --git a/.gitignore b/.gitignore index 610c2b7..c889d46 100644 --- a/.gitignore +++ b/.gitignore @@ -134,3 +134,6 @@ dmypy.json flycheck_*.py tmp.txt + +# Windows +NUL diff --git a/Makefile b/Makefile index e0c2e35..5031406 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,9 @@ GIT = git # least important first (can not stop easily in foreach) PYTHON_EXECUTABLES = python python3 MYPY = mypy -PIP = $(PYTHON) -m pip +# The -O flag is used to suppress error messages related to eggs. +# See also https://stackoverflow.com/questions/43177200/assertionerror-egg-link-does-not-match-installed-location-of-reviewboard-at. +PIP = $(PYTHON) -O -m pip # Otherwise perl may complain on a Mac LANG = C # This is GNU specific I guess @@ -18,55 +20,61 @@ TAG = v$(VERSION) # OS specific section ifeq '$(findstring ;,$(PATH))' ';' - detected_OS := Windows - HOME = $(USERPROFILE) - DEVNUL := NUL - WHICH := where +detected_OS := Windows +HOME = $(USERPROFILE) +DEVNUL := NUL +WHICH := where +GREP := find +EXE := .exe else - detected_OS := $(shell uname 2>/dev/null || echo Unknown) - detected_OS := $(patsubst CYGWIN%,Cygwin,$(detected_OS)) - detected_OS := $(patsubst MSYS%,MSYS,$(detected_OS)) - detected_OS := $(patsubst MINGW%,MSYS,$(detected_OS)) - DEVNUL := /dev/null - WHICH := which -endif - -$(foreach e,$(PYTHON_EXECUTABLES),$(if $(shell ${WHICH} ${e} 2>${DEVNUL}),$(eval PYTHON := ${e}),)) - -ifndef PYTHON - $(error Could not find any Python executable from ${PYTHON_EXECUTABLES}.) +detected_OS := $(shell uname 2>/dev/null || echo Unknown) +detected_OS := $(patsubst CYGWIN%,Cygwin,$(detected_OS)) +detected_OS := $(patsubst MSYS%,MSYS,$(detected_OS)) +detected_OS := $(patsubst MINGW%,MSYS,$(detected_OS)) +DEVNUL := /dev/null +WHICH := which +GREP := grep +EXE := endif ifdef CONDA_PREFIX - home = $(CONDA_PREFIX) +home = $(subst \,/,$(CONDA_PREFIX)) else - home = $(HOME) +home = $(HOME) endif -ifeq ($(detected_OS),Windows) - RM_EGGS = pushd $(home) && del /s/q $(PROJECT).egg-link $(PROJECT)-nspkg.pth +ifdef CONDA_PYTHON_EXE +# look no further +PYTHON := $(subst \,/,$(CONDA_PYTHON_EXE)) else - RM_EGGS = { cd $(home) && find . \( -name $(PROJECT).egg-link -o -name $(PROJECT)-nspkg.pth \) -print -exec rm -i "{}" \; ; } +# On Windows those executables may exist but not functional yet (can be used to install) so use Python -V +$(foreach e,$(PYTHON_EXECUTABLES),$(if $(shell ${e}${EXE} -V 3>${DEVNUL}),$(eval PYTHON := ${e}${EXE}),)) +endif + +ifndef PYTHON +$(error Could not find any Python executable from ${PYTHON_EXECUTABLES}.) endif .PHONY: clean install test dist distclean upload_test upload tag help: ## This help. @perl -ne 'printf(qq(%-30s %s\n), $$1, $$2) if (m/^((?:\w|[.%-])+):.*##\s*(.*)$$/)' $(MAKEFILE_LIST) +# @echo home: $(home) -clean: ## Cleanup the package and remove it from the Python installation path. +init: ## Fulfill the requirements + $(PIP) install -r requirements.txt -r src/requirements.txt + +clean: init ## Cleanup the package and remove it from the Python installation path. $(PYTHON) setup.py clean --all - -$(RM_EGGS) $(PYTHON) -Bc "import pathlib; [p.unlink() for p in pathlib.Path('.').rglob('*.py[co]')]" $(PYTHON) -Bc "import pathlib; [p.rmdir() for p in pathlib.Path('.').rglob('__pycache__')]" $(PYTHON) -Bc "import shutil; import os; [shutil.rmtree(d) for d in ['.pytest_cache', '.mypy_cache', 'dist', 'htmlcov', '.coverage'] if os.path.isdir(d)]" cd src && $(MAKE) clean -install: ## Install the package to the Python installation path. - $(PIP) install -r requirements.txt -r src/requirements.txt +install: init ## Install the package to the Python installation path. $(PIP) install -e . -test: ## Test the package. +test: init ## Test the package. $(PIP) install -r test_requirements.txt $(MYPY) --show-error-codes src $(PYTHON) -m pytest --exitfirst