Skip to content

Commit 42d7cc5

Browse files
ckadnerBluThaitanium
authored andcommitted
Add venv to Makefile
* Also add combine lint target Signed-off-by: Christian Kadner <ckadner@us.ibm.com> Signed-off-by: BluThaitanium <phuthai450@gmail.com>
1 parent f616a53 commit 42d7cc5

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

Makefile

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
1-
# Copyright 2021 The MLX Contributors
1+
# Copyright 2021-2022 The MLX Contributors
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

55
# Acknowledgements:
66
# - The help target was derived from https://stackoverflow.com/a/35730328/5601796
77

8+
VENV ?= .venv
9+
export VIRTUAL_ENV := $(abspath ${VENV})
10+
export PATH := ${VIRTUAL_ENV}/bin:${PATH}
11+
GITHUB_ACTION ?= false
12+
813
.PHONY: help
914
help: ## List the Make targets with description
1015
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
1116
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'
1217

18+
.PHONY: venv
19+
venv: $(VENV)/bin/activate ## Create and activate Python virtual environment
20+
$(VENV)/bin/activate: api/client/setup.py api/server/setup.py api/server/requirements.txt
21+
# create/update the VENV when there was a change to setup.py or requirements.txt
22+
# check if api server or client is already installed (Travis/CI did during install step)
23+
# use pip from the specified VENV as opposed to any pip available in the shell
24+
@echo "VENV=$(VENV)"
25+
@test -d $(VENV) || python3 -m venv $(VENV)
26+
@$(VENV)/bin/pip show mlx-api >/dev/null 2>&1 || $(VENV)/bin/pip install -e api/server && $(VENV)/bin/pip install -r api/server/requirements.txt
27+
@$(VENV)/bin/pip show mlx-client >/dev/null 2>&1 || $(VENV)/bin/pip install -e api/client && $(VENV)/bin/pip install -r api/client/requirements.txt
28+
@if [ "$(GITHUB_ACTION)" = "false" ]; then touch $(VENV)/bin/activate; fi
29+
30+
.PHONY: install
31+
install: venv ## Install Python packages in a virtual environment
32+
@echo "Run 'source $(VENV)/bin/activate' to activate the virtual environment."
33+
1334
.PHONY: check_npm_packages
1435
check_npm_packages: ## Verify NPM packages
1536
@python3 tools/python/verify_npm_packages.py --verify
@@ -39,15 +60,19 @@ check_license: ## Make sure source files have license header
3960

4061
.PHONY: lint_python
4162
lint_python: venv ## Check Python code style compliance
42-
@which flake8 > /dev/null || pip install flake8 || pip3 install flake8
43-
@flake8 . --show-source --statistics \
63+
@which flake8 > /dev/null || pip install flake8
64+
@flake8 api/server api/client tools/python --show-source --statistics \
4465
--select=E9,E2,E3,E5,F63,F7,F82,F4,F841,W291,W292 \
45-
--per-file-ignores ./*:F841 \
66+
--per-file-ignores api/server/swagger_server/controllers/*,api/server/swagger_server/models/*,api/client/swagger_client/models/*,api/client/test/*:E252,F401,W291 \
4667
--exclude .git,__pycache__,docs/source/conf.py,old,build,dist,venv \
4768
--max-line-length=140
4869
@echo "$@: OK"
4970

5071
.PHONY: lint_javascript
5172
lint_javascript: ## Check Javascript code style compliance
52-
@cd dashboard/origin-mlx && npm run lint -- --fix
73+
@cd dashboard/origin-mlx && npm run lint:fix
74+
@echo "$@: OK"
75+
76+
.PHONY: lint
77+
lint: lint_javascript lint_python ## Check for code style violations (JavaScript, Python)
5378
@echo "$@: OK"

0 commit comments

Comments
 (0)