Skip to content

Commit c5f17a2

Browse files
committed
improved implementation, added testing
1 parent c619926 commit c5f17a2

38 files changed

+3260
-629
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ add_executable(netgraph_core_tests
2222
tests/cpp/flow_graph_tests.cpp
2323
tests/cpp/max_flow_tests.cpp
2424
tests/cpp/k_shortest_paths_tests.cpp
25+
tests/cpp/negative_safety_tests.cpp
2526
)
2627
target_link_libraries(netgraph_core_tests PRIVATE netgraph_core GTest::gtest_main)
2728
target_include_directories(netgraph_core_tests PRIVATE tests/cpp)

Makefile

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NetGraph-Core Development Makefile
22

3-
.PHONY: help venv clean-venv dev install check check-ci lint format test qt clean build info hooks cov cpp-test rebuild
3+
.PHONY: help venv clean-venv dev install check check-ci lint format test qt clean build info hooks cov cpp-test rebuild check-python
44

55
.DEFAULT_GOAL := help
66

@@ -21,21 +21,22 @@ DEFAULT_MACOSX := 15.0
2121

2222
help:
2323
@echo "🔧 NetGraph-Core Development Commands"
24-
@echo " make venv - Create a local virtualenv (./venv)"
25-
@echo " make dev - Install dev deps and pre-commit"
26-
@echo " make install - Editable install (no dev deps)"
27-
@echo " make check - Pre-commit (auto-fix) + C++/Python tests, then lint"
28-
@echo " make check-ci - Non-mutating lint + tests (CI entrypoint)"
29-
@echo " make lint - Ruff + Pyright"
30-
@echo " make format - Ruff format"
31-
@echo " make test - Run pytest"
32-
@echo " make qt - Quick tests (exclude slow/benchmark if marked)"
33-
@echo " make cov - Coverage summary + XML + single-page combined HTML"
34-
@echo " make build - Build wheel"
35-
@echo " make clean - Clean build artifacts"
36-
@echo " make hooks - Run pre-commit on all files"
37-
@echo " make info - Show tool versions"
38-
@echo " make rebuild - Clean and rebuild using Apple Clang (respects CMAKE_ARGS)"
24+
@echo " make venv - Create a local virtualenv (./venv)"
25+
@echo " make dev - Install dev deps and pre-commit"
26+
@echo " make install - Editable install (no dev deps)"
27+
@echo " make check - Pre-commit (auto-fix) + C++/Python tests, then lint"
28+
@echo " make check-ci - Non-mutating lint + tests (CI entrypoint)"
29+
@echo " make lint - Ruff + Pyright"
30+
@echo " make format - Ruff format"
31+
@echo " make test - Run pytest"
32+
@echo " make qt - Quick tests (exclude slow/benchmark if marked)"
33+
@echo " make cov - Coverage summary + XML + single-page combined HTML"
34+
@echo " make build - Build wheel"
35+
@echo " make clean - Clean build artifacts"
36+
@echo " make hooks - Run pre-commit on all files"
37+
@echo " make info - Show tool versions"
38+
@echo " make check-python - Check if venv Python matches system Python"
39+
@echo " make rebuild - Clean and rebuild with system Python (respects CMAKE_ARGS)"
3940

4041
# Allow callers to pass CMAKE_ARGS and MACOSX_DEPLOYMENT_TARGET consistently
4142
ENV_MACOS := $(if $(MACOSX_DEPLOYMENT_TARGET),MACOSX_DEPLOYMENT_TARGET=$(MACOSX_DEPLOYMENT_TARGET),MACOSX_DEPLOYMENT_TARGET=$(DEFAULT_MACOSX))
@@ -47,7 +48,7 @@ DEV_ENV := $(ENV_MACOS) $(ENV_CC) $(ENV_CXX) $(ENV_CMAKE)
4748
dev:
4849
@echo "🚀 Setting up development environment..."
4950
@if [ ! -x "$(VENV_BIN)/python" ]; then \
50-
echo "🐍 Creating virtual environment in ./venv ..."; \
51+
echo "🐍 Creating virtual environment with $(PY_FIND) ..."; \
5152
$(PY_FIND) -m venv venv; \
5253
$(VENV_BIN)/python -m pip install -U pip wheel; \
5354
fi
@@ -56,6 +57,7 @@ dev:
5657
@echo "🔗 Installing pre-commit hooks..."
5758
@$(VENV_BIN)/python -m pre_commit install --install-hooks
5859
@echo "✅ Dev environment ready. Activate with: source venv/bin/activate"
60+
@$(MAKE) check-python
5961

6062
venv:
6163
@echo "🐍 Creating virtual environment in ./venv ..."
@@ -104,13 +106,25 @@ clean:
104106
@rm -rf Testing CTestTestfile.cmake
105107

106108
info:
107-
@echo "Python: $$($(PYTHON) --version)"
109+
@echo "Python (active): $$($(PYTHON) --version)"
110+
@echo "Python (system): $$($(PY_FIND) --version 2>/dev/null || echo 'missing')"
111+
@$(MAKE) check-python
108112
@echo "Ruff: $$($(RUFF) --version 2>/dev/null || echo 'missing')"
109113
@echo "Pyright: $$($(PYTHON) -m pyright --version 2>/dev/null | head -1 || echo 'missing')"
110114
@echo "Pytest: $$($(PYTEST) --version 2>/dev/null || echo 'missing')"
111115
@echo "CMake: $$(cmake --version 2>/dev/null | head -1 || echo 'missing')"
112116
@echo "Ninja: $$(ninja --version 2>/dev/null || echo 'missing')"
113117

118+
check-python:
119+
@if [ -x "$(VENV_BIN)/python" ]; then \
120+
VENV_VER=$$($(VENV_BIN)/python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>/dev/null || echo "unknown"); \
121+
SYS_VER=$$($(PY_FIND) -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>/dev/null || echo "unknown"); \
122+
if [ -n "$$VENV_VER" ] && [ -n "$$SYS_VER" ] && [ "$$VENV_VER" != "$$SYS_VER" ]; then \
123+
echo "⚠️ WARNING: venv Python ($$VENV_VER) != system Python ($$SYS_VER)"; \
124+
echo " Run 'make clean-venv && make dev' to recreate venv with system Python"; \
125+
fi; \
126+
fi
127+
114128
hooks:
115129
@$(PRECOMMIT) run --all-files || (echo "Some pre-commit hooks failed. Fix and re-run." && exit 1)
116130

@@ -172,5 +186,7 @@ sanitize-test:
172186
ASAN_OPTIONS=detect_leaks=1 ctest --test-dir "$$BUILD_DIR" --output-on-failure || true
173187

174188
# Clean + reinstall in dev mode (respects CMAKE_ARGS and MACOSX_DEPLOYMENT_TARGET)
189+
# Always uses system Python to avoid venv version mismatches
175190
rebuild: clean
176-
@$(DEV_ENV) $(PIP) install -e .'[dev]'
191+
@echo "🔨 Rebuilding with system Python: $(PY_FIND)"
192+
@$(DEV_ENV) $(PY_FIND) -m pip install -e .'[dev]'

0 commit comments

Comments
 (0)