Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[flake8]
max-line-length = 120
# E203 is not black compliant https://github.com/psf/black/issues/315
extend-ignore = E203
exclude =
submodules,
venv,
.venv,
.git,
dist,
doc,
*lib/python*,
*egg,
build
per-file-ignores =
./pyrit/score/gpt_classifier.py:E501,W291

copyright-check = True
copyright-regexp = # Copyright \(c\) Microsoft Corporation.\n# Licensed under the MIT license.
58 changes: 58 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Builds the pyrit environment and runs all tests and pre-commit hooks

name: build_and_test

on:
push:
branches:
- "main"
pull_request:
branches:
- "main"
- "release/**"
workflow_dispatch:

concurrency:
# This ensures after each commit the old jobs are cancelled and the new ones
# run instead.
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
main-job:
strategy:
matrix:
os: [ubuntu-latest]
python: ["3.10"]
package_name: ["pyrit"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: ${{ inputs.python }}
- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | python3 -
- name: Create Poetry Environment
run: poetry install --with=dev
- name: Run unit tests with code coverage
run: make test-cov-xml
- name: Publish Pytest Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: '**/test-*.xml'
- name: Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: coverage.xml
badge: true
fail_below_min: false
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'
- name: "Run pre-commit hooks"
run: git ls-files -- $(package_name) | xargs poetry run pre-commit run --files
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# PyRIT-specific configs
submodules/
results/
default_memory.json.memory

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: detect-private-key

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
language_version: python3.10

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8

- repo: https://github.com/pycqa/pylint
rev: v2.16.2
hooks:
- id: pylint
args: [ --disable=all, --enable=unused-import ]

# Calling local version of mypy rather the one from GitHub https://github.com/pre-commit/mirrors-mypy
# because there is no way to sync the configs in pyproject.toml and the .pre-commit-config.yaml
# See https://stackoverflow.com/a/75003826/4956355
- repo: local
hooks:
- id: mypy
name: mypy
entry: mypy
language: system
types: [ python ]
34 changes: 17 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License
Copyright (c) Microsoft Corporation.

Copyright (c) Microsoft Corporation.
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.PHONY: all pre-commit mypy test test-cov-html test-cov-xml

CMD:=poetry run
PYMODULE:=pyrit
TESTS:=tests

all: pre-commit

pre-commit:
$(CMD) isort --multi-line 3 --recursive $(PYMODULE) $(TESTS)
pre-commit run --all-files

mypy:
$(CMD) mypy $(PYMODULE) $(TESTS)

test:
$(CMD) pytest --cov=$(PYMODULE) $(TESTS)

test-cov-html:
$(CMD) pytest --cov=$(PYMODULE) $(TESTS) --cov-report html

test-cov-xml:
$(CMD) pytest --cov=$(PYMODULE) $(TESTS) --cov-report xml --junitxml=junit/test-results.xml --doctest-modules

#clean:
# git clean -Xdf # Delete all files in .gitignore
Loading