1+ # Makefile for PyMemoryEditor Python package
2+
3+ # Variables
4+ PACKAGE_NAME = PyMemoryEditor
5+ PYTHON = python3
6+ PIP = pip3
7+ BUILD_DIR = build
8+ DIST_DIR = dist
9+ EGG_INFO = $(PACKAGE_NAME ) .egg-info
10+ VENV_DIR = venv
11+ TEST_DIR = tests
12+
13+ # Colors for output
14+ GREEN = \033[0;32m
15+ YELLOW = \033[0;33m
16+ RED = \033[0;31m
17+ BLUE = \033[0;34m
18+ NC = \033[0m # No Color
19+
20+ # Default target
21+ .PHONY : help
22+ help :
23+ @echo " $( GREEN) PyMemoryEditor Python package Makefile$( NC) "
24+ @echo " "
25+ @echo " Available targets:"
26+ @echo " $( YELLOW) install$( NC) - Install package in development mode"
27+ @echo " $( YELLOW) install-deps$( NC) - Install dependencies"
28+ @echo " $( YELLOW) install-dev$( NC) - Install development dependencies"
29+ @echo " $( YELLOW) test$( NC) - Run tests"
30+ @echo " $( YELLOW) test-verbose$( NC) - Run tests with verbose output"
31+ @echo " $( YELLOW) test-coverage$( NC) - Run tests with coverage report"
32+ @echo " $( YELLOW) lint$( NC) - Run linter (flake8)"
33+ @echo " $( YELLOW) lint-fix$( NC) - Run auto-formatter (black)"
34+ @echo " $( YELLOW) type-check$( NC) - Run type checker (mypy)"
35+ @echo " $( YELLOW) clean$( NC) - Clean build artifacts"
36+ @echo " $( YELLOW) build$( NC) - Build package"
37+ @echo " $( YELLOW) build-wheel$( NC) - Build wheel package"
38+ @echo " $( YELLOW) build-sdist$( NC) - Build source distribution"
39+ @echo " $( YELLOW) validate$( NC) - Validate package"
40+ @echo " $( YELLOW) publish$( NC) - Publish to PyPI"
41+ @echo " $( YELLOW) publish-test$( NC) - Publish to Test PyPI"
42+ @echo " $( YELLOW) version$( NC) - Show current version"
43+ @echo " $( YELLOW) check-deps$( NC) - Check for outdated dependencies"
44+ @echo " $( YELLOW) update-deps$( NC) - Update dependencies"
45+ @echo " $( YELLOW) security$( NC) - Run security audit"
46+ @echo " $( YELLOW) docs$( NC) - Generate documentation"
47+ @echo " $( YELLOW) venv$( NC) - Create virtual environment"
48+ @echo " $( YELLOW) venv-activate$( NC) - Show command to activate venv"
49+ @echo " $( YELLOW) all$( NC) - Run full pipeline (install, lint, test, build)"
50+
51+ # Create virtual environment
52+ .PHONY : venv
53+ venv :
54+ @echo " $( GREEN) Creating virtual environment...$( NC) "
55+ $(PYTHON ) -m venv $(VENV_DIR )
56+ @echo " $( GREEN) Virtual environment created in $( VENV_DIR) $( NC) "
57+ @echo " $( YELLOW) To activate: source $( VENV_DIR) /bin/activate$( NC) "
58+
59+ # Show activation command
60+ .PHONY : venv-activate
61+ venv-activate :
62+ @echo " $( YELLOW) To activate virtual environment run:$( NC) "
63+ @echo " source $( VENV_DIR) /bin/activate"
64+
65+ # Install dependencies
66+ .PHONY : install-deps
67+ install-deps :
68+ @echo " $( GREEN) Installing dependencies...$( NC) "
69+ $(PIP ) install -r requirements.txt
70+ @echo " $( GREEN) Dependencies installed successfully!$( NC) "
71+
72+ # Install development dependencies
73+ .PHONY : install-dev
74+ install-dev :
75+ @echo " $( GREEN) Installing development dependencies...$( NC) "
76+ $(PIP ) install -r requirements.txt
77+ $(PIP ) install pytest pytest-cov flake8 black mypy twine build hatch
78+ @echo " $( GREEN) Development dependencies installed successfully!$( NC) "
79+
80+ # Install package in development mode
81+ .PHONY : install
82+ install : install-deps
83+ @echo " $( GREEN) Installing package in development mode...$( NC) "
84+ $(PIP ) install -e .
85+ @echo " $( GREEN) Package installed successfully!$( NC) "
86+
87+ # Run tests
88+ .PHONY : test
89+ test :
90+ @echo " $( GREEN) Running tests...$( NC) "
91+ $(PYTHON ) -m pytest $(TEST_DIR ) -v
92+ @echo " $( GREEN) Tests completed!$( NC) "
93+
94+ # Run tests with verbose output
95+ .PHONY : test-verbose
96+ test-verbose :
97+ @echo " $( GREEN) Running tests with verbose output...$( NC) "
98+ $(PYTHON ) -m pytest $(TEST_DIR ) -v -s
99+ @echo " $( GREEN) Verbose tests completed!$( NC) "
100+
101+ # Run tests with coverage
102+ .PHONY : test-coverage
103+ test-coverage :
104+ @echo " $( GREEN) Running tests with coverage...$( NC) "
105+ $(PYTHON ) -m pytest $(TEST_DIR ) --cov=$(PACKAGE_NAME ) --cov-report=html --cov-report=term
106+ @echo " $( GREEN) Coverage report generated!$( NC) "
107+ @echo " $( YELLOW) HTML report available at htmlcov/index.html$( NC) "
108+
109+ # Run linter
110+ .PHONY : lint
111+ lint :
112+ @echo " $( GREEN) Running linter (flake8)...$( NC) "
113+ $(PYTHON ) -m flake8 $(PACKAGE_NAME ) $(TEST_DIR )
114+ @echo " $( GREEN) Linting completed!$( NC) "
115+
116+ # Run auto-formatter
117+ .PHONY : lint-fix
118+ lint-fix :
119+ @echo " $( GREEN) Running auto-formatter (black)...$( NC) "
120+ $(PYTHON ) -m black $(PACKAGE_NAME ) $(TEST_DIR )
121+ @echo " $( GREEN) Code formatting completed!$( NC) "
122+
123+ # Run type checker
124+ .PHONY : type-check
125+ type-check :
126+ @echo " $( GREEN) Running type checker (mypy)...$( NC) "
127+ $(PYTHON ) -m mypy $(PACKAGE_NAME ) --ignore-missing-imports
128+ @echo " $( GREEN) Type checking completed!$( NC) "
129+
130+ # Clean build artifacts
131+ .PHONY : clean
132+ clean :
133+ @echo " $( GREEN) Cleaning build artifacts...$( NC) "
134+ rm -rf $(BUILD_DIR )
135+ rm -rf $(DIST_DIR )
136+ rm -rf $(EGG_INFO )
137+ rm -rf .pytest_cache
138+ rm -rf htmlcov
139+ rm -rf .coverage
140+ rm -rf .mypy_cache
141+ find . -type d -name " __pycache__" -exec rm -rf {} +
142+ find . -type f -name " *.pyc" -delete
143+ find . -type f -name " *.pyo" -delete
144+ find . -type f -name " *.pyd" -delete
145+ find . -type f -name " .coverage" -delete
146+ @echo " $( GREEN) Cleanup completed!$( NC) "
147+
148+ # Build package
149+ .PHONY : build
150+ build : clean
151+ @echo " $( GREEN) Building package...$( NC) "
152+ $(PYTHON ) -m build
153+ @echo " $( GREEN) Package built successfully!$( NC) "
154+
155+ # Build wheel package only
156+ .PHONY : build-wheel
157+ build-wheel : clean
158+ @echo " $( GREEN) Building wheel package...$( NC) "
159+ $(PYTHON ) -m build --wheel
160+ @echo " $( GREEN) Wheel package built successfully!$( NC) "
161+
162+ # Build source distribution only
163+ .PHONY : build-sdist
164+ build-sdist : clean
165+ @echo " $( GREEN) Building source distribution...$( NC) "
166+ $(PYTHON ) -m build --sdist
167+ @echo " $( GREEN) Source distribution built successfully!$( NC) "
168+
169+ # Validate package
170+ .PHONY : validate
171+ validate : build
172+ @echo " $( GREEN) Validating package...$( NC) "
173+ $(PYTHON ) -m twine check $(DIST_DIR ) /*
174+ @echo " $( GREEN) Package validation completed!$( NC) "
175+
176+ # Publish to PyPI
177+ .PHONY : publish
178+ publish : validate
179+ @echo " $( YELLOW) Are you sure you want to publish to PyPI? [y/N]$( NC) " && read ans && [ $$ {ans:-N} = y ]
180+ @echo " $( GREEN) Publishing to PyPI...$( NC) "
181+ $(PYTHON ) -m twine upload $(DIST_DIR ) /*
182+ @echo " $( GREEN) Package published successfully to PyPI!$( NC) "
183+
184+ # Publish to Test PyPI
185+ .PHONY : publish-test
186+ publish-test : validate
187+ @echo " $( GREEN) Publishing to Test PyPI...$( NC) "
188+ $(PYTHON ) -m twine upload --repository testpypi $(DIST_DIR ) /*
189+ @echo " $( GREEN) Package published successfully to Test PyPI!$( NC) "
190+
191+ # Show current version
192+ .PHONY : version
193+ version :
194+ @echo " $( GREEN) Current package version:$( NC) "
195+ @$(PYTHON ) -c " import $( PACKAGE_NAME) ; print($( PACKAGE_NAME) .__version__)"
196+
197+ # Check for outdated dependencies
198+ .PHONY : check-deps
199+ check-deps :
200+ @echo " $( GREEN) Checking for outdated dependencies...$( NC) "
201+ $(PIP ) list --outdated
202+
203+ # Update dependencies
204+ .PHONY : update-deps
205+ update-deps :
206+ @echo " $( GREEN) Updating dependencies...$( NC) "
207+ $(PIP ) install --upgrade -r requirements.txt
208+ @echo " $( GREEN) Dependencies updated!$( NC) "
209+
210+ # Security audit
211+ .PHONY : security
212+ security :
213+ @echo " $( GREEN) Running security audit...$( NC) "
214+ $(PIP ) install safety
215+ safety check
216+ @echo " $( GREEN) Security audit completed!$( NC) "
217+
218+ # Generate documentation
219+ .PHONY : docs
220+ docs :
221+ @echo " $( GREEN) Generating documentation...$( NC) "
222+ @if [ -d " docs" ]; then \
223+ cd docs && make html; \
224+ echo " $( GREEN) Documentation generated in docs/_build/html/$( NC) " ; \
225+ else \
226+ echo " $( YELLOW) No docs directory found. Skipping documentation generation.$( NC) " ; \
227+ fi
228+
229+ # Full development pipeline
230+ .PHONY : all
231+ all : install lint type-check test build validate
232+ @echo " $( GREEN) Full pipeline completed successfully!$( NC) "
233+
234+ # Development workflow targets
235+ .PHONY : dev-setup
236+ dev-setup : venv install-dev install
237+ @echo " $( GREEN) Development environment setup completed!$( NC) "
238+ @echo " $( YELLOW) Don't forget to activate the virtual environment:$( NC) "
239+ @echo " source $( VENV_DIR) /bin/activate"
240+
241+ .PHONY : pre-commit
242+ pre-commit : lint type-check test
243+ @echo " $( GREEN) Pre-commit checks passed!$( NC) "
244+
245+ .PHONY : pre-publish
246+ pre-publish : all security
247+ @echo " $( GREEN) Pre-publish checks completed!$( NC) "
248+
249+ # CI/CD targets
250+ .PHONY : ci
251+ ci : install-dev install lint type-check test build validate
252+ @echo " $( GREEN) CI pipeline completed!$( NC) "
253+
254+ # Show package info
255+ .PHONY : info
256+ info :
257+ @echo " $( GREEN) Package Information:$( NC) "
258+ @echo " Name: $( PACKAGE_NAME) "
259+ @$(PYTHON ) -c " import $( PACKAGE_NAME) ; print('Version:', $( PACKAGE_NAME) .__version__)" 2> /dev/null || echo " Version: Not installed"
260+ @echo " Python: $( shell $( PYTHON) --version) "
261+ @echo " Pip: $( shell $( PIP) --version) "
262+ @echo " "
263+ @echo " $( GREEN) Installed packages:$( NC) "
264+ @$(PIP ) list | grep -E " ($( PACKAGE_NAME) |pytest|flake8|black|mypy|twine|build)"
265+
266+ # Quick release workflow
267+ .PHONY : release
268+ release : pre-publish publish
269+ @echo " $( GREEN) Release completed!$( NC) "
270+
271+ .PHONY : release-test
272+ release-test : pre-publish publish-test
273+ @echo " $( GREEN) Test release completed!$( NC) "
274+
275+ # Install from PyPI (for testing)
276+ .PHONY : install-from-pypi
277+ install-from-pypi :
278+ @echo " $( GREEN) Installing from PyPI...$( NC) "
279+ $(PIP ) install $(PACKAGE_NAME )
280+ @echo " $( GREEN) Package installed from PyPI!$( NC) "
281+
282+ # Install from Test PyPI (for testing)
283+ .PHONY : install-from-test-pypi
284+ install-from-test-pypi :
285+ @echo " $( GREEN) Installing from Test PyPI...$( NC) "
286+ $(PIP ) install --index-url https://test.pypi.org/simple/ $(PACKAGE_NAME )
287+ @echo " $( GREEN) Package installed from Test PyPI!$( NC) "
288+
289+ # Uninstall package
290+ .PHONY : uninstall
291+ uninstall :
292+ @echo " $( GREEN) Uninstalling package...$( NC) "
293+ $(PIP ) uninstall $(PACKAGE_NAME ) -y
294+ @echo " $( GREEN) Package uninstalled!$( NC) "
0 commit comments