Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various linting problems post-merge #46

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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: 10 additions & 9 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# code style (import ordering)
- tool: "isort"
command: "python -m isort --check --diff --color ."
deps: "isort"
deps: "isort colorama"
# (pyflakes, pycodestyle, mccabe) + pep8-naming
- tool: "flake8"
command: "python -m flake8 ."
Expand All @@ -34,12 +34,12 @@ jobs:
deps: "pydocstyle"
# Common security issues
- tool: "bandit"
command: "python -m bandit -c ci/bandit.yml -r ."
deps: "bandit"
# packaging (CheeseShop) compliance
- tool: "pyroma"
command: "pyroma ."
deps: "pyroma"
command: "python -m bandit --configfile pyproject.toml --recursive ."
deps: "bandit toml"
# # packaging (CheeseShop) compliance [DISABLED, pyroma doesn't support PEP 621 metadata yet]
# - tool: "pyroma"
# command: "pyroma ."
# deps: "pyroma"
# type checking
- tool: "mypy"
command: "mypy --namespace-packages -p compass"
Expand All @@ -56,12 +56,13 @@ jobs:
run: ${{ matrix.command }}

release-file:
name: check for RELEASE.rst
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v2
- name: Check for RELEASE.rst
run: test -e RELEASE.rst
- name: No RELEASE.rst file found!
- name: You need to add a RELEASE.rst file at the top-level.
if: failure()
run: echo "::error::You need to add a RELEASE.rst file at the top-level."
run: echo "::error::No RELEASE.rst file found!"
9 changes: 0 additions & 9 deletions ci/bandit.yml

This file was deleted.

18 changes: 9 additions & 9 deletions compass.api/src/compass/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
]

long_description = """
The ***Compass Interface*** project aims to provide a unified and well-documented API to
the Scouts' national membership system, *[Compass](https://compass.scouts.org.uk)*.
The ***Compass Interface*** project aims to provide a unified and well-documented API to
the Scouts' national membership system, *[Compass](https://compass.scouts.org.uk)*.

The project aims to:
- increase flexibility and simplicity when developing applications that interface with *Compass* data,
- provide stability and abstract complexities of *Compass*, and
- enable greater support to our adult volunteers and
members.
The project aims to:
- increase flexibility and simplicity when developing applications that interface with *Compass* data,
- provide stability and abstract complexities of *Compass*, and
- enable greater support to our adult volunteers and
members.

***Compass Interface*** is naturally [open source](https://github.com/the-scouts/compass-interface)
***Compass Interface*** is naturally [open source](https://github.com/the-scouts/compass-interface)
and is licensed under the **[MIT license](https://choosealicense.com/licenses/mit/)**.
"""

Expand Down Expand Up @@ -107,7 +107,7 @@
from compass.core.logger import enable_debug_logging

enable_debug_logging()
uvicorn.run("app:app", host="0.0.0.0", port=8002)
uvicorn.run("app:app", host="0.0.0.0", port=8002) # nosec (B104; don't care as explicitly for local testing)
print()


Expand Down
4 changes: 2 additions & 2 deletions compass.api/src/compass/api/routes/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ async def get_unit_data(unit_id: int) -> UnitRecordModel:


@router.get("/{unit_id}/children", response_model=list[ci.HierarchyUnit])
async def get_unit_data(unit_id: int) -> list[ci.HierarchyUnit]:
async def get_unit_children(unit_id: int) -> list[ci.HierarchyUnit]:
"""Gets hierarchy details for given unit ID."""
logger.debug(f"Getting /hierarchy/{{unit_id}} for {unit_id=}")
async with error_handler:
return (await get_unit(unit_id)).children


@router.get("/{unit_id}/sections", response_model=list[ci.HierarchyUnit])
async def get_unit_data(unit_id: int) -> list[ci.HierarchyUnit]:
async def get_unit_sections(unit_id: int) -> list[ci.HierarchyUnit]:
"""Gets hierarchy details for given unit ID."""
logger.debug(f"Getting /hierarchy/{{unit_id}} for {unit_id=}")
async with error_handler:
Expand Down
4 changes: 3 additions & 1 deletion compass.api/src/compass/api/routes/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ async def get_current_member(api: ci.CompassInterface = Depends(ci_user)) -> ci.


