Skip to content

Commit

Permalink
Windows specific
Browse files Browse the repository at this point in the history
  • Loading branch information
gpaulissen committed Oct 16, 2023
1 parent 547c0b2 commit e9d1b7d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,6 @@ dmypy.json
flycheck_*.py

tmp.txt

# Windows
NUL
62 changes: 35 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e9d1b7d

Please sign in to comment.