Skip to content

Commit 3946afa

Browse files
authored
Makefile (#125)
* first commit * changed unit_tests.yaml * generate-protos * better generate-protos logic * append -> prepend * more make targets
1 parent 45f8735 commit 3946afa

9 files changed

Lines changed: 83 additions & 27 deletions

File tree

.github/workflows/unit_tests.yaml

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,13 @@ jobs:
4242
with:
4343
python-version: ${{ matrix.python-version }}
4444
- name: Install Dependencies
45-
run: |
46-
pip install pytype
47-
pip install pylint
48-
pip install pyink
49-
pip install -r requirements.txt
50-
pip install -r benchmarks/requirements.in
45+
run: make install-deps
5146
- name: Typecheck the code with pytype
52-
run: |
53-
pytype --jobs auto --disable=import-error,module-attr jetstream/ benchmarks/
47+
run: make type-check
5448
- name: Analysing the code with pylint
55-
run: |
56-
pylint jetstream/ benchmarks/
49+
run: make linter-check
5750
- name: Format check with pyink
58-
run: |
59-
pyink --pyink-indentation 2 --line-length 80 --check --verbose .
51+
run: make format-check
6052

6153
cpu:
6254
name: "JetStream unit tests"
@@ -73,11 +65,8 @@ jobs:
7365
with:
7466
python-version: ${{ matrix.python-version }}
7567
- name: Install Dependencies
76-
run: |
77-
pip install -r requirements.txt
68+
run: make install-deps
7869
- name: Run all unit tests in JetStream (jetstream/tests)
79-
run: |
80-
coverage run -m unittest -v
70+
run: make unit-tests
8171
- name: Create test coverage report
82-
run: |
83-
coverage report -m --omit="jetstream/core/proto/*,jetstream/engine/tokenizer_pb2.py,jetstream/third_party/*" --fail-under=96
72+
run: make check-test-coverage

Makefile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
PYTHON := python
2+
PIP := $(PYTHON) -m pip
3+
GRPC_TOOLS_VERSION := 1.62.1
4+
5+
all: update-and-install-deps generate-protos format check
6+
7+
# Dependency management targets
8+
update-and-install-deps: update-deps install-deps
9+
10+
update-deps:
11+
$(PIP) install pip-tools
12+
$(PYTHON) -m piptools compile requirements.in
13+
14+
install-deps:
15+
$(PIP) install pytype pylint pyink -r requirements.txt -r benchmarks/requirements.in
16+
17+
# Code generation/formatting targets
18+
generate-protos: generate-and-prepend-preambles format
19+
20+
generate-and-prepend-preambles:
21+
$(PIP) install grpcio-tools==$(GRPC_TOOLS_VERSION)
22+
for id in $$(find . -name "*.proto"); do \
23+
$(PYTHON) -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. $$id && \
24+
PROTO_FILE=$$(echo $$id | awk '{print substr($$0, 1, length($$0)-6)}') && \
25+
PB_GRPC_PY=$(addsuffix "_pb2_grpc.py",$$PROTO_FILE) && \
26+
PB_PY=$(addsuffix "_pb2.py",$$PROTO_FILE) && \
27+
cat license_preamble.txt $$PB_GRPC_PY >> $(addsuffix "_temp",$$PB_GRPC_PY) && \
28+
mv $(addsuffix "_temp",$$PB_GRPC_PY) $$PB_GRPC_PY; \
29+
cat license_preamble.txt $$PB_PY >> $(addsuffix "_temp",$$PB_PY) && \
30+
mv $(addsuffix "_temp",$$PB_PY) $$PB_PY; \
31+
done
32+
33+
format:
34+
$(PIP) install pyink
35+
pyink --pyink-indentation 2 --line-length 80 --verbose .
36+
37+
# Code checking related targets
38+
check: type-check format-check linter-check
39+
40+
type-check:
41+
$(PIP) install pytype
42+
pytype --jobs auto --disable=import-error,module-attr jetstream/ benchmarks/
43+
44+
format-check:
45+
$(PIP) install pyink
46+
pyink --pyink-indentation 2 --line-length 80 --check --verbose .
47+
48+
linter-check:
49+
$(PIP) install pylint
50+
pylint --ignore-patterns=".*_pb2.py,.*_pb2_grpc.py" jetstream/ benchmarks/
51+
52+
53+
# Testing related targets
54+
tests: unit-tests check-test-coverage
55+
56+
unit-tests:
57+
coverage run -m unittest -v
58+
59+
check-test-coverage:
60+
coverage report -m --omit="jetstream/core/proto/*,jetstream/engine/tokenizer_pb2.py,jetstream/third_party/*" --fail-under=96

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Currently, there are two reference engine implementations available -- one for J
3939

4040
### Setup
4141
```
42-
pip install -r requirements.txt
42+
make update-and-install-deps
4343
```
4444

4545
### Run local server & Testing

jetstream/core/proto/jetstream.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// NOTICE: run `make generate-protos` if making changes to this file
16+
1517
syntax = "proto3";
1618

1719
package jetstream_proto;

jetstream/core/proto/jetstream_pb2.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
1514
# -*- coding: utf-8 -*-
1615
# Generated by the protocol buffer compiler. DO NOT EDIT!
1716
# source: jetstream/core/proto/jetstream.proto
1817
# Protobuf Python Version: 4.25.1
19-
# pylint: disable=all
2018
"""Generated protocol buffer code."""
2119
from google.protobuf import descriptor as _descriptor
2220
from google.protobuf import descriptor_pool as _descriptor_pool

jetstream/core/proto/jetstream_pb2_grpc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
1514
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
16-
# pylint: disable=all
1715
"""Client and server classes corresponding to protobuf-defined services."""
1816
import grpc
1917

jetstream/engine/tokenizer_pb2.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
1514
# -*- coding: utf-8 -*-
1615
# Generated by the protocol buffer compiler. DO NOT EDIT!
1716
# source: jetstream/engine/tokenizer.proto
1817
# Protobuf Python Version: 4.25.1
19-
# pylint: disable=all
2018
"""Generated protocol buffer code."""
2119
from google.protobuf import descriptor as _descriptor
2220
from google.protobuf import descriptor_pool as _descriptor_pool

jetstream/engine/tokenizer_pb2_grpc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
1514
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
16-
# pylint: disable=all
1715
"""Client and server classes corresponding to protobuf-defined services."""
1816
import grpc

license_preamble.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

0 commit comments

Comments
 (0)