@router.get("/me/roles", response_model=ci.MemberRolesCollection)
async def get_current_member_roles(api: ci.CompassInterface = Depends(ci_user), volunteer_only: bool = False) -> ci.MemberRolesCollection:
async def get_current_member_roles(
api: ci.CompassInterface = Depends(ci_user), volunteer_only: bool = False
) -> ci.MemberRolesCollection:
"""Gets my roles."""
logger.debug(f"Getting /me/roles for {api.user.membership_number}")
async with error_handler:
Expand Down
2 changes: 1 addition & 1 deletion compass.api/src/compass/api/util/flatten_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from typing import TYPE_CHECKING, Union

from compass.api.schemas.unit_records import UnitRecord
from compass.core.settings import Settings
import compass.core as ci
from compass.core.settings import Settings

if TYPE_CHECKING:
from collections.abc import Iterator
Expand Down
4 changes: 3 additions & 1 deletion compass.api/src/compass/api/util/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ async def create_token(username: str, pw: str, role: Optional[str], location: Op
return access_token


async def authenticate_user(username: str, password: str, role: Optional[str], location: Optional[str]) -> tuple[User, ci.CompassInterface]:
async def authenticate_user(
username: str, password: str, role: Optional[str], location: Optional[str]
) -> tuple[User, ci.CompassInterface]:
logger.info(f"Logging in to Compass -- {username}")
api = ci.login(username, password, role=role, location=location)

Expand Down
2 changes: 1 addition & 1 deletion docker/gunicorn_conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from os import cpu_count, getenv
from os import cpu_count, getenv # isort: skip

# Non-gunicorn variables
host = getenv("HOST", "0.0.0.0")
Expand Down
23 changes: 23 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ xfail_strict = true
[tool.pylint]
MASTER.persistent=false # pylint runs on CI, so no point saving
MASTER.jobs=0 # auto-detect the number of processors to use
MASTER.ignore-paths="^tests/.*"
DESIGN.max-statements=60
FORMAT.max-line-length=132
SIMILARITIES.ignore-imports=true
Expand Down Expand Up @@ -105,6 +106,28 @@ disable = [
"wrong-import-order",
]

# pydocstyle configuration
[tool.pydocstyle]
convention = "google"
# re-enable D413, Missing blank line after last section
add_select = ["D413"]
# ignore missing docstrings in public modules, public classes, public methods, and public functions
add_ignore = ["D100", "D101", "D102", "D103"]
match-dir = "(?!tools|tests).*"

# bandit configuration
[tool.bandit]
exclude_dirs = [
"./docker/*",
"./scripts/*",
"./tests/*",
"./tools/*",
]

skips = [
'B410', # import lxml.* (defusedxml.lxml is deprecated)
]

[tool.coverage.report]
exclude_lines = [
# re-enable the standard pragma
Expand Down
8 changes: 0 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,3 @@ max-complexity = 15
# black manages line length
ignore = E501, W503
classmethod-decorators = classmethod, validator

# pydocstyle configuration
[pydocstyle]
convention = google
# re-enable D413, Missing blank line after last section
add_select = D413
# ignore missing docstrings in public modules, public classes, public methods, and public functions
add_ignore = D100, D101, D102, D103
2 changes: 1 addition & 1 deletion tests/test_compass_core_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pathlib
import sys

from compass.core.logger import logger
from compass.core.logger import enable_debug_logging
from compass.core.logger import logger


class TestLogger:
Expand Down
6 changes: 3 additions & 3 deletions tools/prepare_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def update_changelog(version):
"\n".join(RELEASE_FILE.read_text(encoding="utf-8").split("\n")[1:]).strip(),
"",
*lines[3:],
""
"",
)
HISTORY_FILE.write_text("\n".join(new_changelog_lines), encoding="utf-8")

Expand Down Expand Up @@ -73,10 +73,10 @@ def push_with_tags(version):
print("Committing changes")
commit(new_version)

print(f"Creating tag")
print("Creating tag")
tag(new_version)

print(f"Pushing changes")
print("Pushing changes")
push_with_tags(new_version)

raise SystemExit(0)
2 changes: 1 addition & 1 deletion update_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def main() -> list[str]:
return [resp.content for resp in responses]


if __name__ == '__main__':
if __name__ == "__main__":
files_contents = asyncio.run(main())
for i, filename in enumerate(files):
Path(f"js/{filename}.js").write_bytes(files_contents[i].decode("utf-8-sig").encode("utf-8"))