@@ -30,14 +30,17 @@ ifeq "$(ERROR_LOG_PATH)" ""
3030endif 
3131
3232ifeq  "$(COMMAND ) " ""
33- 	COMMAND_CMD!=`command -v xcrun || command which which  || command -v  which || command -v command `
33+ 	COMMAND_CMD!=`command -v xcrun || command -v command  || command which  which || command -v which `
3434	ifeq "$(COMMAND_CMD)" "*xcrun"
35- 		COMMAND_ARGS=--find
35+ 		COMMAND_ARGS=  --find
3636	endif
3737	ifeq "$(COMMAND_CMD)" "*command"
38- 		COMMAND_ARGS=-pv
38+ 		COMMAND_ARGS=  -pv
3939	endif
40- 	COMMAND=$(COMMAND_CMD) $(COMMAND_ARGS)
40+ 	ifeq "$(COMMAND_CMD)" ""
41+ 		COMMAND_CMD="command"
42+ 	endif
43+ 	COMMAND := $(COMMAND_CMD)$(COMMAND_ARGS)
4144endif 
4245
4346ifeq  "$(MAKE ) " ""
6265endif 
6366
6467ifeq  "$(LINK ) " ""
65- 	LINK=ln -sf
68+ 	LINK=$(COMMAND)  ln -sf
6669endif 
6770
71+ #  Python command configuration
6872ifeq  "$(PYTHON ) " ""
73+ 	#  Try to find python3, fallback to python
6974	PY_CMD=$(COMMAND) python3
7075	ifneq "$(PY_CMD)" ""
76+ 		#  Only use -B arg with python3
7177		PY_ARGS=-B
7278	else
7379		PY_CMD=$(COMMAND) python
7480	endif
75- 	PYTHON=$(PY_CMD) $(PY_ARGS)
76- 	ifeq "$(COVERAGE)" ""
81+ 	#  Set PYTHON only if not already set
82+ 	PYTHON := $(PY_CMD) $(PY_ARGS)
83+ endif 
84+ 
85+ #  Coverage configuration
86+ ifeq  "$(COVERAGE ) " ""
87+ 	#  If PYTHON is set (either by us or externally), try module approach first
88+ 	ifneq "$(PYTHON)" ""
7789		COVERAGE=$(PYTHON) -m coverage
78- 		# COV_CORE_SOURCE = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/
79- 		COV_CORE_CONFIG = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/.coveragerc
80- 		COV_CORE_DATAFILE = .coverage
8190	endif
91+ 	#  If COVERAGE is still not set, fall back to direct command
8292	ifeq "$(COVERAGE)" ""
8393		COVERAGE!=$(COMMAND) coverage
8494	endif
85- else 
86- 	ifeq "$(COVERAGE)" ""
87- 		COVERAGE!=$(COMMAND) coverage
95+ 	#  Only set COV_CORE_* variables when COVERAGE is configured
96+ 	ifneq "$(COVERAGE)" ""
8897		# COV_CORE_SOURCE = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/
8998		COV_CORE_CONFIG = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/.coveragerc
9099		COV_CORE_DATAFILE = .coverage
91100	endif
92101endif 
93102
94- ifndef  CC_TOOL 
95- 	FETCH_CC_TOOL := tests/fetch-test-reporter
96- 	CC_TOOL := ./cc-test-reporter
97- 	CC_TOOL_ARGS := after-build --exit-code 0 -t coverage.py
98- 	DS_TOOL := ./bin/deepsource
99- 	DS_TOOL_ARGS := report --analyzer test-coverage --key python --value-file ./coverage.xml
100- endif 
101- 
102103ifndef  PIP_COMMON_FLAGS 
103104	#  Define common pip install flags
104105	PIP_COMMON_FLAGS := --use-pep517 --exists-action s --upgrade --upgrade-strategy eager
@@ -157,6 +158,26 @@ include $(FETCH_CC_INCLUDE_PATH)
157158
158159.PHONY : all clean test cleanup init help clean-docs must_be_root must_have_flake must_have_pytest uninstall cleanup-dev-backups
159160
161+ .env :
162+ 	$(QUIET )$(ECHO )  " Missing environment override." 
163+ 	$(QUIET )$(ECHO )  "   SHELL: '$( SHELL) " 
164+ 	$(QUIET )$(ECHO )  "   LOG: '$( LOG) " 
165+ 	$(QUIET )$(ECHO )  "   ERROR_LOG_PATH: '$( ERROR_LOG_PATH) " 
166+ 	$(QUIET )$(ECHO )  "   QUIET: '$( QUIET) " 
167+ 	$(QUIET )$(ECHO )  "   COMMAND: '$( COMMAND) " 
168+ 	$(QUIET )$(ECHO )  "   MAKE: '$( MAKE) " 
169+ 	$(QUIET )$(ECHO )  "   ECHO: '$( ECHO) " 
170+ 	$(QUIET )$(ECHO )  "   PYTHON: '$( PYTHON) " 
171+ 	$(QUIET )$(ECHO )  "   COVERAGE: '$( COVERAGE) " 
172+ 	$(QUIET )$(ECHO )  "   FETCH_CC_INCLUDE_PATH: '$( FETCH_CC_INCLUDE_PATH) " 
173+ 	$(QUIET )$(ECHO )  "   CC_TOOL: '$( CC_TOOL) " 
174+ 	$(QUIET )$(ECHO )  "   DS_TOOL: '$( DS_TOOL) " 
175+ 	$(QUIET )$(ECHO )  "   CC_TOOL_ARGS: '$( CC_TOOL_ARGS) " 
176+ 	$(QUIET )$(ECHO )  "   DS_TOOL_ARGS: '$( DS_TOOL_ARGS) " 
177+ 	$(QUIET )$(ECHO )  "   PIP_ENV_FLAGS: '$( PIP_ENV_FLAGS) " 
178+ 	$(QUIET )$(ECHO )  "   PIP_COMMON_FLAGS: '$( PIP_COMMON_FLAGS) " 
179+ 	$(QUIET )$(ECHO )  "   DO_FAIL: '$( DO_FAIL) " 
180+ 	$(QUIET )$(ECHO )  " " #  intentionally blank
160181
161182MANIFEST.in : init
162183	$(QUIET )$(ECHO )  " include requirements.txt" > " $@ " ; 
@@ -222,15 +243,15 @@ purge: legacy-purge
222243	$(QUIET )$(RMDIR )  ./test-reports/ 2> $(ERROR_LOG_PATH )  ||  : 
223244	$(QUIET )$(ECHO )  " $@ : Done." 
224245
225- test-reports :
246+ test-reports : .env 
226247	$(QUIET ) mkdir $(INST_OPTS )  ./test-reports 2> $(ERROR_LOG_PATH )  > $(ERROR_LOG_PATH )  ||  true  ; 
227248	$(QUIET )$(BSMARK )  ./test-reports 2> $(ERROR_LOG_PATH )  > $(ERROR_LOG_PATH )  ||  true  ; 
228249	$(QUIET )$(ECHO )  " $@ : Done." 
229250
230251test-reqs : cc-test-reporter test-reports init
231- 	$(QUIET )$(PYTHON )  -m pip install $(PIP_COMMON_FLAGS )  $(PIP_ENV_FLAGS )  -r tests/ requirements.txt 2> $(ERROR_LOG_PATH )  ||  true 
252+ 	$(QUIET )$(PYTHON )  -m pip install $(PIP_COMMON_FLAGS )  $(PIP_ENV_FLAGS )  -r tests- requirements.txt 2> $(ERROR_LOG_PATH )  ||  true 
232253
233- just-test : cleanup
254+ just-test : cleanup .env 
234255	$(QUIET )$(COVERAGE )  run -p --source=pythonrepo -m unittest discover --verbose --buffer -s ./tests -t $(dir  $(abspath  $(lastword  $(MAKEFILE_LIST ) ) ) )  ||  $(PYTHON )  -m unittest discover --verbose --buffer -s ./tests -t ./ ||  DO_FAIL=" exit 2" ; 
235256	$(QUIET )$(WAIT )  ; 
236257	$(QUIET )$(DO_FAIL )  ; 
0 commit comments