Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile Linter | Python & Javascript #353

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
54 changes: 53 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
# Copyright 2021 The MLX Contributors
# Copyright 2021-2022 The MLX Contributors
#
# SPDX-License-Identifier: Apache-2.0

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

VENV ?= .venv
export VIRTUAL_ENV := $(abspath ${VENV})
export PATH := ${VIRTUAL_ENV}/bin:${PATH}
GITHUB_ACTION ?= false

.PHONY: help
help: ## List the Make targets with description
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'

.PHONY: venv
venv: $(VENV)/bin/activate ## Create and activate Python virtual environment
$(VENV)/bin/activate: api/client/setup.py api/server/setup.py api/server/requirements.txt
# create/update the VENV when there was a change to setup.py or requirements.txt
# check if api server or client is already installed (Travis/CI did during install step)
# use pip from the specified VENV as opposed to any pip available in the shell
@echo "VENV=$(VENV)"
@test -d $(VENV) || python3 -m venv $(VENV)
@$(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
@$(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
@if [ "$(GITHUB_ACTION)" = "false" ]; then touch $(VENV)/bin/activate; fi

.PHONY: install
install: venv ## Install Python packages in a virtual environment
@echo "Run 'source $(VENV)/bin/activate' to activate the virtual environment."

.PHONY: check_npm_packages
check_npm_packages: ## Verify NPM packages
@python3 tools/python/verify_npm_packages.py --verify
Expand All @@ -36,3 +57,34 @@ check_license: ## Make sure source files have license header
@git grep -L "SPDX-License-Identifier: Apache-2.0" -- *.py *.yml *.yaml *.sh *.html *.js *.css *.ts *.tsx ':!*.bundle.js' | \
grep . && echo "Missing license headers in files above. Run './tools/bash/add_license_headers.sh'" && exit 1 || \
echo "$@: OK"

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

.PHONY: lint_javascript
lint_javascript: ## Check Javascript code style compliance
@cd dashboard/origin-mlx && npm run lint:fix
@echo "$@: OK"

.PHONY: lint
lint: lint_javascript lint_python ## Check for code style violations (JavaScript, Python)
@echo "$@: OK"

.PHONY: format_python
format_python:
@which autoflake > /dev/null || pip install autoflake
@which autopep8 > /dev/null || pip install autopep8
@autoflake api tools/python -i --recursive --remove-all-unused-imports \
--ignore-init-module-imports --remove-unused-variables
@autopep8 api/ tools/python/ -i --recursive -a -a -a --experimental \
--select=E9,E2,E3,E5,F63,F7,F82,F4,F841,W291 \
--exclude .git,__pycache__,docs/source/conf.py,old,build,dist,venv \
--max-line-length=140
@echo "$@: OK"
8 changes: 4 additions & 4 deletions api/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pip install "git+https://github.com/machine-learning-exchange/mlx.git@main#egg=m
Then import the package:

```python
import swagger_client
import swagger_client # noqa: F401
```


Expand All @@ -43,9 +43,9 @@ Please follow the [installation procedure](#installation--usage) and then run th
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ComponentServiceApi()
Expand Down
18 changes: 9 additions & 9 deletions api/client/docs/ApplicationSettingsApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Returns the application settings.
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ApplicationSettingsApi()
Expand Down Expand Up @@ -63,9 +63,9 @@ Modify one or more of the application settings.
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ApplicationSettingsApi()
Expand Down Expand Up @@ -110,9 +110,9 @@ Set and store the application settings.
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ApplicationSettingsApi()
Expand Down
18 changes: 9 additions & 9 deletions api/client/docs/CatalogServiceApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Method | HTTP request | Description
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.CatalogServiceApi()
Expand Down Expand Up @@ -69,9 +69,9 @@ No authorization required
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.CatalogServiceApi()
Expand Down Expand Up @@ -116,9 +116,9 @@ No authorization required
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.CatalogServiceApi()
Expand Down
78 changes: 39 additions & 39 deletions api/client/docs/ComponentServiceApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Method | HTTP request | Description
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ComponentServiceApi()
Expand Down Expand Up @@ -72,9 +72,9 @@ No authorization required
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ComponentServiceApi()
Expand Down Expand Up @@ -116,9 +116,9 @@ No authorization required
### Example
```python
from __future__ import print_function
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ComponentServiceApi()
Expand Down Expand Up @@ -159,9 +159,9 @@ Returns the component artifacts compressed into a .tgz (.tar.gz) file.
### Example
```python
from __future__ import print_function
import swagger_client
from swagger_client.rest import ApiException
from urllib3.response import HTTPResponse
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from urllib3.response import HTTPResponse # noqa: F401


# create an instance of the API class
Expand Down Expand Up @@ -214,9 +214,9 @@ Generate sample code to use component in a pipeline
### Example
```python
from __future__ import print_function
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ComponentServiceApi()
Expand Down Expand Up @@ -258,9 +258,9 @@ No authorization required
### Example
```python
from __future__ import print_function
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ComponentServiceApi()
Expand Down Expand Up @@ -302,9 +302,9 @@ No authorization required
### Example
```python
from __future__ import print_function
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ComponentServiceApi()
Expand Down Expand Up @@ -346,9 +346,9 @@ No authorization required
### Example
```python
from __future__ import print_function
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ComponentServiceApi()
Expand Down Expand Up @@ -396,9 +396,9 @@ No authorization required
### Example
```python
from __future__ import print_function
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ComponentServiceApi()
Expand Down Expand Up @@ -444,9 +444,9 @@ No authorization required
### Example
```python
from __future__ import print_function
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ComponentServiceApi()
Expand Down Expand Up @@ -487,9 +487,9 @@ No authorization required
### Example
```python
from __future__ import print_function
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ComponentServiceApi()
Expand Down Expand Up @@ -533,9 +533,9 @@ No authorization required
### Example
```python
from __future__ import print_function
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ComponentServiceApi()
Expand Down Expand Up @@ -579,9 +579,9 @@ No authorization required
### Example
```python
from __future__ import print_function
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.ComponentServiceApi()
Expand Down
24 changes: 12 additions & 12 deletions api/client/docs/CredentialServiceApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Creates a credential associated with a pipeline.
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.CredentialServiceApi()
Expand Down Expand Up @@ -66,9 +66,9 @@ No authorization required
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.CredentialServiceApi()
Expand Down Expand Up @@ -110,9 +110,9 @@ No authorization required
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.CredentialServiceApi()
Expand Down Expand Up @@ -155,9 +155,9 @@ No authorization required
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
import swagger_client # noqa: F401
from swagger_client.rest import ApiException # noqa: F401
from pprint import pprint # noqa: F401

# create an instance of the API class
api_instance = swagger_client.CredentialServiceApi()
Expand Down
Loading