Skip to content

Commit 7aed12e

Browse files
authored
Add Pre-Commit Hooks and Fix Dev Dependency Issues (#12)
* Add pre commit functionality to the repo, fix any errors popping up with current state of main and running the pre commit checks, fix install and versioning issues with dev dependencies * update DEVELOPING.md docs
1 parent f905346 commit 7aed12e

File tree

13 files changed

+67
-161
lines changed

13 files changed

+67
-161
lines changed

.github/workflows/ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ jobs:
2020
2121
- name: Run tox
2222
run: tox
23-

.pre-commit-config.yaml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- repo: https://github.com/astral-sh/ruff-pre-commit
8+
rev: v0.5.2
9+
hooks:
10+
- id: ruff
11+
- repo: https://github.com/psf/black-pre-commit-mirror
12+
rev: 24.4.2
13+
hooks:
14+
- id: black
15+
- repo: https://github.com/pycqa/isort
16+
rev: 5.13.2
17+
hooks:
18+
- id: isort
19+
- repo: https://github.com/pre-commit/mirrors-mypy
20+
rev: v1.10.1
21+
hooks:
22+
- id: mypy
23+
args: [--check-untyped-defs]
24+
additional_dependencies:
25+
[
26+
# main dependencies
27+
click,
28+
datasets,
29+
loguru,
30+
numpy,
31+
openai,
32+
requests,
33+
transformers,
34+
35+
# dev dependencies
36+
pytest,
37+
38+
# types
39+
types-click,
40+
types-requests,
41+
]

DEVELOPING.md

+3-135
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
<!--
2-
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing,
11-
software distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
-->
16-
171
# Developing GuideLLM
182

193
GuideLLM is developed and tested using Python 3.8-3.11.
@@ -33,16 +17,12 @@ python3 -m pip install -e "./[dev]"
3317

3418
This will clone the GuideLLM repo, install it, and install the development dependencies.
3519

36-
To develop framework specific features, you will also need the relevant framework packages.
37-
Those can be installed by adding the framework name to the install extras. Frameworks include
38-
`torch`, `keras`, and `tensorflow_v1`. For example:
20+
After this, install pre-commit hooks to ensure code quality and style checks are run before committing changes.
21+
3922
```bash
40-
python3 -m pip install -e "./[dev,torch]"
23+
pre-commit install
4124
```
4225

43-
Note: Running all pytorch tests using `make test TARGETS=torch`, also requires `torchvision`
44-
and `onnxruntime` install all these dependencies using `python3 -m pip install -e "./[dev, torch, torchvision, onnxruntime]"`
45-
4626
**Code Styling and Formatting checks**
4727

4828
```bash
@@ -52,115 +32,3 @@ make quality
5232

5333
This will run automatic code styling using `black` and `isort` and test that the
5434
repository's code matches its standards.
55-
56-
**EXAMPLE: test changes locally**
57-
58-
```bash
59-
make test TARGETS=<CSV of frameworks to run>
60-
```
61-
62-
This will run the targeted GuideLLM unit tests for the frameworks specified.
63-
The targets should be specified, because not all framework dependencies can be installed to run all tests.
64-
65-
To run just PyTorch tests, run
66-
```bash
67-
make test TARGETS=pytorch
68-
```
69-
70-
File any error found before changes as an Issue and fix any errors found after making changes before submitting a Pull Request.
71-
72-
## GitHub Workflow
73-
74-
1. Fork the `neuralmagic/guidellm` repository into your GitHub account: https://github.com/neuralmagic/guidellm/fork.
75-
76-
2. Clone your fork of the GitHub repository, replacing `<username>` with your GitHub username.
77-
78-
Use ssh (recommended):
79-
80-
```bash
81-
git clone [email protected]:<username>/guidellm.git
82-
```
83-
84-
Or https:
85-
86-
```bash
87-
git clone https://github.com/<username>/guidellm.git
88-
```
89-
90-
3. Add a remote to keep up with upstream changes.
91-
92-
```bash
93-
git remote add upstream https://github.com/neuralmagic/guidellm.git
94-
```
95-
96-
If you already have a copy, fetch upstream changes.
97-
98-
```bash
99-
git fetch upstream
100-
```
101-
102-
4. Create a feature branch to work in.
103-
104-
```bash
105-
git checkout -b feature-xxx remotes/upstream/main
106-
```
107-
108-
5. Work in your feature branch.
109-
110-
```bash
111-
git commit -a
112-
```
113-
114-
6. Periodically rebase your changes
115-
116-
```bash
117-
git pull --rebase
118-
```
119-
120-
7. When done, combine ("squash") related commits into a single one
121-
122-
```bash
123-
git rebase -i upstream/main
124-
```
125-
126-
This will open your editor and allow you to re-order commits and merge them:
127-
- Re-order the lines to change commit order (to the extent possible without creating conflicts)
128-
- Prefix commits using `s` (squash) or `f` (fixup) to merge extraneous commits.
129-
130-
8. Submit a pull-request
131-
132-
```bash
133-
git push origin feature-xxx
134-
```
135-
136-
Go to your fork main page
137-
138-
```bash
139-
https://github.com/<username>/guidellm
140-
```
141-
142-
If you recently pushed your changes GitHub will automatically pop up a `Compare & pull request` button for any branches you recently pushed to. If you click that button it will automatically offer you to submit your pull-request to the `neuralmagic/guidellm` repository.
143-
144-
- Give your pull-request a meaningful title.
145-
You'll know your title is properly formatted once the `Semantic Pull Request` GitHub check
146-
transitions from a status of "pending" to "passed".
147-
- In the description, explain your changes and the problem they are solving.
148-
149-
9. Addressing code review comments
150-
151-
Repeat steps 5. through 7. to address any code review comments and rebase your changes if necessary.
152-
153-
Push your updated changes to update the pull request
154-
155-
```bash
156-
git push origin [--force] feature-xxx
157-
```
158-
159-
`--force` may be necessary to overwrite your existing pull request in case your
160-
commit history was changed when performing the rebase.
161-
162-
Note: Be careful when using `--force` since you may lose data if you are not careful.
163-
164-
```bash
165-
git push origin --force feature-xxx
166-
```

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include LICENSE
1+
include LICENSE

docs/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
TODO

docs/conf.py

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
TODO

pyproject.toml

+13-13
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ dependencies = [
3636

3737
[project.optional-dependencies]
3838
dev = [
39-
"guidellm[code_quality]",
40-
"pre-commit",
41-
"sphinx",
42-
]
43-
code_quality = [
44-
"black",
45-
"isort",
46-
"mypy",
47-
"pytest",
48-
"pytest-mock",
49-
"ruff",
50-
"tox",
51-
"types-requests"
39+
# general
40+
"pre-commit~=3.5.0",
41+
"sphinx~=7.1.2",
42+
43+
# code quality
44+
"black~=24.4.2",
45+
"isort~=5.13.2",
46+
"mypy~=1.10.1",
47+
"pytest~=8.2.2",
48+
"pytest-mock~=3.14.0",
49+
"ruff~=0.5.2",
50+
"tox~=4.16.0",
51+
"types-requests~=2.32.0"
5252
]
5353

5454

src/guidellm/core/distribution.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Distribution:
1616
:type data: List[Union[int, float]], optional
1717
"""
1818

19-
def __init__(self, data: Optional[List[Union[int, float]]] = None):
19+
def __init__(self, data: Optional[Union[List[int], List[float]]] = None):
2020
"""
2121
Initialize the Distribution with optional data.
2222
@@ -227,7 +227,7 @@ def describe(self) -> dict:
227227
logger.debug(f"Generated description: {description}")
228228
return description
229229

230-
def add_data(self, new_data: List[Union[int, float]]):
230+
def add_data(self, new_data: Union[List[int], List[float]]):
231231
"""
232232
Add new data points to the distribution.
233233
@@ -237,7 +237,7 @@ def add_data(self, new_data: List[Union[int, float]]):
237237
self._data.extend(new_data)
238238
logger.debug(f"Added new data: {new_data}")
239239

240-
def remove_data(self, remove_data: List[Union[int, float]]):
240+
def remove_data(self, remove_data: Union[List[int], List[float]]):
241241
"""
242242
Remove specified data points from the distribution.
243243

tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ def inner_wrapper(*_, base_url: Optional[str] = None, **kwargs) -> OpenAIBackend
2828

2929
defaults.update(kwargs)
3030

31-
return Backend.create(**defaults)
31+
return Backend.create(**defaults) # type: ignore
3232

3333
return inner_wrapper

tests/dummy/data/openai.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def openai_completion_factory(
3737
}
3838
payload.update(kwargs)
3939

40-
yield Completion(**payload)
40+
yield Completion(**payload) # type: ignore
4141

4242

4343
def openai_model_factory(n: int = 3) -> Generator[Model, None, None]:

tests/unit/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def openai_models_list_patch(mocker) -> List[openai.types.Model]:
2525
Mock available models function to avoid OpenAI API call.
2626
"""
2727

28-
items: list[openai.types.Model] = [
28+
items: List[openai.types.Model] = [
2929
item for item in dummy.data.openai_model_factory()
3030
]
3131
mocker.patch(

tests/unit/request/test_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_request_generator_repr():
7474
@pytest.mark.regression
7575
def test_request_generator_iter_calls_create_item():
7676
generator = TestRequestGenerator(mode="sync")
77-
generator.create_item = Mock(
77+
generator.create_item = Mock( # type: ignore
7878
return_value=TextGenerationRequest(prompt="Mock prompt")
7979
)
8080

@@ -91,7 +91,7 @@ def test_request_generator_iter_calls_create_item():
9191
@pytest.mark.regression
9292
def test_request_generator_async_iter_calls_create_item():
9393
generator = TestRequestGenerator(mode="sync")
94-
generator.create_item = Mock(
94+
generator.create_item = Mock( # type: ignore
9595
return_value=TextGenerationRequest(prompt="Mock prompt")
9696
)
9797

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ env_list = py38,py39,py310,py311,py312
44

55
[testenv]
66
deps = .[code_quality]
7-
commands =
7+
commands =
88
python -m pytest tests/unit
99

1010
[testenv:lint]

0 commit comments

Comments
 (0)