Skip to content

Commit d4639f9

Browse files
authored
Setup update (#124)
* style(makefile): 🎨 create dynamically generated help target and move phony to top of each target This aids in clear target expectations and keeping track of missing descriptions as Clear target was missing from help. * style(lint): 🧱 configure black and isort in pyproject.toml This allows running black/isort in pre-commit or locally to use the same settings and user have the same experience. * style(markdown): 🚨 add alt text to resolve updated markdownlint img rule * style(black): 🚨 black format via version 24.2.0
1 parent b90ae1a commit d4639f9

33 files changed

+93
-49
lines changed

.pre-commit-config.yaml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.4.0
3+
rev: v4.6.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
88
- id: end-of-file-fixer
99
types: [ python ]
10-
- id: requirements-txt-fixer
1110

12-
- repo: https://github.com/psf/black
13-
rev: 23.7.0
11+
- repo: local
1412
hooks:
1513
- id: black
16-
args: [ --line-length=100, --exclude="" ]
17-
18-
# this is not technically always safe but usually is
19-
# use comments `# isort: off` and `# isort: on` to disable/re-enable isort
20-
- repo: https://github.com/pycqa/isort
21-
rev: 5.12.0
22-
hooks:
14+
name: black
15+
entry: black
16+
language: system
17+
pass_filenames: true
18+
types: [ python ]
19+
# this is not technically always safe but usually is
20+
# use comments `# isort: off` and `# isort: on` to disable/re-enable isort
2321
- id: isort
24-
args: [ --line-length=100, --profile=black ]
22+
name: isort
23+
entry: isort
24+
language: system
25+
pass_filenames: true
26+
types: [ python ]
2527

2628
# this is slightly dangerous because python imports have side effects
2729
# and this tool removes unused imports, which may be providing
2830
# necessary side effects for the code to run
2931
- repo: https://github.com/PyCQA/autoflake
30-
rev: v2.2.0
32+
rev: v2.3.1
3133
hooks:
3234
- id: autoflake
3335
args:
@@ -39,11 +41,11 @@ repos:
3941
exclude: "llm_guard/__init__.py"
4042

4143
- repo: https://github.com/zricethezav/gitleaks
42-
rev: v8.17.0
44+
rev: v8.18.2
4345
hooks:
4446
- id: gitleaks
4547

4648
- repo: https://github.com/igorshubovych/markdownlint-cli
47-
rev: v0.35.0
49+
rev: v0.39.0
4850
hooks:
4951
- id: markdownlint

Makefile

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,51 @@
1-
.PHONY: help lint test build docs-serve install-dev publish clean
1+
.DEFAULT_GOAL := help
22

3-
help:
4-
@echo "Available commands:"
5-
@echo "make lint - Check code with linters using pre-commit."
6-
@echo "make test - Run unit tests using pytest."
7-
@echo "make build - Build the package for PyPI."
8-
@echo "make docs-serve - Serve documentation using mkdocs."
9-
@echo "make install-dev - Install development dependencies."
10-
@echo "make publish - Publish to PyPI."
11-
12-
install-dev:
3+
.PHONY: install-dev
4+
install-dev: ## Install development dependencies.
135
@echo "Installing development dependencies..."
146
@python -m pip install ".[dev]"
15-
@python -m pre-commit install
7+
@pre-commit install
168

17-
lint:
9+
.PHONY: lint
10+
lint: ## Check code with linters using pre-commit.
1811
@echo "Running linters..."
1912
@pre-commit run --all-files
2013

21-
test:
14+
.PHONY: test
15+
test: ## Run unit tests using pytest.
2216
@echo "Running tests..."
2317
@pytest --exitfirst --verbose --failed-first --cov=.
2418

25-
build:
19+
.PHONY: build
20+
build: ## Build the package for PyPI.
2621
@echo "Building for PyPI..."
2722
@python -m pip install --upgrade build
2823
@python -m build
2924

30-
publish:
25+
.PHONY: publish
26+
publish: ## Publish to PyPI.
3127
@echo "Publishing to PyPI..."
3228
@python -m pip install --upgrade twine
3329
@python -m twine upload --repository llm-guard dist/*
3430

35-
docs-serve:
31+
.PHONY: docs-serve
32+
docs-serve: ## Serve documentation using mkdocs.
3633
@echo "Serving documentation..."
3734
@mkdocs serve -a localhost:8085
3835

39-
clean:
36+
.PHONY: clean
37+
clean: ## Clean and Remove build files and pytest cache.
4038
@echo "Cleaning up..."
4139
@rm -rf build dist .pytest_cache .egg-info llm_guard.egg-info
40+
41+
.PHONY: help
42+
help: ## List all targets and help information.
43+
@echo "Available commands:"
44+
@grep --no-filename -E '^([a-z.A-Z_%-/]+:.*?)##' $(MAKEFILE_LIST) | sort | \
45+
awk 'BEGIN {FS = ":.*?(## ?)"}; { \
46+
if (length($$1) > 0) { \
47+
printf " \033[36m%-30s\033[0m %s\n", $$1, $$2; \
48+
} else { \
49+
printf "%s\n", $$2; \
50+
} \
51+
}'

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ stars](https://img.shields.io/github/stars/protectai/llm-guard.svg?style=social&
1212
[![Downloads](https://static.pepy.tech/badge/llm-guard)](https://pepy.tech/project/llm-guard)
1313
[![Downloads](https://static.pepy.tech/badge/llm-guard/month)](https://pepy.tech/project/llm-guard)
1414

15-
<a href="https://join.slack.com/t/laiyerai/shared_invite/zt-28jv3ci39-sVxXrLs3rQdaN3mIl9IT~w"><img src="https://github.com/protectai/llm-guard/blob/main/docs/assets/join-our-slack-community.png?raw=true" width="200"></a>
15+
<a href="https://join.slack.com/t/laiyerai/shared_invite/zt-28jv3ci39-sVxXrLs3rQdaN3mIl9IT~w"><img src="https://github.com/protectai/llm-guard/blob/main/docs/assets/join-our-slack-community.png?raw=true" width="200" alt="Join Our Slack Community"></a>
1616

1717
## What is LLM Guard?
1818

@@ -108,7 +108,7 @@ we would love to have you as part of our community.
108108
Join our Slack to give us feedback, connect with the maintainers and fellow users, ask questions,
109109
get help for package usage or contributions, or engage in discussions about LLM security!
110110

111-
<a href="https://join.slack.com/t/laiyerai/shared_invite/zt-28jv3ci39-sVxXrLs3rQdaN3mIl9IT~w"><img src="https://github.com/protectai/llm-guard/blob/main/docs/assets/join-our-slack-community.png?raw=true" width="200"></a>
111+
<a href="https://join.slack.com/t/laiyerai/shared_invite/zt-28jv3ci39-sVxXrLs3rQdaN3mIl9IT~w"><img src="https://github.com/protectai/llm-guard/blob/main/docs/assets/join-our-slack-community.png?raw=true" width="200" alt="Join Our Slack Community"></a>
112112

113113
### Production Support
114114

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ LLM Guard by [Protect AI](https://protectai.com/llm-guard) is a comprehensive to
44

55
[**Playground**](https://huggingface.co/spaces/ProtectAI/llm-guard-playground) | [**Changelog**](./changelog.md)
66

7-
<a href="https://join.slack.com/t/laiyerai/shared_invite/zt-28jv3ci39-sVxXrLs3rQdaN3mIl9IT~w"><img src="./assets/join-our-slack-community.png" width="200"></a>
7+
<a href="https://join.slack.com/t/laiyerai/shared_invite/zt-28jv3ci39-sVxXrLs3rQdaN3mIl9IT~w"><img src="./assets/join-our-slack-community.png" width="200" alt="Join Our Slack Community"></a>
88

99
## What is LLM Guard?
1010

@@ -55,4 +55,4 @@ we would love to have you as part of our community.
5555
Join our Slack to give us feedback, connect with the maintainers and fellow users, ask questions,
5656
get help for package usage or contributions, or engage in discussions about LLM security!
5757

58-
<a href="https://join.slack.com/t/laiyerai/shared_invite/zt-28jv3ci39-sVxXrLs3rQdaN3mIl9IT~w"><img src="./assets/join-our-slack-community.png" width="200"></a>
58+
<a href="https://join.slack.com/t/laiyerai/shared_invite/zt-28jv3ci39-sVxXrLs3rQdaN3mIl9IT~w"><img src="./assets/join-our-slack-community.png" width="200" alt="Join Our Slack Community"></a>

llm_guard/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
"""LLM Guard package"""
2+
23
from .evaluate import scan_output, scan_prompt

llm_guard/input_scanners/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Input scanners init"""
2+
23
from .anonymize import Anonymize
34
from .ban_code import BanCode
45
from .ban_competitors import BanCompetitors

llm_guard/input_scanners/anonymize.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,11 @@ def scan(self, prompt: str) -> (str, bool, float):
318318
)
319319

320320
risk_score = round(
321-
max(analyzer_result.score for analyzer_result in analyzer_results)
322-
if analyzer_results
323-
else 0.0,
321+
(
322+
max(analyzer_result.score for analyzer_result in analyzer_results)
323+
if analyzer_results
324+
else 0.0
325+
),
324326
2,
325327
)
326328
analyzer_results = self._remove_conflicts_and_get_text_manipulation_data(analyzer_results)

llm_guard/input_scanners/anonymize_helpers/transformers_recognizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ def _load_pipeline(
148148
self.model.onnx_path,
149149
export=False,
150150
subfolder=self.model.onnx_subfolder,
151-
provider="CUDAExecutionProvider"
152-
if device().type == "cuda"
153-
else "CPUExecutionProvider",
151+
provider=(
152+
"CUDAExecutionProvider" if device().type == "cuda" else "CPUExecutionProvider"
153+
),
154154
revision=self.model.onnx_revision,
155155
file_name=self.model.onnx_filename,
156156
use_io_binding=True if device().type == "cuda" else False,

llm_guard/input_scanners/secrets_plugins/adafruit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
This plugin searches for Adafruit keys
33
"""
4+
45
import re
56

67
from detect_secrets.plugins.base import RegexBasedDetector

llm_guard/input_scanners/secrets_plugins/adobe.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
This plugin searches for Adobe keys
33
"""
4+
45
import re
56

67
from detect_secrets.plugins.base import RegexBasedDetector

0 commit comments

Comments
 (0)