Skip to content

Commit 4e478f1

Browse files
committed
feat: more ruff rules and bandit
More ruff rules added and bandit added Modified GH action to run bandit
1 parent f09e58a commit 4e478f1

File tree

6 files changed

+97
-10
lines changed

6 files changed

+97
-10
lines changed

.github/workflows/pyshiny-tests.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
name: 'Test App E2E'
2-
on: # rebuild any PRs and main branch changes
1+
name: 'Test PyShiny App'
2+
on:
33
pull_request:
44
push:
55
branches:
66
- main
77

88
jobs:
9-
build:
9+
test:
1010
runs-on: ubuntu-latest
1111
steps:
12-
1312
- name: Checkout (GitHub)
1413
uses: actions/checkout@v3
1514

1615
- name: Build and run dev container tests
1716
uses: devcontainers/ci@v0.3
1817
with:
19-
runCmd: poetry run pytest
18+
runCmd: ./run_tests_and_bandit.sh

poetry.lock

Lines changed: 50 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ playwright = "^1.42.0"
3131
pytest-playwright = "^0.4.4"
3232
requests = "^2.31.0"
3333
tenacity = "^8.2.3"
34+
bandit = "^1.7.8"
3435

3536
[build-system]
3637
requires = ["poetry-core"]

ruff.toml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@ target-version = "py310"
22
line-length = 120
33

44
[lint]
5-
select = ["B", "E", "F", "I", "ISC", "NPY", "PT", "PTH", "RUF", "UP"]
6-
unfixable = ["B"]
7-
ignore = ["ISC001"]
5+
select = [
6+
"I", # isort: Import sorting
7+
"S", # flake8-bandit: Security checks from Bandit
8+
"B", # flake8-bugbear: Finds likely bugs and design problems in your program
9+
"PT", # flake8-pytest-style: PyTest style checks
10+
"DTZ", # flake8-datetimez: Checks for correct datetime usage
11+
"ISC", # flake8-implicit-str-concat: Checks for implicitly concatenated strings in a list
12+
"RET", # flake8-return: Checks return values
13+
"PTH", # flake8-use-pathlib: Encourages the use of pathlib over os.path
14+
"N", # pep8-naming: Naming convention checks
15+
"E", # pycodestyle errors: Checks against PEP 8 errors
16+
"F", # Pyflakes: Checks for various errors
17+
"UP", # pyupgrade: Checks for older syntax versions and suggests upgrades
18+
"NPY", # NumPy-specific rules
19+
"PD", # pandas-vet: Checks for pandas best practices and potential errors
20+
"RUF", # Ruff-specific rules: Rules specific to Ruff
21+
]
22+
unfixable = [
23+
"B", # Marking flake8-bugbear as unfixable, indicating that these warnings should be manually reviewed
24+
]
25+
ignore = [
26+
"ISC001" # ruff recommends disabling the rule
27+
]
28+
29+
[lint.per-file-ignores]
30+
"tests/*" = [
31+
"S101", # Security check: assert statements
32+
"S311", # Security check: random
33+
]

run_tests_and_bandit.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# This script is for Github Action purposes.
3+
# You cannot run multiple commands with runCmd in devcontainers/ci@v0.3 action
4+
# Hence, this script is created to run the tests and bandit.
5+
6+
set -e # Exit immediately if a command exits with a non-zero status.
7+
8+
echo "Running pytest..."
9+
poetry run pytest
10+
11+
echo "Running Bandit..."
12+
poetry run bandit -r pyshiny_template

tests/playwirght/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
@retry(wait=wait_fixed(0.5), stop=stop_after_delay(10))
1414
def wait_for_server_to_start(url):
15-
response = requests.get(url)
15+
response = requests.get(url) # noqa: S113
1616
response.raise_for_status() # Will raise an exception if the request is unsuccessful, i.e. server is not ready
1717

1818

0 commit comments

Comments
 (0)